Skip to content
3 changes: 3 additions & 0 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ protected function uninstallRepeatableFieldsPlugin()

// And now uninstall the plugin
$installer = new Installer;
$installer->setDatabase($db);
$installer->uninstall('plugin', $extensionId);

$db->transactionCommit();
Expand Down Expand Up @@ -551,6 +552,7 @@ protected function uninstallEosPlugin()

// Uninstall the plugin
$installer = new Installer;
$installer->setDatabase($db);
$installer->uninstall('plugin', $extensionId);

$db->transactionCommit();
Expand Down Expand Up @@ -607,6 +609,7 @@ protected function updateManifestCaches()
}

$installer = new Installer;
$installer->setDatabase($db);

foreach ($extensions as $extension)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public function discover_install()
foreach ($eid as $id)
{
$installer = new Installer;
$installer->setDatabase($this->getDatabase());

$result = $installer->discover_install($id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ public function rebuild(): void
foreach ($pathsToSearch as $extensionFolderPath)
{
$tmpInstaller = new Installer;
$tmpInstaller->setDatabase($this->getDatabase());

$tmpInstaller->setPath('source', $extensionFolderPath);

Expand Down
6 changes: 3 additions & 3 deletions installation/src/Application/InstallationApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,11 @@ private function executeController()
list($controllerName, $task) = explode('.', $task, 2);
}

// Compile the class name
$class = 'Joomla\\CMS\\Installation\\Controller\\' . ucfirst($controllerName) . 'Controller';
$factory = new MVCFactory('Joomla\\CMS');
$factory->setDatabase($this->getContainer()->get(DatabaseInterface::class));

// Create the instance
$controller = new $class([], new MVCFactory('Joomla\\CMS', $this), $this, $this->input);
$controller = $factory->createController($controllerName, 'Installation', [], $this, $this->input);

// Execute the task
$controller->execute($task);
Expand Down
2 changes: 2 additions & 0 deletions installation/src/Model/ConfigurationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function setup($options)
$return = false;
}

// This is needed because the installer loads the extension table in constructor, needs to be refactored in 5.0
Factory::$database = $db;
$installer = Installer::getInstance();

Expand Down Expand Up @@ -367,6 +368,7 @@ public function checkTestingSampledata($db)
$db->insertObject('#__extensions', $testingPlugin, 'extension_id');

$installer = new Installer;
$installer->setDatabase($db);

if (!$installer->refreshManifestCache($testingPlugin->extension_id))
{
Expand Down
18 changes: 8 additions & 10 deletions installation/src/Model/LanguagesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@
use Joomla\CMS\Table\Table;
use Joomla\CMS\Updater\Update;
use Joomla\CMS\Updater\Updater;
use Joomla\Database\DatabaseAwareInterface;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Registry\Registry;

/**
* Language Installer model for the Joomla Core Installer.
*
* @since 3.1
*/
class LanguagesModel extends BaseInstallationModel
class LanguagesModel extends BaseInstallationModel implements DatabaseAwareInterface
{
use DatabaseAwareTrait;

/**
* @var object Client object.
* @since 3.1
Expand Down Expand Up @@ -74,13 +78,6 @@ public function __construct()
Factory::getApplication()->setConfiguration(new Registry(new \JConfig));
}

/*
* Factory::getDbo() gets called during app bootup, and because of the "uniqueness" of the install app, the config doesn't get read
* correctly at that point. So, we have to reset the factory database object here so that we can get a valid database configuration.
* The day we have proper dependency injection will be a glorious one.
*/
Factory::$database = null;

parent::__construct();
}

Expand All @@ -94,7 +91,7 @@ public function __construct()
public function getItems()
{
// Get the extension_id of the en-GB package.
$db = Factory::getDbo();
$db = $this->getDatabase();
$extQuery = $db->getQuery(true);

$extQuery->select($db->quoteName('extension_id'))
Expand Down Expand Up @@ -152,6 +149,7 @@ public function install($lids)
{
$app = Factory::getApplication();
$installerBase = new Installer;
$installerBase->setDatabase($this->getDatabase());

// Loop through every selected language.
foreach ($lids as $id)
Expand Down Expand Up @@ -397,7 +395,7 @@ protected function getInstalledlangs($clientName = 'administrator')
protected function getLanguageList($clientId = 1)
{
// Create a new db object.
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true);

// Select field element from the extensions table.
Expand Down
7 changes: 7 additions & 0 deletions libraries/src/Adapter/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Joomla\CMS\Factory;
use Joomla\CMS\Object\CMSObject;
use Joomla\Database\DatabaseAwareInterface;

/**
* Adapter Class
Expand Down Expand Up @@ -79,6 +80,12 @@ public function __construct($basepath, $classprefix = null, $adapterfolder = nul
$this->_adapterfolder = $adapterfolder ?: 'adapters';

$this->_db = Factory::getDbo();

// Ensure BC, when removed in 5, then the db must be set with setDatabase explicitly
if ($this instanceof DatabaseAwareInterface)
{
$this->setDatabase($this->_db);
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions libraries/src/Console/ExtensionDiscoverInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ protected function configure(): void
public function processDiscover($eid): int
{
$jInstaller = new Installer;
$jInstaller->setDatabase($this->db);
$count = 0;

if ($eid === -1)
Expand Down
15 changes: 8 additions & 7 deletions libraries/src/Installer/Adapter/ComponentAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ protected function finaliseUninstall(): bool
{
$extensionId = $this->extension->extension_id;

$db = $this->parent->getDbo();
$db = $this->getDatabase();

// Remove the schema version
$query = $db->getQuery(true)
Expand Down Expand Up @@ -723,7 +723,7 @@ public function prepareDiscoverInstall()
$element = $this->extension->element;

// Try to delete existing failed records before retrying
$db = $this->db;
$db = $this->getDatabase();

$query = $db->getQuery(true)
->select($db->quoteName('extension_id'))
Expand Down Expand Up @@ -869,6 +869,7 @@ protected function setupUpdates()

// Use a temporary instance due to side effects; start in the administrator first
$tmpInstaller = new Installer;
$tmpInstaller->setDatabase($this->getDatabase());
$tmpInstaller->setPath('source', $this->parent->getPath('extension_administrator'));

if (!$tmpInstaller->findManifest())
Expand Down Expand Up @@ -926,7 +927,7 @@ protected function storeExtension($deleteExisting = false)
$element = $this->extension->element;

// Try to delete existing failed records before retrying
$db = $this->db;
$db = $this->getDatabase();

$query = $db->getQuery(true)
->select($db->quoteName('extension_id'))
Expand Down Expand Up @@ -1011,7 +1012,7 @@ protected function storeExtension($deleteExisting = false)
*/
protected function _buildAdminMenus($componentId = null)
{
$db = $this->parent->getDbo();
$db = $this->getDatabase();
$option = $this->element;

// If a component exists with this option in the table within the protected menutype 'main' then we don't need to add menus
Expand Down Expand Up @@ -1247,7 +1248,7 @@ protected function _buildAdminMenus($componentId = null)
*/
protected function _removeAdminMenus($id)
{
$db = $this->parent->getDbo();
$db = $this->getDatabase();

/** @var \Joomla\CMS\Table\Menu $table */
$table = Table::getInstance('menu');
Expand Down Expand Up @@ -1318,7 +1319,7 @@ protected function _updateSiteMenus($componentId = null)
*/
protected function _updateMenus($componentId, $clientId = null)
{
$db = $this->parent->getDbo();
$db = $this->getDatabase();
$option = $this->element;
$link = 'index.php?option=' . $option;
$linkMatch = 'index.php?option=' . $option . '&%';
Expand Down Expand Up @@ -1507,7 +1508,7 @@ public function refreshManifestCache()
*/
protected function _createAdminMenuItem(array &$data, $parentId)
{
$db = $this->parent->getDbo();
$db = $this->getDatabase();

/** @var \Joomla\CMS\Table\Menu $table */
$table = Table::getInstance('menu');
Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Installer/Adapter/FileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected function finaliseUninstall(): bool

$extensionId = $this->extension->extension_id;

$db = $this->parent->getDbo();
$db = $this->getDatabase();

// Remove the schema version
$query = $db->getQuery(true)
Expand Down Expand Up @@ -461,7 +461,7 @@ protected function storeExtension()
protected function extensionExistsInSystem($extension = null)
{
// Get a database connector object
$db = $this->parent->getDbo();
$db = $this->getDatabase();

$query = $db->getQuery(true)
->select($db->quoteName('extension_id'))
Expand Down
6 changes: 3 additions & 3 deletions libraries/src/Installer/Adapter/LanguageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function finaliseUninstall(): bool
$extensionId = $this->extension->extension_id;

// Remove the schema version
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->delete($db->quoteName('#__schemas'))
->where($db->quoteName('extension_id') . ' = :extension_id')
Expand Down Expand Up @@ -503,7 +503,7 @@ protected function getSefString($itemLanguageTag)
$numberPrefixesFound = 0;

// Get the sef value of all current content languages.
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('sef'))
->from($db->quoteName('#__languages'));
Expand Down Expand Up @@ -813,7 +813,7 @@ private function resetUserLanguage(): void
}

// Setting the language of users which have this language as the default language
$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select(
[
Expand Down
5 changes: 3 additions & 2 deletions libraries/src/Installer/Adapter/LibraryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ protected function checkExtensionInFilesystem()

// We don't want to compromise this instance!
$installer = new Installer;
$installer->setDatabase($this->getDatabase());
$installer->setPackageUninstall(true);
$installer->uninstall('library', $this->currentExtensionId);

// Clear the cached data
$this->currentExtensionId = null;
$this->extension = Table::getInstance('Extension', 'JTable', array('dbo' => $this->db));
$this->extension = Table::getInstance('Extension', 'JTable', array('dbo' => $this->getDatabase()));

// From this point we'll consider this an update
$this->setRoute('update');
Expand Down Expand Up @@ -172,7 +173,7 @@ protected function finaliseUninstall(): bool
{
$extensionId = $this->extension->extension_id;

$db = $this->parent->getDbo();
$db = $this->getDatabase();

// Remove the schema version
$query = $db->getQuery(true)
Expand Down
6 changes: 3 additions & 3 deletions libraries/src/Installer/Adapter/ModuleAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ protected function finaliseUninstall(): bool
{
$extensionId = $this->extension->extension_id;

$db = $this->parent->getDbo();
$db = $this->getDatabase();
$retval = true;

// Remove the schema version
Expand Down Expand Up @@ -710,7 +710,7 @@ protected function storeExtension()
protected function _rollback_menu($arg)
{
// Get database connector object
$db = $this->parent->getDbo();
$db = $this->getDatabase();

$moduleId = $arg['id'];

Expand Down Expand Up @@ -744,7 +744,7 @@ protected function _rollback_menu($arg)
protected function _rollback_module($arg)
{
// Get database connector object
$db = $this->parent->getDbo();
$db = $this->getDatabase();

$moduleId = $arg['id'];

Expand Down
8 changes: 5 additions & 3 deletions libraries/src/Installer/Adapter/PackageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ protected function copyBaseFiles()
}

$tmpInstaller = new Installer;
$tmpInstaller->setDatabase($this->getDatabase());
$installResult = $tmpInstaller->install($package['dir']);

if (!$installResult)
Expand Down Expand Up @@ -223,7 +224,7 @@ protected function finaliseInstall()
// Set the package ID for each of the installed extensions to track the relationship
if (!empty($this->installedIds))
{
$db = $this->db;
$db = $this->getDatabase();
$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('package_id') . ' = :id')
Expand Down Expand Up @@ -316,7 +317,7 @@ protected function finaliseInstall()
*/
protected function finaliseUninstall(): bool
{
$db = $this->parent->getDbo();
$db = $this->getDatabase();

// Remove the schema version
$query = $db->getQuery(true)
Expand Down Expand Up @@ -436,6 +437,7 @@ protected function removeExtensionFiles()
foreach ($manifest->filelist as $extension)
{
$tmpInstaller = new Installer;
$tmpInstaller->setDatabase($this->getDatabase());
$tmpInstaller->setPackageUninstall(true);

$id = $this->_getExtensionId($extension->type, $extension->id, $extension->client, $extension->group);
Expand Down Expand Up @@ -681,7 +683,7 @@ protected function triggerManifestScript($method)
*/
protected function _getExtensionId($type, $id, $client, $group)
{
$db = $this->parent->getDbo();
$db = $this->getDatabase();

$query = $db->getQuery(true)
->select($db->quoteName('extension_id'))
Expand Down
3 changes: 2 additions & 1 deletion libraries/src/Installer/Adapter/PluginAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ protected function createExtensionRoot()
{
// Create a new installer because findManifest sets stuff; side effects!
$tmpInstaller = new Installer;
$tmpInstaller->setDatabase($this->getDatabase());

// Look in the extension root
$tmpInstaller->setPath('source', $this->parent->getPath('extension_root'));
Expand Down Expand Up @@ -202,7 +203,7 @@ protected function finaliseUninstall(): bool
{
$extensionId = $this->extension->extension_id;

$db = $this->parent->getDbo();
$db = $this->getDatabase();

// Remove the schema version
$query = $db->getQuery(true)
Expand Down
Loading