Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Joomla\Component\Finder\Administrator\Service\HTML\Filter;
use Joomla\Component\Finder\Administrator\Service\HTML\Finder;
use Joomla\Component\Finder\Administrator\Service\HTML\Query;
use Joomla\Database\DatabaseInterface;
use Psr\Container\ContainerInterface;

/**
Expand Down Expand Up @@ -46,8 +47,16 @@ class FinderComponent extends MVCComponent implements BootableExtensionInterface
*/
public function boot(ContainerInterface $container)
{
$this->getRegistry()->register('finder', new Finder);
$this->getRegistry()->register('filter', new Filter);
$finder = new Finder;
$finder->setDatabase($container->get(DatabaseInterface::class));

$this->getRegistry()->register('finder', $finder);

$filter = new Filter;
$filter->setDatabase($container->get(DatabaseInterface::class));

$this->getRegistry()->register('filter', $filter);

$this->getRegistry()->register('query', new Query);
}
}
5 changes: 1 addition & 4 deletions administrator/components/com_finder/src/Indexer/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ abstract class Adapter extends CMSPlugin
*/
public function __construct(&$subject, $config)
{
// Get the database object.
$this->db = Factory::getDbo();

// Call the parent constructor.
parent::__construct($subject, $config);

Expand All @@ -157,7 +154,7 @@ public function __construct(&$subject, $config)
}

// Get the indexer object
$this->indexer = new Indexer;
$this->indexer = new Indexer($this->db);
}

/**
Expand Down
15 changes: 11 additions & 4 deletions administrator/components/com_finder/src/Indexer/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Profiler\Profiler;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;
use Joomla\String\StringHelper;
Expand Down Expand Up @@ -112,13 +113,19 @@ class Indexer
/**
* Indexer constructor.
*
* @param DatabaseInterface $db The database
*
* @since 3.8.0
*/
public function __construct()
public function __construct(DatabaseInterface $db = null)
{
$this->db = Factory::getDbo();
if ($db === null)
{
@trigger_error(sprintf('Database will be mandatory in 5.0.'), E_USER_DEPRECATED);
$db = Factory::getContainer()->get(DatabaseInterface::class);
}

$db = $this->db;
$this->db = $db;

// Set up query template for addTokensToDb
$this->addTokensToDbQueryTemplate = $db->getQuery(true)->insert($db->quoteName('#__finder_tokens'))
Expand Down Expand Up @@ -1020,7 +1027,7 @@ protected function addTokensToDb($tokens, $context = '')
*/
protected function toggleTables($memory)
{
if (strtolower(Factory::getDbo()->getServerType()) != 'mysql')
if (strtolower($this->db->getServerType()) != 'mysql')
{
return true;
}
Expand Down
20 changes: 16 additions & 4 deletions administrator/components/com_finder/src/Indexer/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Finder\Administrator\Helper\LanguageHelper;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
Expand All @@ -31,6 +33,8 @@
*/
class Query
{
use DatabaseAwareTrait;

/**
* Flag to show whether the query can return results.
*
Expand Down Expand Up @@ -191,8 +195,16 @@ class Query
* @since 2.5
* @throws Exception on database error.
*/
public function __construct($options)
public function __construct($options, DatabaseInterface $db = null)
{
if ($db === null)
{
@trigger_error(sprintf('Database will be mandatory in 5.0.'), E_USER_DEPRECATED);
$db = Factory::getContainer()->get(DatabaseInterface::class);
}

$this->setDatabase($db);

// Get the input string.
$this->input = $options['input'] ?? '';

Expand Down Expand Up @@ -516,7 +528,7 @@ public function getRequiredTermIds()
protected function processStaticTaxonomy($filterId)
{
// Get the database object.
$db = Factory::getDbo();
$db = $this->getDatabase();

// Initialize user variables
$groups = implode(',', Factory::getUser()->getAuthorisedViewLevels());
Expand Down Expand Up @@ -630,7 +642,7 @@ protected function processDynamicTaxonomy($filters)
}

// Get the database object.
$db = Factory::getDbo();
$db = $this->getDatabase();

$query = $db->getQuery(true);

Expand Down Expand Up @@ -1339,7 +1351,7 @@ protected function processString($input, $lang, $mode)
protected function getTokenData($token)
{
// Get the database object.
$db = Factory::getDbo();
$db = $this->getDatabase();

// Create a database query to build match the token.
$query = $db->getQuery(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Joomla\CMS\Language\Text;
use Joomla\Component\Finder\Administrator\Helper\LanguageHelper;
use Joomla\Component\Finder\Administrator\Indexer\Query;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Registry\Registry;

/**
Expand All @@ -27,6 +28,8 @@
*/
class Filter
{
use DatabaseAwareTrait;

/**
* Method to generate filters using the slider widget and decorated
* with the FinderFilter JavaScript behaviors.
Expand All @@ -39,7 +42,7 @@ class Filter
*/
public function slider($options = array())
{
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true);
$user = Factory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
Expand Down Expand Up @@ -239,7 +242,7 @@ public function select($idxQuery, $options)
}
else
{
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true);

// Load the predefined filter if specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\Component\Finder\Administrator\Helper\LanguageHelper;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Utilities\ArrayHelper;

/**
Expand All @@ -24,6 +25,8 @@
*/
class Finder
{
use DatabaseAwareTrait;

/**
* Creates a list of types to filter on.
*
Expand All @@ -34,7 +37,7 @@ class Finder
public function typeslist()
{
// Load the finder types.
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('DISTINCT t.title AS text, t.id AS value')
->from($db->quoteName('#__finder_types') . ' AS t')
Expand Down Expand Up @@ -75,7 +78,7 @@ public function typeslist()
public function mapslist()
{
// Load the finder types.
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('title', 'text'))
->select($db->quoteName('id', 'value'))
Expand Down
2 changes: 1 addition & 1 deletion components/com_finder/src/Model/SearchModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ protected function populateState($ordering = null, $direction = null)
$options['when2'] = $request->getString('w2', $params->get('w2', ''));

// Load the query object.
$this->searchquery = new Query($options);
$this->searchquery = new Query($options, $this->getDatabase());

// Load the query token data.
$this->excludedTerms = $this->searchquery->getExcludedTermIds();
Expand Down
3 changes: 2 additions & 1 deletion modules/mod_finder/src/Helper/FinderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Finder\Administrator\Indexer\Query;
use Joomla\Database\DatabaseInterface;
use Joomla\Utilities\ArrayHelper;

/**
Expand Down Expand Up @@ -76,6 +77,6 @@ public static function getQuery($params)
$options['filters'] = ArrayHelper::toInteger($options['filters']);

// Instantiate a query object.
return new Query($options);
return new Query($options, Factory::getContainer()->get(DatabaseInterface::class));
}
}