Skip to content

Commit

Permalink
refactor: get rid of old Alert class
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jul 8, 2024
1 parent 507c052 commit 766f3d5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
23 changes: 19 additions & 4 deletions phpmyfaq/admin/instances.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @since 2012-03-16
*/

use phpMyFAQ\Component\Alert;
use phpMyFAQ\Configuration;
use phpMyFAQ\Entity\InstanceEntity;
use phpMyFAQ\Enums\PermissionType;
use phpMyFAQ\Filesystem;
Expand All @@ -26,13 +26,16 @@
use phpMyFAQ\System;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
use phpMyFAQ\User\CurrentUser;
use Symfony\Component\HttpFoundation\Request;

if (!defined('IS_VALID_PHPMYFAQ')) {
http_response_code(400);
exit();
}

$faqConfig = Configuration::getConfigurationInstance();
$user = CurrentUser::getCurrentUser($faqConfig);

if ($user->perm->hasPermission($user->getUserId(), PermissionType::INSTANCE_EDIT->value)) {
$fileSystem = new Filesystem(PMF_ROOT_DIR);
Expand All @@ -41,6 +44,8 @@
$currentClient->setFileSystem($fileSystem);
$instanceId = Filter::filterInput(INPUT_POST, 'instance_id', FILTER_VALIDATE_INT);

$templateVars = [];

// Update client instance
if ('update-instance' === $action && is_integer($instanceId)) {
$system = new System();
Expand All @@ -61,16 +66,25 @@
}

if (is_null($updatedData->getUrl())) {
echo Alert::danger('ad_entryins_fail', $faqConfig->getDb()->error());
$templateVars = [
... $templateVars,
'updateError' => $faqConfig->getDb()->error(),
];
} else {
if ($updatedClient->update($instanceId, $updatedData)) {
if ($moveInstance) {
$updatedClient->moveClientFolder($originalData->url, $updatedData->getUrl());
$updatedClient->deleteClientFolder($originalData->url);
}
echo Alert::success('ad_config_saved');
$templateVars = [
... $templateVars,
'updateSuccess' => Translation::get('ad_config_saved'),
];
} else {
echo Alert::danger('ad_entryins_fail', $faqConfig->getDb()->error());
$templateVars = [
... $templateVars,
'updateError' => $faqConfig->getDb()->error(),
];
}
}
}
Expand All @@ -81,6 +95,7 @@
}

$templateVars = [
... $templateVars,
'userPermInstanceAdd' => $user->perm->hasPermission($user->getUserId(), PermissionType::INSTANCE_ADD->value),
'multisiteFolderIsWritable' => is_writable(PMF_ROOT_DIR . DIRECTORY_SEPARATOR . 'multisite'),
'ad_instance_add' => Translation::get('ad_instance_add'),
Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/admin/statistics.sessions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* @since 2003-02-24
*/

use phpMyFAQ\Component\Alert;
use phpMyFAQ\Configuration;
use phpMyFAQ\Date;
use phpMyFAQ\Enums\PermissionType;
Expand Down Expand Up @@ -112,5 +111,5 @@

echo $template->render($templateVars);
} else {
echo Alert::danger('err_NotAuth');
require __DIR__ . '/no-permission.php';
}
2 changes: 0 additions & 2 deletions phpmyfaq/admin/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Elastic\Elasticsearch\Exception\ClientResponseException;
use Elastic\Elasticsearch\Exception\ServerResponseException;
use Elastic\Transport\Exception\NoNodeAvailableException;
use phpMyFAQ\Component\Alert;
use phpMyFAQ\Configuration;
use phpMyFAQ\Database;
use phpMyFAQ\Enums\PermissionType;
Expand Down Expand Up @@ -51,7 +50,6 @@
} catch (ClientResponseException | ServerResponseException | NoNodeAvailableException $e) {
$faqConfig->getLogger()->error('Error while fetching Elasticsearch information', [$e->getMessage()]);
$esInformation = 'n/a';
echo Alert::danger('ad_entryins_fail');
}
} else {
$esInformation = 'n/a';
Expand Down
12 changes: 12 additions & 0 deletions phpmyfaq/assets/templates/admin/configuration/instances.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endif %}
{% if updateError %}
<div class="alert alert-danger alert-dismissible fade show mt-2">
{{ updateError }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endif %}
{% if updateSuccess %}
<div class="alert alert-success alert-dismissible fade show mt-2">
{{ updateSuccess }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endif %}
<table class="table">
<thead>
<tr>
Expand Down

0 comments on commit 766f3d5

Please sign in to comment.