diff --git a/administrator/components/com_finder/src/Extension/FinderComponent.php b/administrator/components/com_finder/src/Extension/FinderComponent.php index 0f861b3a75f92..65944b880778a 100644 --- a/administrator/components/com_finder/src/Extension/FinderComponent.php +++ b/administrator/components/com_finder/src/Extension/FinderComponent.php @@ -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; /** @@ -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); } } diff --git a/administrator/components/com_finder/src/Indexer/Adapter.php b/administrator/components/com_finder/src/Indexer/Adapter.php index f13105ea3fe9a..0d7d9b341bbe9 100644 --- a/administrator/components/com_finder/src/Indexer/Adapter.php +++ b/administrator/components/com_finder/src/Indexer/Adapter.php @@ -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); @@ -157,7 +154,7 @@ public function __construct(&$subject, $config) } // Get the indexer object - $this->indexer = new Indexer; + $this->indexer = new Indexer($this->db); } /** diff --git a/administrator/components/com_finder/src/Indexer/Indexer.php b/administrator/components/com_finder/src/Indexer/Indexer.php index d5fc15427a2bd..79a3aa8b667b4 100644 --- a/administrator/components/com_finder/src/Indexer/Indexer.php +++ b/administrator/components/com_finder/src/Indexer/Indexer.php @@ -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; @@ -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')) @@ -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; } diff --git a/administrator/components/com_finder/src/Indexer/Query.php b/administrator/components/com_finder/src/Indexer/Query.php index 33dabbcbcb118..50e97d2a4df04 100644 --- a/administrator/components/com_finder/src/Indexer/Query.php +++ b/administrator/components/com_finder/src/Indexer/Query.php @@ -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; @@ -31,6 +33,8 @@ */ class Query { + use DatabaseAwareTrait; + /** * Flag to show whether the query can return results. * @@ -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'] ?? ''; @@ -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()); @@ -630,7 +642,7 @@ protected function processDynamicTaxonomy($filters) } // Get the database object. - $db = Factory::getDbo(); + $db = $this->getDatabase(); $query = $db->getQuery(true); @@ -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) diff --git a/administrator/components/com_finder/src/Service/HTML/Filter.php b/administrator/components/com_finder/src/Service/HTML/Filter.php index f9de3fcc9d089..f81a1610a0e96 100644 --- a/administrator/components/com_finder/src/Service/HTML/Filter.php +++ b/administrator/components/com_finder/src/Service/HTML/Filter.php @@ -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; /** @@ -27,6 +28,8 @@ */ class Filter { + use DatabaseAwareTrait; + /** * Method to generate filters using the slider widget and decorated * with the FinderFilter JavaScript behaviors. @@ -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()); @@ -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. diff --git a/administrator/components/com_finder/src/Service/HTML/Finder.php b/administrator/components/com_finder/src/Service/HTML/Finder.php index a0dc52d118bbd..0968df797eb34 100644 --- a/administrator/components/com_finder/src/Service/HTML/Finder.php +++ b/administrator/components/com_finder/src/Service/HTML/Finder.php @@ -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; /** @@ -24,6 +25,8 @@ */ class Finder { + use DatabaseAwareTrait; + /** * Creates a list of types to filter on. * @@ -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') @@ -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')) diff --git a/components/com_finder/src/Model/SearchModel.php b/components/com_finder/src/Model/SearchModel.php index 62272b0ebaab2..cc248493436dd 100644 --- a/components/com_finder/src/Model/SearchModel.php +++ b/components/com_finder/src/Model/SearchModel.php @@ -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(); diff --git a/modules/mod_finder/src/Helper/FinderHelper.php b/modules/mod_finder/src/Helper/FinderHelper.php index 611cc9228b866..f69afb5aa068c 100644 --- a/modules/mod_finder/src/Helper/FinderHelper.php +++ b/modules/mod_finder/src/Helper/FinderHelper.php @@ -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; /** @@ -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)); } }