Browse Source

Add Clear cache to Admin\Maintenance page

Visman 2 years ago
parent
commit
68d8e27396

+ 6 - 0
app/Controllers/Routing.php

@@ -754,6 +754,12 @@ class Routing
                 'AdminMaintenance:rebuild',
                 'AdminMaintenance:rebuild',
                 'AdminRebuildIndex'
                 'AdminRebuildIndex'
             );
             );
+            $r->add(
+                $r::PST,
+                '/admin/maintenance/clear',
+                'AdminMaintenance:clearCache',
+                'AdminMaintenanceClear'
+            );
             $r->add(
             $r->add(
                 $r::GET,
                 $r::GET,
                 '/admin/logs',
                 '/admin/logs',

+ 70 - 1
app/Models/Pages/Admin/Maintenance.php

@@ -15,6 +15,7 @@ use ForkBB\Models\Page;
 use ForkBB\Models\Pages\Admin;
 use ForkBB\Models\Pages\Admin;
 use ForkBB\Models\Config\Config;
 use ForkBB\Models\Config\Config;
 use function \ForkBB\__;
 use function \ForkBB\__;
+use RuntimeException;
 
 
 class Maintenance extends Admin
 class Maintenance extends Admin
 {
 {
@@ -56,6 +57,7 @@ class Maintenance extends Admin
         $this->aIndex          = 'maintenance';
         $this->aIndex          = 'maintenance';
         $this->formMaintenance = $this->formMaintenance($config);
         $this->formMaintenance = $this->formMaintenance($config);
         $this->formRebuild     = $this->formRebuild();
         $this->formRebuild     = $this->formRebuild();
+        $this->formClearCache  = $this->formClearCache();
 
 
         return $this;
         return $this;
     }
     }
@@ -118,7 +120,7 @@ class Maintenance extends Admin
                     ],
                     ],
                 ],
                 ],
                 'indx' => [
                 'indx' => [
-                    'legend' => 'Rebuild index head',
+                    'legend' => 'Rebuilding search index',
                     'fields' => [
                     'fields' => [
                         'limit' => [
                         'limit' => [
                             'type'    => 'number',
                             'type'    => 'number',
@@ -162,6 +164,39 @@ class Maintenance extends Admin
 
 
     }
     }
 
 
+    /**
+     * Подготавливает массив данных для формы
+     */
+    protected function formClearCache(): array
+    {
+        $form = [
+            'action' => $this->c->Router->link('AdminMaintenanceClear'),
+            'hidden' => [
+                'token' => $this->c->Csrf->create('AdminMaintenanceClear'),
+            ],
+            'sets'   => [
+                'clear-cache' => [
+                    'legend' => 'Clearing the cache',
+                    'fields' => [
+                        'confirm' => [
+                            'type'    => 'checkbox',
+                            'label'   => 'Confirm action',
+                            'checked' => false,
+                        ],
+                    ],
+                ],
+            ],
+            'btns'   => [
+                'clear' => [
+                    'type'  => 'submit',
+                    'value' => __('Clear'),
+                ],
+            ],
+        ];
+
+        return $form;
+    }
+
     /**
     /**
      * Подстановка значения по умолчанию
      * Подстановка значения по умолчанию
      */
      */
@@ -239,4 +274,38 @@ class Maintenance extends Admin
             return $this->c->Redirect->page('AdminMaintenance')->message('Rebuilding index end', FORK_MESS_SUCC);
             return $this->c->Redirect->page('AdminMaintenance')->message('Rebuilding index end', FORK_MESS_SUCC);
         }
         }
     }
     }
+
+    /**
+     * Пересчитывает количество сообщений пользователей
+     */
+    public function clearCache(array $args, string $method): Page
+    {
+        $this->c->Lang->load('validator');
+        $this->c->Lang->load('admin_maintenance');
+
+        $v = $this->c->Validator->reset()
+            ->addValidators([
+            ])->addRules([
+                'confirm' => 'checkbox',
+                'token'   => 'token:AdminMaintenanceClear',
+            ])->addAliases([
+            ])->addArguments([
+            ])->addMessages([
+            ]);
+
+        if (
+            ! $v->validation($_POST)
+            || '1' !== $v->confirm
+        ) {
+            return $this->c->Message->message(
+                '1' !== $v->confirm ? 'No confirm redirect' : ($this->c->Csrf->getError() ?? 'Bad token')
+            );
+        }
+
+        if (true !== $this->c->Cache->clear()) {
+            throw new RuntimeException('Unable to clear cache');
+        }
+
+        return $this->c->Redirect->page('AdminMaintenance')->message('Clear cache redirect', FORK_MESS_SUCC);
+    }
 }
 }

+ 13 - 1
app/lang/en/admin_maintenance.po

@@ -46,7 +46,7 @@ msgid "Rebuild index"
 msgstr "Rebuild index"
 msgstr "Rebuild index"
 
 
 msgid "Rebuilding search index"
 msgid "Rebuilding search index"
-msgstr "Rebuilding search index"
+msgstr "Rebuild search index"
 
 
 msgid "Rebuilding index end"
 msgid "Rebuilding index end"
 msgstr "Rebuilding index is over."
 msgstr "Rebuilding index is over."
@@ -68,3 +68,15 @@ msgstr "The message that will be displayed to users when the board is in mainten
 
 
 msgid "Default maintenance message"
 msgid "Default maintenance message"
 msgstr "The forums are temporarily down for maintenance. <b>Please try again in a few minutes.</b>"
 msgstr "The forums are temporarily down for maintenance. <b>Please try again in a few minutes.</b>"
+
+msgid "Clear cache head"
+msgstr "Clear cache"
+
+msgid "Clearing the cache"
+msgstr "Clear cache"
+
+msgid "Clear"
+msgstr "Clear"
+
+msgid "Clear cache redirect"
+msgstr "Board cache cleared."

+ 12 - 0
app/lang/ru/admin_maintenance.po

@@ -68,3 +68,15 @@ msgstr "Сообщение, которое будет показываться 
 
 
 msgid "Default maintenance message"
 msgid "Default maintenance message"
 msgstr "Форум временно закрыт на обслуживание. <b>Пожалуйста, попробуйте зайти позже.</b>"
 msgstr "Форум временно закрыт на обслуживание. <b>Пожалуйста, попробуйте зайти позже.</b>"
+
+msgid "Clear cache head"
+msgstr "Очистка кэша"
+
+msgid "Clearing the cache"
+msgstr "Очистка кэша"
+
+msgid "Clear"
+msgstr "Очистить"
+
+msgid "Clear cache redirect"
+msgstr "Кэш форума очищен."

+ 8 - 0
app/templates/admin/maintenance.forkbb.php

@@ -12,6 +12,14 @@
         <div class="f-fdiv">
         <div class="f-fdiv">
 @if ($form = $p->formRebuild)
 @if ($form = $p->formRebuild)
     @include ('layouts/form')
     @include ('layouts/form')
+@endif
+        </div>
+      </section>
+      <section id="fork-clcch" class="f-admin">
+        <h2>{!! __('Clear cache head') !!}</h2>
+        <div class="f-fdiv">
+@if ($form = $p->formClearCache)
+    @include ('layouts/form')
 @endif
 @endif
         </div>
         </div>
       </section>
       </section>

+ 7 - 0
public/style/ForkBB/admin.css

@@ -1031,6 +1031,13 @@
   }
   }
 }
 }
 
 
+/****************************************/
+/* Админка/Обслуживание                 */
+/****************************************/
+#fork-clcch #id-dl-confirm > dt {
+  display: none;
+}
+
 /****************************************/
 /****************************************/
 /* Админка/Провайдеры                   */
 /* Админка/Провайдеры                   */
 /****************************************/
 /****************************************/