From 44522d9e197544aa247bd76767d644c2afa0dca2 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 22 Jun 2019 00:20:59 +0300 Subject: [PATCH] Admin Panel: Tools #170 #165 - next round of implementation --- .../admin/app/Controllers/ToolsController.php | 45 ++++++++++++++++++- site/plugins/admin/routes/web.php | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/site/plugins/admin/app/Controllers/ToolsController.php b/site/plugins/admin/app/Controllers/ToolsController.php index 6e3cfb16..4737d2ea 100644 --- a/site/plugins/admin/app/Controllers/ToolsController.php +++ b/site/plugins/admin/app/Controllers/ToolsController.php @@ -3,6 +3,8 @@ namespace Flextype; use function Flextype\Component\I18n\__; +use Flextype\Component\Filesystem\Filesystem; +use Flextype\Component\Number\Number; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; @@ -82,11 +84,18 @@ class ToolsController extends Controller public function cache(Request $request, Response $response) : Response { + $doctrine_size = Number::byteFormat($this->getDirectorySize(PATH['cache'] . '/doctrine')); + $glide_size = Number::byteFormat($this->getDirectorySize(PATH['cache'] . '/glide')); + $twig_size = Number::byteFormat($this->getDirectorySize(PATH['cache'] . '/twig')); + return $this->view->render( $response, 'plugins/admin/views/templates/system/tools/cache.html', [ 'menu_item' => 'tools', + 'doctrine_size' => $doctrine_size, + 'glide_size' => $glide_size, + 'twig_size' => $twig_size, 'links' => [ 'information' => [ 'link' => $this->router->pathFor('admin.tools.index'), @@ -98,8 +107,42 @@ class ToolsController extends Controller 'title' => __('admin_cache'), 'attributes' => ['class' => 'navbar-item active'] ], - ] + ], + 'buttons' => [ + 'settings_clear_cache' => [ + 'type' => 'action', + 'id' => 'clear-cache', + 'link' => $this->router->pathFor('admin.settings.clear-cache'), + 'title' => __('admin_clear_cache_all'), + 'attributes' => ['class' => 'float-right btn'] + ] + ] ] ); } + + + public function clearCacheProcess($request, $response) + { + $id = $request->getParsedBody()['cache-id']; + + $this->cache->clear($id); + + $this->flash->addMessage('success', __('admin_message_cache_files_deleted')); + + return $response->withRedirect($this->router->pathFor('admin.tools.cache')); + } + + + public function getDirectorySize($path) + { + $bytestotal = 0; + $path = realpath($path); + if($path!==false && $path!='' && file_exists($path)){ + foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS)) as $object){ + $bytestotal += $object->getSize(); + } + } + return $bytestotal; + } } diff --git a/site/plugins/admin/routes/web.php b/site/plugins/admin/routes/web.php index 1b7ac07a..efe6934f 100644 --- a/site/plugins/admin/routes/web.php +++ b/site/plugins/admin/routes/web.php @@ -85,5 +85,6 @@ $app->group('/' . $admin_route, function () use ($flextype, $app) { $app->get('/tools', 'ToolsController:index')->setName('admin.tools.index'); $app->get('/tools/information', 'ToolsController:information')->setName('admin.tools.information'); $app->get('/tools/cache', 'ToolsController:cache')->setName('admin.tools.cache'); + $app->post('/tools/cache', 'ToolsController:clearCacheProcess')->setName('admin.tools.clearCacheProcess'); })->add(new AuthMiddleware($flextype));