From 88cf205962dbc13827169f239169f3fc1b5a1bd0 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Mon, 5 Jun 2023 18:32:36 +0700 Subject: [PATCH] Added clear logs option in admin panel (#775) --- common.php | 16 +++++++++++ library/ajax/manage_admin.php | 6 ++++ library/language/source/main.php | 4 ++- styles/templates/admin/index.tpl | 49 +++++++++++++++++--------------- 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/common.php b/common.php index 66c689206..6541d8400 100644 --- a/common.php +++ b/common.php @@ -211,6 +211,22 @@ function bb_log($msg, $file_name, $return_path = false) return file_write($msg, $path); } +/** + * Remove files recursively by extension + * + * @param string $path + * @param array $findExtension + * @return void + */ +function remove_files_by_extension(string $path, array $findExtension) +{ + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $file) { + if (in_array(pathinfo($file, PATHINFO_EXTENSION), $findExtension) && is_file($file)) { + unlink($file); + } + } +} + function file_write($str, $file, $max_size = LOG_MAX_SIZE, $lock = true, $replace_content = false) { $bytes_written = false; diff --git a/library/ajax/manage_admin.php b/library/ajax/manage_admin.php index 486b467a4..76e866fd8 100644 --- a/library/ajax/manage_admin.php +++ b/library/ajax/manage_admin.php @@ -16,6 +16,12 @@ global $userdata, $lang, $bb_cfg; $mode = (string)$this->request['mode']; switch ($mode) { + case 'clear_logs': + remove_files_by_extension(LOG_DIR, ['log']); + + $this->response['logs_html'] = '' . $lang['ALL_LOGS_FILE_CLEARED'] . ''; + break; + case 'clear_cache': foreach ($bb_cfg['cache']['engines'] as $cache_name => $cache_val) { if (!in_array('db_sqlite', $cache_val)) { diff --git a/library/language/source/main.php b/library/language/source/main.php index e69af09ff..a03f1b20a 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -101,6 +101,7 @@ $lang['CLICK_RETURN_GROUP'] = 'Click %sHere%s to return to group information'; $lang['ADMIN_PANEL'] = 'Go to Administration Panel'; $lang['ALL_CACHE_CLEARED'] = 'Cache has been cleared'; +$lang['ALL_LOGS_FILE_CLEARED'] = 'Log files has been removed'; $lang['ALL_TEMPLATE_CLEARED'] = 'Template cache has been cleared'; $lang['DATASTORE_CLEARED'] = 'Datastore has been cleared'; $lang['BOARD_DISABLE'] = 'Sorry, this forum is disabled. Try to come back later'; @@ -1645,7 +1646,8 @@ $lang['NOT_AVAILABLE'] = 'Not available'; // Clear Cache $lang['DATASTORE'] = 'Datastore'; -$lang['CLEAR_CACHE'] = 'Clear Cache'; +$lang['CLEAR_CACHE'] = 'Cache'; +$lang['CLEAR_LOGS'] = 'Log files'; $lang['CLEAR_TEMPLATES_CACHE'] = 'Templates cache'; // Update diff --git a/styles/templates/admin/index.tpl b/styles/templates/admin/index.tpl index f62031925..932897db4 100644 --- a/styles/templates/admin/index.tpl +++ b/styles/templates/admin/index.tpl @@ -65,23 +65,24 @@
@@ -106,12 +107,14 @@ - - + +
{L_CLEAR}: - {L_DATASTORE} · - {L_CLEAR_CACHE} · - {L_CLEAR_TEMPLATES_CACHE} - {L_CLEAR}: + {L_DATASTORE} · + {L_CLEAR_CACHE} · + {L_CLEAR_TEMPLATES_CACHE} · + {L_CLEAR_LOGS} +
{L_UPDATE}: