Skip to content

Commit

Permalink
refactor: improved code a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Oct 21, 2023
1 parent f4ce7a1 commit bbe57a6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 37 deletions.
2 changes: 0 additions & 2 deletions phpmyfaq/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@
//
Strings::init($currentLanguage);

$request = Request::createFromGlobals();

$routes = include __DIR__ . '/../src/api-routes.php';

$context = new RequestContext();
Expand Down
6 changes: 4 additions & 2 deletions phpmyfaq/setup/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
27 changes: 4 additions & 23 deletions phpmyfaq/setup/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Expand Down Expand Up @@ -120,8 +121,6 @@
</div>
<?php

$system = new System();
$faqConfig = Configuration::getConfigurationInstance();
$version = $faqConfig->getVersion();

$update = new Update($system, $faqConfig);
Expand Down Expand Up @@ -296,34 +295,16 @@
// Perform the queries for optimizing the database
echo '<div class="mt-5 mb-5">';
echo '<h6>Update Progress:</h6>';
echo '<div class="text-center">';

try {
$progressCallback = function ($query) {
echo "Executing query: $query" . PHP_EOL;
};
$update->applyUpdates($progressCallback);
} catch (ErrorException $exception) {
} catch (ErrorException | Exception $exception) {
echo '<p class="alert alert-danger"><strong>Error:</strong> ' . $exception->getMessage() . '</p>';
System::renderFooter();
}

/*
foreach ($query as $executeQuery) {
$result = $faqConfig->getDb()->query($executeQuery);
printf('<span title="%s">█</span>', $executeQuery);
if (!$result) {
echo '<p class="alert alert-danger"><strong>Error:</strong> Please update your version of phpMyFAQ ' .
'once again or send us a <a href="https://github.com/thorsten/phpMyFAQ/issues" target="_blank">' .
'bug report</a></p>';
printf('<p class="error"><strong>DB error:</strong> %s</p>', $faqConfig->getDb()->error());
printf('<code>%s</code>', htmlentities($executeQuery));
System::renderFooter();
}
usleep(10000);
}
*/
echo '</div>';
echo '</div>';

//
Expand Down
14 changes: 4 additions & 10 deletions phpmyfaq/src/phpMyFAQ/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -85,7 +79,7 @@ public static function getInstance(): ?DatabaseDriver
}

/**
* Returns the database type.
* Returns the database type as string
*/
public static function getType(): string
{
Expand Down
6 changes: 6 additions & 0 deletions phpmyfaq/src/phpMyFAQ/Setup/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -109,6 +112,9 @@ public function setDryRun(bool $dryRun): void
$this->dryRun = $dryRun;
}

/**
* @throws Exception
*/
private function executeQueries(callable $progressCallback): void
{
if ($this->dryRun) {
Expand Down

0 comments on commit bbe57a6

Please sign in to comment.