diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Administration/UpdateController.php b/phpmyfaq/src/phpMyFAQ/Controller/Administration/UpdateController.php index a49b2d8c81..362df9c9cb 100644 --- a/phpmyfaq/src/phpMyFAQ/Controller/Administration/UpdateController.php +++ b/phpmyfaq/src/phpMyFAQ/Controller/Administration/UpdateController.php @@ -24,8 +24,6 @@ use phpMyFAQ\Core\Exception; use phpMyFAQ\Enums\PermissionType; use phpMyFAQ\Filter; -use phpMyFAQ\Setup\Update; -use phpMyFAQ\Setup\Upgrade; use phpMyFAQ\System; use phpMyFAQ\Translation; use Symfony\Component\HttpClient\HttpClient; @@ -44,6 +42,7 @@ class UpdateController extends AbstractController { /** * @throws Exception + * @throws \Exception */ #[Route('admin/api/health-check')] public function healthCheck(): JsonResponse @@ -52,7 +51,7 @@ public function healthCheck(): JsonResponse $dateTime = new DateTime(); $dateLastChecked = $dateTime->format(DateTimeInterface::ATOM); - $upgrade = new Upgrade(new System(), $this->configuration); + $upgrade = $this->container->get('phpmyfaq.setup.upgrade'); if (!$upgrade->isMaintenanceEnabled()) { return $this->json( @@ -164,7 +163,7 @@ public function downloadPackage(Request $request): JsonResponse $versionNumber = Filter::filterVar($request->get('versionNumber'), FILTER_SANITIZE_SPECIAL_CHARS); - $upgrade = new Upgrade(new System(), $this->configuration); + $upgrade = $this->container->get('phpmyfaq.setup.upgrade'); $pathToPackage = $upgrade->downloadPackage($versionNumber); if ($pathToPackage === false) { @@ -191,7 +190,7 @@ public function extractPackage(): StreamedResponse { $this->userHasPermission(PermissionType::CONFIGURATION_EDIT); - $upgrade = new Upgrade(new System(), $this->configuration); + $upgrade = $this->container->get('phpmyfaq.setup.upgrade'); $pathToPackage = urldecode((string) $this->configuration->get('upgrade.lastDownloadedPackage')); return new StreamedResponse(static function () use ($upgrade, $pathToPackage) { @@ -216,7 +215,7 @@ public function createTemporaryBackup(): StreamedResponse { $this->userHasPermission(PermissionType::CONFIGURATION_EDIT); - $upgrade = new Upgrade(new System(), $this->configuration); + $upgrade = $this->container->get('phpmyfaq.setup.upgrade'); $backupHash = md5(uniqid()); return new StreamedResponse(static function () use ($upgrade, $backupHash) { @@ -241,7 +240,7 @@ public function installPackage(): StreamedResponse { $this->userHasPermission(PermissionType::CONFIGURATION_EDIT); - $upgrade = new Upgrade(new System(), $this->configuration); + $upgrade = $this->container->get('phpmyfaq.setup.upgrade'); $configurator = $this->container->get('phpmyfaq.setup.environment_configurator'); return new StreamedResponse(static function () use ($upgrade, $configurator) { $progressCallback = static function ($progress) { @@ -267,7 +266,7 @@ public function updateDatabase(): StreamedResponse $configuration = $this->configuration; - $update = new Update(new System(), $this->configuration); + $update = $this->container->get('phpmyfaq.setup.update'); $update->setVersion(System::getVersion()); return new StreamedResponse(static function () use ($configuration, $update) { @@ -295,7 +294,7 @@ public function cleanUp(): JsonResponse { $this->userHasPermission(PermissionType::CONFIGURATION_EDIT); - $upgrade = new Upgrade(new System(), $this->configuration); + $upgrade = $this->container->get('phpmyfaq.setup.upgrade'); $upgrade->cleanUp(); return $this->json(['message' => '✅ Cleanup successful.'], Response::HTTP_OK); diff --git a/phpmyfaq/src/phpMyFAQ/Setup/Update.php b/phpmyfaq/src/phpMyFAQ/Setup/Update.php index cb8ee22047..64c7dc82ba 100644 --- a/phpmyfaq/src/phpMyFAQ/Setup/Update.php +++ b/phpmyfaq/src/phpMyFAQ/Setup/Update.php @@ -211,7 +211,7 @@ private function executeQueries(callable $progressCallback): void { if ($this->dryRun) { foreach ($this->queries as $query) { - array_push($this->dryRunQueries, $query); + $this->dryRunQueries[] = $query; } } else { foreach ($this->queries as $query) { diff --git a/phpmyfaq/src/services.php b/phpmyfaq/src/services.php index 7c80f27fb0..6c684065c1 100644 --- a/phpmyfaq/src/services.php +++ b/phpmyfaq/src/services.php @@ -29,7 +29,10 @@ use phpMyFAQ\Services\Gravatar; use phpMyFAQ\Session; use phpMyFAQ\Setup\EnvironmentConfigurator; +use phpMyFAQ\Setup\Update; +use phpMyFAQ\Setup\Upgrade; use phpMyFAQ\Sitemap; +use phpMyFAQ\System; use phpMyFAQ\Tags; use phpMyFAQ\User\CurrentUser; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; @@ -115,6 +118,20 @@ new Reference('phpmyfaq.configuration') ]); + $services->set('phpmyfaq.setup.update', Update::class) + ->args([ + new Reference('phpmyfaq.system'), + new Reference('phpmyfaq.configuration') + ]); + + $services->set('phpmyfaq.setup.upgrade', Upgrade::class) + ->args([ + new Reference('phpmyfaq.system'), + new Reference('phpmyfaq.configuration') + ]); + + $services->set('phpmyfaq.system', System::class); + $services->set('phpmyfaq.tags', Tags::class) ->args([ new Reference('phpmyfaq.configuration')