Skip to content

Commit

Permalink
fix: simplified code (#3312)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jan 3, 2025
1 parent 76b1d36 commit 90fb9f9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,6 +42,7 @@ class UpdateController extends AbstractController
{
/**
* @throws Exception
* @throws \Exception
*/
#[Route('admin/api/health-check')]
public function healthCheck(): JsonResponse
Expand All @@ -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(
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/Setup/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions phpmyfaq/src/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 90fb9f9

Please sign in to comment.