Added clear logs option in admin panel (#775)

This commit is contained in:
Roman Kelesidis 2023-06-05 18:32:36 +07:00 committed by GitHub
commit 88cf205962
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 24 deletions

View file

@ -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;

View file

@ -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'] = '<span class="seed bold">' . $lang['ALL_LOGS_FILE_CLEARED'] . '</span>';
break;
case 'clear_cache':
foreach ($bb_cfg['cache']['engines'] as $cache_name => $cache_val) {
if (!in_array('db_sqlite', $cache_val)) {

View file

@ -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

View file

@ -75,6 +75,7 @@
ajax.callback.manage_admin = function (data) {
$('#cache').html(data.cache_html);
$('#datastore').html(data.datastore_html);
$('#logs').html(data.logs_html);
$('#indexer').html(data.indexer_html);
$('#template_cache').html(data.template_cache_html);
$('#update_user_level').html(data.update_user_level_html);
@ -110,7 +111,9 @@
<td>
<a href="#" id="datastore" onclick="ajax.manage_admin('clear_datastore'); return false;">{L_DATASTORE}</a>&nbsp;&middot;
<a href="#" id="cache" onclick="ajax.manage_admin('clear_cache'); return false;">{L_CLEAR_CACHE}</a>&nbsp;&middot;
<a href="#" id="template_cache" onclick="ajax.manage_admin('clear_template_cache'); return false;">{L_CLEAR_TEMPLATES_CACHE}</a>
<a href="#" id="template_cache"
onclick="ajax.manage_admin('clear_template_cache'); return false;">{L_CLEAR_TEMPLATES_CACHE}</a>&nbsp;&middot;
<a href="#" id="logs" onclick="ajax.manage_admin('clear_logs'); return false;">{L_CLEAR_LOGS}</a>
</td>
</tr>
<tr>