Skip to content

Commit 3058437

Browse files
committed
fix: hardened the setup
1 parent 200c02c commit 3058437

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

phpmyfaq/src/phpMyFAQ/Controller/Frontend/SetupController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ final class SetupController
4444
public function index(Request $request): Response
4545
{
4646
$system = new System();
47+
48+
if (!$system->checkInstallation()) {
49+
return new Response('phpMyFAQ is already installed.', Response::HTTP_FORBIDDEN);
50+
}
51+
4752
$installer = new Installer($system);
4853

4954
$checkBasicError = '';
@@ -84,6 +89,11 @@ public function index(Request $request): Response
8489
public function install(): Response
8590
{
8691
$system = new System();
92+
93+
if (!$system->checkInstallation()) {
94+
return new Response('phpMyFAQ is already installed.', Response::HTTP_FORBIDDEN);
95+
}
96+
8797
$installer = new Installer($system);
8898

8999
$installationError = '';

phpmyfaq/src/phpMyFAQ/Setup/Installer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,11 @@ public function checkInitialRewriteBasePath(Request $request): bool
732732
*/
733733
public function startInstall(?array $setup = null): void
734734
{
735+
$rootDir = $setup['rootDir'] ?? PMF_ROOT_DIR;
736+
if (is_file($rootDir . '/content/core/config/database.php')) {
737+
throw new Exception('phpMyFAQ is already installed. Please use the update.');
738+
}
739+
735740
$ldapSetup = [];
736741
$query = [];
737742
$uninstall = [];

tests/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@
7474
$loader->register();
7575

7676
//
77-
// Delete a possible SQLite file first
77+
// Delete possible leftover files from previous test runs
7878
//
7979
@unlink(PMF_TEST_DIR . '/test.db');
80+
@unlink(PMF_TEST_DIR . '/content/core/config/database.php');
8081

8182
//
8283
// Create database credentials for SQLite

0 commit comments

Comments
 (0)