From 0ac1131e8c3396d0476734137938c022a6bc7b69 Mon Sep 17 00:00:00 2001 From: "Willy \"Linty" Date: Mon, 4 Dec 2023 17:34:52 +0100 Subject: [PATCH] Issue #1854 adding a new tab in maintenance page --- admin/include/add_core_tabs.inc.php | 11 +- admin/maintenance.php | 68 +++- admin/maintenance_actions.php | 1 + admin/maintenance_sys.php | 374 ++++++++++++++++++ admin/themes/default/js/maintenance_sys.js | 116 ++++++ .../default/template/maintenance_actions.tpl | 30 +- .../default/template/maintenance_sys.tpl | 209 ++++++++++ language/en_UK/admin.lang.php | 3 + language/fr_FR/admin.lang.php | 3 + 9 files changed, 794 insertions(+), 21 deletions(-) create mode 100644 admin/maintenance_sys.php create mode 100644 admin/themes/default/js/maintenance_sys.js create mode 100644 admin/themes/default/template/maintenance_sys.tpl diff --git a/admin/include/add_core_tabs.inc.php b/admin/include/add_core_tabs.inc.php index ce1473585..37be24774 100644 --- a/admin/include/add_core_tabs.inc.php +++ b/admin/include/add_core_tabs.inc.php @@ -77,11 +77,11 @@ function add_core_tabs($sheets, $tab_id) case 'configuration': global $conf_link; - $sheets['main'] = array('caption' => l10n('General'), 'url' => $conf_link.'main'); - $sheets['sizes'] = array('caption' => l10n('Photo sizes'), 'url' => $conf_link.'sizes'); - $sheets['watermark'] = array('caption' => l10n('Watermark'), 'url' => $conf_link.'watermark'); - $sheets['display'] = array('caption' => l10n('Display'), 'url' => $conf_link.'display'); - $sheets['comments'] = array('caption' => l10n('Comments'), 'url' => $conf_link.'comments'); + $sheets['main'] = array('caption' => ''.l10n('General'), 'url' => $conf_link.'main'); + $sheets['sizes'] = array('caption' => ''.l10n('Photo sizes'), 'url' => $conf_link.'sizes'); + $sheets['watermark'] = array('caption' => ''.l10n('Watermark'), 'url' => $conf_link.'watermark'); + $sheets['display'] = array('caption' => ''.l10n('Display'), 'url' => $conf_link.'display'); + $sheets['comments'] = array('caption' => ''.l10n('Comments'), 'url' => $conf_link.'comments'); // $sheets['default'] = array('caption' => l10n('Guest Settings'), 'url' => $conf_link.'default'); break; @@ -186,6 +186,7 @@ function add_core_tabs($sheets, $tab_id) global $my_base_url; $sheets['actions'] = array('caption' => ''.l10n('Actions'), 'url' => $my_base_url.'maintenance&tab=actions'); $sheets['env'] = array('caption' => ''.l10n('Environment'), 'url' => $my_base_url.'maintenance&tab=env'); + $sheets['sys'] = array('caption' => ''.l10n('System Activities'), 'url' => $my_base_url.'maintenance&tab=sys'); break; } diff --git a/admin/maintenance.php b/admin/maintenance.php index 2e3820252..4af358a3a 100644 --- a/admin/maintenance.php +++ b/admin/maintenance.php @@ -24,6 +24,72 @@ if (isset($_GET['action'])) { check_pwg_token(); } +// +-----------------------------------------------------------------------+ +// | Commons parameters | +// +-----------------------------------------------------------------------+ + +$maint_actions = array( + 'derivatives' => array( + 'icon' => 'icon-trash-1', + 'label' => l10n('Delete multiple size images'), + ), + 'lock_gallery' => array( + 'icon' => 'icon-lock', + 'label' => l10n('Lock gallery'), + ), + 'unlock_gallery' => array( + 'icon' => 'icon-lock', + 'label' => l10n('Unlock gallery'), + ), + 'categories' => array( + 'icon' => 'icon-folder-open', + 'label' => l10n('Update albums informations'), + ), + 'images' => array( + 'icon' => 'icon-info-circled-1', + 'label' => l10n('Update photos information'), + ), + 'delete_orphan_tags' => array( + 'icon' => 'icon-tags', + 'label' => l10n('Delete orphan tags'), + ), + 'user_cache' => array( + 'icon' => 'icon-user-1', + 'label' => l10n('Purge user cache'), + ), + 'history_detail' => array( + 'icon' => 'icon-back-in-time', + 'label' => l10n('Purge history detail'), + ), + 'history_summary' => array( + 'icon' => 'icon-back-in-time', + 'label' => l10n('Purge history summary'), + ), + 'sessions' => array( + 'icon' => 'icon-th-list', + 'label' => l10n('Purge sessions'), + ), + 'feeds' => array( + 'icon' => 'icon-bell', + 'label' => l10n('Purge never used notification feeds'), + ), + 'database' => array( + 'icon' => 'icon-database', + 'label' => l10n('Repair and optimize database'), + ), + 'c13y' => array( + 'icon' => 'icon-ok', + 'label' => l10n('Reinitialize check integrity'), + ), + 'search' => array( + 'icon' => 'icon-search', + 'label' => l10n('Purge search history'), + ), + 'compiled-templates' => array( + 'icon' => 'icon-file-code', + 'label' => l10n('Purge compiled templates'), + ), +); // +-----------------------------------------------------------------------+ // | tabs | @@ -34,7 +100,7 @@ $my_base_url = get_root_url().'admin.php?page='; if (isset($_GET['tab'])) { - check_input_parameter('tab', $_GET, false, '/^(actions|env)$/'); + check_input_parameter('tab', $_GET, false, '/^(actions|env|sys)$/'); $page['tab'] = $_GET['tab']; } else diff --git a/admin/maintenance_actions.php b/admin/maintenance_actions.php index 8d6db5674..c001a2a1d 100644 --- a/admin/maintenance_actions.php +++ b/admin/maintenance_actions.php @@ -282,6 +282,7 @@ list($db_current_date) = pwg_db_fetch_row(pwg_query('SELECT now();')); $template->assign( array( + 'maint_actions' => $maint_actions, 'U_MAINT_CATEGORIES' => sprintf($url_format, 'categories'), 'U_MAINT_IMAGES' => sprintf($url_format, 'images'), 'U_MAINT_ORPHAN_TAGS' => sprintf($url_format, 'delete_orphan_tags'), diff --git a/admin/maintenance_sys.php b/admin/maintenance_sys.php new file mode 100644 index 000000000..9267c31eb --- /dev/null +++ b/admin/maintenance_sys.php @@ -0,0 +1,374 @@ + 'empty', + ); + + // For each categories (Core, Plugin and Theme) we need to format theirs actions + switch ($rows['object_id']) + { + case ACTIVITY_SYSTEM_CORE: + $object_icon = 'icon-heart'; + $object = l10n('Core'); + + switch ($rows['action']) + { + case 'install': + $action_icon = 'icon-download'; + $action_color = 'icon-green'; + $action = l10n('Install'); + break; + + case 'config': + $action_icon = 'icon-cog-alt'; + $action_color = 'icon-yellow'; + $action = l10n('Configuration'); + // for config we need to specific format details + if (isset($details['config_section'])) + { + $c_icon = ''; + $c_text = ''; + switch ($details['config_section']) + { + case 'main': + $c_icon = 'icon-cog'; + $c_text = l10n('General'); + break; + + case 'watermark': + $c_icon = 'icon-file-image'; + $c_text = l10n('Watermark'); + break; + + case 'sizes': + $c_icon = 'icon-zoom-square'; + $c_text = l10n('Photo sizes'); + // sizes have 2 params always Photo sizes and sometimes config_action + if (isset($details['config_action']) && 'restore_settings' == $details['config_action']) + { + $detail[] = array( + 'icon' => 'icon-back-in-time', + 'text' => l10n('Set as default') + ); + } + break; + + case 'comments': + $c_icon = 'icon-chat'; + $c_text = l10n('Comments'); + break; + + case 'display': + $c_icon = 'icon-television'; + $c_text = l10n('Display'); + break; + + default: + $c_icon = 'icon-cog-alt'; + $c_text = $details['config_section']; + break; + } + + $detail['type'] = 'config_section'; + $detail[] = array( + 'icon' => $c_icon, + 'text' => $c_text + ); + } + break; + + case 'maintenance': + $action_icon = 'icon-cone'; + $action_color = 'icon-yellow'; + $action = l10n('Maintenance'); + // for maintenance we need to specific format details + if (isset($details['maintenance_action'])) + { + $action_detail = $details['maintenance_action']; + $detail = array( + 'type' => 'maintenance_action', + 'icon' => $maint_actions[$action_detail]['icon'] ?? 'icon-cone', + 'text' => $maint_actions[$action_detail]['label'] ?? $action_detail, + ); + } + break; + + case 'update': + $action_icon = 'icon-arrows-cw'; + $action_color = 'icon-blue'; + $action = l10n('Update'); + $major_infos = true; + break; + + case 'autoupdate': + $action_icon = 'icon-arrows-cw'; + $action_color = 'icon-blue'; + $action = l10n('Auto-update'); + $major_infos = true; + break; + + default: + $action_icon = 'icon-download'; + $action_color = 'icon-yellow'; + break; + } + break; + + case ACTIVITY_SYSTEM_PLUGIN: + $object_icon = 'icon-puzzle'; + $object = str_replace(['_', '-'], ' ', $details['plugin_id']); + switch ($rows['action']) + { + case 'install': + $action_icon = 'icon-download'; + $action_color = 'icon-green'; + $action = l10n('Install'); + break; + + case 'update': + $action_icon = 'icon-arrows-cw'; + $action_color = 'icon-blue'; + $action = l10n('Update'); + break; + + case 'activate': + $action_icon = 'icon-check'; + $action_color = 'icon-green'; + $action = l10n('Activate'); + break; + + case 'deactivate': + $action_icon = 'icon-block'; + $action_color = 'icon-purple'; + $action = l10n('Deactivate'); + break; + + case 'uninstall': + $action_icon = 'icon-trash-1'; + $action_color = 'icon-red'; + $action = l10n('Uninstall'); + break; + + case 'restore': + $action_icon = 'icon-back-in-time'; + $action_color = 'icon-blue'; + $action = l10n('Restore'); + break; + + case 'delete': + $action_icon = 'icon-trash-1'; + $action_color = 'icon-red'; + $action = l10n('Delete'); + // for delete we need to specific format details + if (isset($details['db_version'])) + { + $detail['type'] = 'db_fs_version'; + $detail[] = array( + 'icon' => 'icon-flow-branch', + 'text' => 'database : ' . $details['db_version'] + ); + } + if (isset($details['fs_version'])) + { + $detail['type'] = 'db_fs_version'; + $detail[] = array( + 'icon' => 'icon-flow-branch', + 'text' => 'filesystem : ' . $details['fs_version'] + ); + } + break; + + case 'autoupdate': + $action_icon = 'icon-arrows-cw'; + $action_color = 'icon-blue'; + $action = l10n('Auto-update'); + break; + + default: + $action_icon = 'icon-puzzle'; + $action_color = 'icon-yellow'; + break; + } + break; + + case ACTIVITY_SYSTEM_THEME: + $object_icon = 'icon-brush'; + $object = str_replace(['_', '-'], ' ', $details['theme_id']); + + switch ($rows['action']) + { + case 'install': + $action_icon = 'icon-download'; + $action_color = 'icon-green'; + $action = l10n('Install'); + break; + + case 'activate': + $action_icon = 'icon-check'; + $action_color = 'icon-green'; + $action = l10n('Activate'); + break; + + case 'deactivate': + $action_icon = 'icon-block'; + $action_color = 'icon-purple'; + $action = l10n('Deactivate'); + break; + + case 'delete': + $action_icon = 'icon-trash-1'; + $action_color = 'icon-red'; + $action = l10n('Delete'); + break; + + case 'set_default': + $action_icon = 'icon-star'; + $action_color = 'icon-yellow'; + $action = l10n('Set as default'); + break; + + case 'update': + $action_icon = 'icon-arrows-cw'; + $action_color = 'icon-blue'; + $action = l10n('Update'); + break; + + default: + $action_icon = 'icon-brush'; + $action_color = 'icon-yellow'; + break; + } + break; + + default: + break; + } + + // For each lines we need to format theirs details (general details) + if (isset($details['from_version'])) + { + $detail = array( + 'type' => 'from_to', + array( + 'icon' => 'icon-flow-branch', + 'text' => $details['from_version'], + ), + array( + 'icon' => isset($details['to_version']) ? 'icon-flow-branch' : 'icon-block', + 'text' => isset($details['to_version']) ? $details['to_version'] : ($details['result'] ?? ''), + ), + ); + } + else if (isset($details['version'])) + { + $detail = array( + 'type' => 'version', + 'icon' => 'icon-flow-branch', + 'text' => $details['version'] + ); + } + else if (isset($details['result'])) + { + $detail = array( + 'type' => 'error', + 'icon' => 'icon-block', + 'text' => $details['result'] + ); + } + + // Format our data before send + // This data will be manipulate by maintenance_sys.js + list($date, $hour) = explode(' ', $rows['occured_on']); + $data[] = array( + 'major_infos' => $major_infos, + 'id' => $rows['activity_id'], + 'object_icon' => $object_icon, + 'object' => ucwords($object), + 'action_icon' => $action_icon, + 'action_color' => $action_color, + 'action' => $action, + 'user_id' => $rows['performed_by'], + 'username' => $rows['username'], + 'date' => format_date($date), + 'hour' => $hour, + 'detail' => $detail + ); + } + + // Now we good to send our response data + $response = array( + 'data' => $data, + ); + echo json_encode($response); + exit; + } +} +else +{ + $page['warnings'][] = str_replace('%s', l10n('user_status_webmaster'), l10n('%s status is required to edit parameters.')); +} + +// +-----------------------------------------------------------------------+ +// | template init | +// +-----------------------------------------------------------------------+ + +$template->assign('isWebmaster', (is_webmaster()) ? 1 : 0); +$template->set_filenames(array('maintenance'=>'maintenance_sys.tpl')); + +// +-----------------------------------------------------------------------+ +// | sending html code | +// +-----------------------------------------------------------------------+ + +$template->assign_var_from_handle('ADMIN_CONTENT', 'maintenance'); +?> \ No newline at end of file diff --git a/admin/themes/default/js/maintenance_sys.js b/admin/themes/default/js/maintenance_sys.js new file mode 100644 index 000000000..506887fd6 --- /dev/null +++ b/admin/themes/default/js/maintenance_sys.js @@ -0,0 +1,116 @@ +const color_icons = ["icon-red", "icon-blue", "icon-yellow", "icon-purple", "icon-green"]; + +function line_constructor(line){ + let new_line = $('#body_example').clone(); + const line_details_example = $('#line_details_example').clone(); + const initial_user = line.username.charAt(0).toUpperCase(); + + // id + new_line.attr('id', line.id); + + // Display major information + if (line.major_infos) { + new_line.addClass('major-infos'); + } + + // Display object + new_line.find('.icon_object').addClass(line.object_icon); + new_line.find('.text_object').text(line.object).attr('title', line.object); + + // Display action + new_line.find('.color_action').addClass(line.action_color); + new_line.find('.icon_action').addClass(line.action_icon); + new_line.find('.text_action').text(line.action).attr('title', line.action); + + // Display Username + 'System' == line.username + ? new_line.find('.icon_user').addClass('icon-wrench') + : new_line.find('.icon_user').addClass(color_icons[line.user_id % 5]).html(initial_user); + new_line.find('.text_username').text(line.username).attr('title', line.username); + + // Display date & hour + new_line.find('.text_date').text(line.date).attr('title', line.date + ' ' + line.hour); + new_line.find('.text_hour').text(line.hour); + + // Display Details + switch(line.detail.type){ + case 'empty': + default: + // For empty CSS do it for us but he exist + break; + + // Here is when we want to display only one element in details (and default) + case 'error': + case 'version': + case 'maintenance_action': + let new_line_detail = line_details_example.clone(); + new_line_detail.removeAttr('id'); + + new_line_detail.find('.icon_details').addClass(line.detail.icon); + new_line_detail.find('.text_details').text(line.detail.text).attr('title', line.detail.text); + new_line.find('.tab-body-details').append(new_line_detail); + break; + + // Here is when we want to display multiple elements one by one (Work if details can have one or multiple elements) + case 'db_fs_version': + case 'config_section': + Object.keys(line.detail) + .filter((key) => 'type' !== key) + .forEach((key) => { + let detail = line.detail[key]; + let new_line_details = line_details_example.clone(); + + new_line_details.removeAttr('id'); + new_line_details.find('.icon_details').addClass(detail.icon); + new_line_details.find('.text_details').text(detail.text).attr('title', detail.text); + new_line.find('.tab-body-details').append(new_line_details); + }); + break; + + // Here is when we need to specific the format for somes types + // from_to + case 'from_to': + let from = line_details_example.clone(); + from.removeAttr('id'); + from.find('.icon_details').addClass(line.detail[0].icon); + from.find('.text_details').text(line.detail[0].text).attr('title', line.detail[0].text); + new_line.find('.tab-body-details').append(from); + + new_line.find('.tab-body-details').append(' '); + + let to = line_details_example.clone(); + to.removeAttr('id'); + to.find('.icon_details').addClass(line.detail[1].icon); + to.find('.text_details').text(line.detail[1].text).attr('title', line.detail[1].text); + new_line.find('.tab-body-details').append(to); + break; + } + + $('#tab-body-content').append(new_line); +} + +function get_system_activities(){ + $.ajax({ + url: window.location.href, + type: 'GET', + data: { + method: 'pwg.activity_sys.getList' + }, + dataType: 'json', + success: (response) => { + const lines = response.data; + // help to debug + // console.log(lines); + $('.loading').hide(); + lines.forEach((line) => line_constructor(line)); + + }, + error: (e) => { + console.log(e); + } + }); +} + +$(document).ready(function() { + get_system_activities(); +}); \ No newline at end of file diff --git a/admin/themes/default/template/maintenance_actions.tpl b/admin/themes/default/template/maintenance_actions.tpl index ef6b3dc07..c9ffa4a22 100644 --- a/admin/themes/default/template/maintenance_actions.tpl +++ b/admin/themes/default/template/maintenance_actions.tpl @@ -124,26 +124,26 @@ $(".delete-size-check").click( function () { {'Global Gallery Actions'|translate}
{if (isset($U_MAINT_LOCK_GALLERY))} - {'Lock gallery'|@translate} + {$maint_actions['lock_gallery']['label']} {else} - {'Unlock gallery'|@translate} + {$maint_actions['unlock_gallery']['label']} {/if} - {'Update albums informations'|@translate} - {'Update photos information'|@translate} - {'Repair and optimize database'|@translate} - {'Reinitialize check integrity'|@translate} + {$maint_actions['categories']['label']} + {$maint_actions['images']['label']} + {$maint_actions['database']['label']} + {$maint_actions['c13y']['label']}
{'Purge Actions'|@translate}
- {'Purge user cache'|@translate} - {'Delete orphan tags'|@translate} - {'Purge history detail'|@translate} - {'Purge history summary'|@translate} - {'Purge sessions'|@translate} - {'Purge never used notification feeds'|@translate} - {'Purge search history'|@translate} + {$maint_actions['user_cache']['label']} + {$maint_actions['delete_orphan_tags']['label']} + {$maint_actions['history_detail']['label']} + {$maint_actions['history_summary']['label']} + {$maint_actions['sessions']['label']} + {$maint_actions['feeds']['label']} + {$maint_actions['search']['label']}
@@ -175,7 +175,7 @@ $(".delete-size-check").click( function () { {if $time_elapsed_since_last_calc} {$time_elapsed_since_last_calc} {else}   {"never calculated"|@translate} {/if} {'Refresh'|@translate} - {'Purge compiled templates'|@translate} + {$maint_actions['compiled-templates']['label']} {if isset($cache_sizes)} {"%s MB"|@translate:{round($cache_sizes[2]['value']/1024/1024, 2)}} @@ -187,7 +187,7 @@ $(".delete-size-check").click( function () {
- {'Delete multiple size images'|@translate} + {$maint_actions['derivatives']['label']} {if isset($cache_sizes)} {"%s MB"|@translate:{round($cache_sizes[1]['value']['all']/1024/1024, 2)}} diff --git a/admin/themes/default/template/maintenance_sys.tpl b/admin/themes/default/template/maintenance_sys.tpl new file mode 100644 index 000000000..c8549dceb --- /dev/null +++ b/admin/themes/default/template/maintenance_sys.tpl @@ -0,0 +1,209 @@ +{if $isWebmaster == 1} + {combine_css path="admin/themes/default/fontello/css/animation.css" order=10} {* order 10 is required, see issue 1080 *} + {combine_script id='sys' load='footer' path='admin/themes/default/js/maintenance_sys.js'} +
+
+
+

{'Object'|translate}

+
+
+

{'Action'|translate}

+
+
+

{'Users'|translate}

+
+
+

{'Date'|translate}

+
+
+

{'Details'|translate}

+
+
+ +
+ +
+ +
+
+

+ + Object +

+
+
+

+ + Action +

+
+
+

+ + Username +

+
+
+

+ + Date + Hour +

+
+
+

+ + Details +

+
+
+ +
+ +
+ +{/if} \ No newline at end of file diff --git a/language/en_UK/admin.lang.php b/language/en_UK/admin.lang.php index 83b969d2f..33b97f110 100644 --- a/language/en_UK/admin.lang.php +++ b/language/en_UK/admin.lang.php @@ -1351,4 +1351,7 @@ $lang['Activate button "%s"'] = 'Activate button "%s"'; $lang['Detect and avoid duplicates during upload'] = 'Detect and avoid duplicates during upload'; $lang['During upload, if Piwigo detects the photo already exists, associate the existing photo to the destination album, without duplicating file'] = 'During upload, if Piwigo detects the photo already exists, associate the existing photo to the destination album, without duplicating file'; $lang['%d files'] = "%d files"; +$lang['Auto-update'] = 'Auto-update'; +$lang['Core'] = 'Core'; +$lang['System Activities'] = 'System Activities'; // Leave this line empty diff --git a/language/fr_FR/admin.lang.php b/language/fr_FR/admin.lang.php index a88f6cb8f..dd79d0f54 100644 --- a/language/fr_FR/admin.lang.php +++ b/language/fr_FR/admin.lang.php @@ -1351,4 +1351,7 @@ $lang['Activate button "%s"'] = 'Afficher le bouton "%s"'; $lang['Detect and avoid duplicates during upload'] = 'Détecter et éviter les doublons à l\'import'; $lang['During upload, if Piwigo detects the photo already exists, associate the existing photo to the destination album, without duplicating file'] = 'Pendant l\'ajout de photo, si Piwigo détecte que la photo existe déjà, associer la photo existante à l\'album de destination, sans dupliquer le fichier.'; $lang['%d files'] = "%d fichiers"; +$lang['Auto-update'] = 'Mise à jour auto'; +$lang['Core'] = 'Noyau'; +$lang['System Activities'] = 'Activités système'; // Leave this line empty