diff --git a/phpmyfaq/api/index.php b/phpmyfaq/api/index.php index ab88550e1a..9ffaefd095 100644 --- a/phpmyfaq/api/index.php +++ b/phpmyfaq/api/index.php @@ -72,8 +72,6 @@ // Strings::init($currentLanguage); -$request = Request::createFromGlobals(); - $routes = include __DIR__ . '/../src/api-routes.php'; $context = new RequestContext(); diff --git a/phpmyfaq/setup/index.php b/phpmyfaq/setup/index.php index 9edebd859e..6e433623cb 100644 --- a/phpmyfaq/setup/index.php +++ b/phpmyfaq/setup/index.php @@ -22,11 +22,13 @@ */ use Composer\Autoload\ClassLoader; -use phpMyFAQ\Component\Alert;use phpMyFAQ\Core\Exception; +use phpMyFAQ\Component\Alert; +use phpMyFAQ\Core\Exception; use phpMyFAQ\Language\LanguageCodes; use phpMyFAQ\Setup\Installer; use phpMyFAQ\Strings; -use phpMyFAQ\System;use phpMyFAQ\Translation; +use phpMyFAQ\System; +use phpMyFAQ\Translation; define('PMF_ROOT_DIR', dirname(__FILE__, 2)); const PMF_SRC_DIR = PMF_ROOT_DIR . '/src'; diff --git a/phpmyfaq/setup/update.php b/phpmyfaq/setup/update.php index 6508a0b314..e09ef1fd51 100644 --- a/phpmyfaq/setup/update.php +++ b/phpmyfaq/setup/update.php @@ -23,7 +23,6 @@ use phpMyFAQ\Database; use phpMyFAQ\Filter; use phpMyFAQ\Permission\BasicPermission; -use phpMyFAQ\Setup\Installer; use phpMyFAQ\Setup\Update; use phpMyFAQ\Strings; use phpMyFAQ\System; @@ -48,7 +47,9 @@ $version = Filter::filterInput(INPUT_POST, 'version', FILTER_SANITIZE_SPECIAL_CHARS); $query = []; -$update = new Update(new System(), Configuration::getConfigurationInstance()); +$system = new System(); +$faqConfig = Configuration::getConfigurationInstance(); +$update = new Update($system, $faqConfig); if (!$update->checkDatabaseFile()) { $redirect = new RedirectResponse('./index.php'); @@ -120,8 +121,6 @@ getVersion(); $update = new Update($system, $faqConfig); @@ -296,34 +295,16 @@ // Perform the queries for optimizing the database echo '
'; echo '
Update Progress:
'; - echo '
'; try { $progressCallback = function ($query) { echo "Executing query: $query" . PHP_EOL; }; $update->applyUpdates($progressCallback); - } catch (ErrorException $exception) { + } catch (ErrorException | Exception $exception) { echo '

Error: ' . $exception->getMessage() . '

'; - System::renderFooter(); } - /* - foreach ($query as $executeQuery) { - $result = $faqConfig->getDb()->query($executeQuery); - printf('', $executeQuery); - if (!$result) { - echo '

Error: Please update your version of phpMyFAQ ' . - 'once again or send us a ' . - 'bug report

'; - printf('

DB error: %s

', $faqConfig->getDb()->error()); - printf('%s', htmlentities($executeQuery)); - System::renderFooter(); - } - usleep(10000); - } - */ - echo '
'; echo '
'; // diff --git a/phpmyfaq/src/phpMyFAQ/Database.php b/phpmyfaq/src/phpMyFAQ/Database.php index 066a23c1ad..3b32572078 100755 --- a/phpmyfaq/src/phpMyFAQ/Database.php +++ b/phpmyfaq/src/phpMyFAQ/Database.php @@ -31,19 +31,13 @@ */ class Database { - /** - * Instance. - */ + /** @var DatabaseDriver|null */ private static ?DatabaseDriver $instance = null; - /** - * Database type. - */ + /** @var string Database type. */ private static string $dbType; - /** - * Table prefix. - */ + /** @var string|null Table prefix */ private static ?string $tablePrefix = null; /** @@ -85,7 +79,7 @@ public static function getInstance(): ?DatabaseDriver } /** - * Returns the database type. + * Returns the database type as string */ public static function getType(): string { diff --git a/phpmyfaq/src/phpMyFAQ/Setup/Update.php b/phpmyfaq/src/phpMyFAQ/Setup/Update.php index d98da2978d..25b2886f4c 100644 --- a/phpmyfaq/src/phpMyFAQ/Setup/Update.php +++ b/phpmyfaq/src/phpMyFAQ/Setup/Update.php @@ -57,6 +57,9 @@ public function isConfigTableAvailable(DatabaseDriver $database): bool return $database->numRows($result) === 0; } + /** + * @throws Exception + */ public function applyUpdates(callable $progressCallback): bool { // 3.1 updates @@ -109,6 +112,9 @@ public function setDryRun(bool $dryRun): void $this->dryRun = $dryRun; } + /** + * @throws Exception + */ private function executeQueries(callable $progressCallback): void { if ($this->dryRun) {