Skip to content

Commit 8c810a1

Browse files
authored
Inject the database into the installer script when possible (#40724)
* Inject the database into the installer script when possible * Proxy the database in the legacy installer class
1 parent 0891fcf commit 8c810a1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

libraries/src/Installer/InstallerAdapter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Joomla\Database\DatabaseAwareInterface;
2222
use Joomla\Database\DatabaseAwareTrait;
2323
use Joomla\Database\DatabaseDriver;
24+
use Joomla\Database\DatabaseInterface;
2425
use Joomla\DI\Container;
2526
use Joomla\DI\ContainerAwareInterface;
2627
use Joomla\DI\ContainerAwareTrait;
@@ -996,6 +997,11 @@ function (Container $container) use ($classname) {
996997
// Create a new instance
997998
$this->parent->manifestClass = $container->get(InstallerScriptInterface::class);
998999

1000+
// Set the database
1001+
if ($this->parent->manifestClass instanceof DatabaseAwareInterface) {
1002+
$this->parent->manifestClass->setDatabase($container->get(DatabaseInterface::class));
1003+
}
1004+
9991005
// And set this so we can copy it later
10001006
$this->manifest_script = $manifestScript;
10011007
}

libraries/src/Installer/LegacyInstallerScript.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
namespace Joomla\CMS\Installer;
1111

12+
use Joomla\CMS\Factory;
13+
use Joomla\Database\DatabaseAwareInterface;
14+
use Joomla\Database\DatabaseAwareTrait;
15+
use Joomla\Database\Exception\DatabaseNotFoundException;
16+
1217
// phpcs:disable PSR1.Files.SideEffects
1318
\defined('_JEXEC') or die;
1419
// phpcs:enable PSR1.Files.SideEffects
@@ -18,8 +23,10 @@
1823
*
1924
* @since 4.2.0
2025
*/
21-
class LegacyInstallerScript implements InstallerScriptInterface
26+
class LegacyInstallerScript implements InstallerScriptInterface, DatabaseAwareInterface
2227
{
28+
use DatabaseAwareTrait;
29+
2330
/**
2431
* @var \stdClass
2532
* @since 4.2.0
@@ -168,6 +175,15 @@ private function callOnScript(string $name, array $arguments): bool
168175
return true;
169176
}
170177

178+
if ($this->installerScript instanceof DatabaseAwareInterface) {
179+
try {
180+
$this->installerScript->setDatabase($this->getDatabase());
181+
} catch (DatabaseNotFoundException $e) {
182+
@trigger_error(sprintf('Database must be set, this will not be caught anymore in 6.0 in %s.', __METHOD__), E_USER_DEPRECATED);
183+
$this->installerScript->setDatabase(Factory::getContainer()->get(DatabaseInterface::class));
184+
}
185+
}
186+
171187
$return = $this->__call($name, $arguments);
172188

173189
// When function doesn't have a return value, assume it succeeded

0 commit comments

Comments
 (0)