From f101226bf54e68daa5258a4e512a6af65fdcf962 Mon Sep 17 00:00:00 2001 From: Adam Daley Date: Wed, 27 May 2026 04:17:24 +0100 Subject: [PATCH] Register 'dbal' service in UpdatePatcher (#3616) * Register 'dbal' service in UpdatePatcher * Fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/library/FOSSBilling/UpdatePatcher.php | 6 ++++ .../library/FOSSBilling/UpdatePatcherTest.php | 34 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests-legacy/library/FOSSBilling/UpdatePatcherTest.php diff --git a/src/library/FOSSBilling/UpdatePatcher.php b/src/library/FOSSBilling/UpdatePatcher.php index cd42fdeb1..f32762afa 100644 --- a/src/library/FOSSBilling/UpdatePatcher.php +++ b/src/library/FOSSBilling/UpdatePatcher.php @@ -11,7 +11,9 @@ declare(strict_types=1); namespace FOSSBilling; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; +use FOSSBilling\Doctrine\DriverManagerFactory; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Path; @@ -30,6 +32,10 @@ class UpdatePatcher implements InjectionAwareInterface public function setDi(\Pimple\Container $di): void { + if (!$di->offsetExists('dbal')) { + $di['dbal'] = static fn (): Connection => DriverManagerFactory::getConnection(); + } + $this->di = $di; } diff --git a/tests-legacy/library/FOSSBilling/UpdatePatcherTest.php b/tests-legacy/library/FOSSBilling/UpdatePatcherTest.php new file mode 100644 index 000000000..5012b6059 --- /dev/null +++ b/tests-legacy/library/FOSSBilling/UpdatePatcherTest.php @@ -0,0 +1,34 @@ +offsetExists('dbal')); + + $patcher = new UpdatePatcher(); + $patcher->setDi($di); + + self::assertTrue($di->offsetExists('dbal')); + } + + public function testSetDiDoesNotOverrideExistingDbalEntry(): void + { + $di = new Pimple\Container(); + $sentinel = new stdClass(); + $di['dbal'] = $sentinel; + + $patcher = new UpdatePatcher(); + $patcher->setDi($di); + + self::assertSame($sentinel, $di['dbal']); + } +}