Skip to content

Commit c397556

Browse files
committed
fix: use database version for update migrations and always reset maintenance mode
setVersion() was called with System::getVersion() (the installed code version, e.g. 4.1.0) instead of the database version (e.g. 4.0.18). This caused version_compare('4.1.0', '4.1.0-alpha', '<') to return false, skipping all 4.1 database migrations and leaving the version number unchanged at 4.0.18. Additionally, maintenance mode is now reset to false in all error paths and the catch block handles both phpMyFAQ\Core\Exception and \Exception, preventing admin lockout when the database update fails.
1 parent c2ddbf4 commit c397556

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/UpdateController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,18 @@ public function updateDatabase(): JsonResponse
245245
$this->userHasPermission(PermissionType::CONFIGURATION_EDIT);
246246

247247
$update = $this->container->get(id: 'phpmyfaq.setup.update');
248-
$update->setVersion(System::getVersion());
248+
$update->setVersion($this->configuration->get('main.currentVersion'));
249249

250250
try {
251251
if ($update->applyUpdates()) {
252252
$this->configuration->set('main.maintenanceMode', 'false');
253253
return new JsonResponse(['success' => 'Database successfully updated.'], Response::HTTP_OK);
254254
}
255255

256+
$this->configuration->set('main.maintenanceMode', 'false');
256257
return new JsonResponse(['error' => 'Update database failed.'], Response::HTTP_BAD_GATEWAY);
257-
} catch (Exception $exception) {
258+
} catch (Exception|\Exception $exception) {
259+
$this->configuration->set('main.maintenanceMode', 'false');
258260
return new JsonResponse([
259261
'error' => 'Update database failed: ' . $exception->getMessage(),
260262
], Response::HTTP_BAD_GATEWAY);

phpmyfaq/src/phpMyFAQ/Setup/UpdateRunner.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private function taskInstallPackage(SymfonyStyle $io): int
204204
private function taskUpdateDatabase(SymfonyStyle $io): int
205205
{
206206
$update = new Update($this->system, $this->configuration);
207-
$update->setVersion(System::getVersion());
207+
$update->setVersion($this->configuration->get('main.currentVersion'));
208208

209209
$progressBar = $io->createProgressBar(max: 100);
210210
$progressBar->start();
@@ -220,11 +220,13 @@ private function taskUpdateDatabase(SymfonyStyle $io): int
220220
return Command::SUCCESS;
221221
}
222222

223+
$this->configuration->set(key: 'main.maintenanceMode', value: 'false');
223224
$io->error(message: 'Update database failed.');
224225
return Command::FAILURE;
225-
} catch (Exception $exception) {
226+
} catch (Exception|\Exception $exception) {
226227
$progressBar->finish();
227228
$io->newLine(count: 2);
229+
$this->configuration->set(key: 'main.maintenanceMode', value: 'false');
228230
$io->error(message: 'Update database failed: ' . $exception->getMessage());
229231
return Command::FAILURE;
230232
}

0 commit comments

Comments
 (0)