diff --git a/YOUR_ADMIN/includes/auto_loaders/config.log_manager.php b/YOUR_ADMIN/includes/auto_loaders/config.log_manager.php index 83903a5..edc9112 100644 --- a/YOUR_ADMIN/includes/auto_loaders/config.log_manager.php +++ b/YOUR_ADMIN/includes/auto_loaders/config.log_manager.php @@ -1,9 +1,9 @@ 'init_script', 'loadFile' => 'init_log_manager.php' -); \ No newline at end of file +]; diff --git a/YOUR_ADMIN/includes/init_includes/init_log_manager.php b/YOUR_ADMIN/includes/init_includes/init_log_manager.php index 1d2c1cf..cb1366c 100644 --- a/YOUR_ADMIN/includes/init_includes/init_log_manager.php +++ b/YOUR_ADMIN/includes/init_includes/init_log_manager.php @@ -1,47 +1,43 @@ Logging) haven't been set, set them now! -// -if (!defined('LOG_MANAGER_KEEP_DAYS')) { - $next_sort = $db->Execute( - "SELECT MAX(sort_order) as max_sort - FROM " . TABLE_CONFIGURATION . " - WHERE configuration_group_id = 10", - false, - false, - 0, - true - ); - $sort_order = $next_sort->fields['max_sort'] + 1; - $sort_order2 = $sort_order + 1; - $db->Execute( - "INSERT INTO " . TABLE_CONFIGURATION . " - ( configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, use_function, set_function ) - VALUES - ( 'Log Manager: Days to Keep', 'LOG_MANAGER_KEEP_DAYS', '0', 'Enter the maximum number of days to keep any file with a .log file extension in your store\'s logs directory.

If the value you enter is non-zero, then any files created prior to that relative date will be permanently removed from your store\'s file-system.
', 10, $sort_order, now(), NULL, NULL), - - ( 'Log Manager: Logs to Keep', 'LOG_MANAGER_KEEP_THESE', 'zcInstall', 'Enter a comma-separated list of name-prefixes for any log-files that you want to keep, regardless of their age.

The values you enter are case-sensitive, i.e. zcInstall is different than zcinstall. The default setting (zcInstall) results in any file matching /logs/zcInstall*.log being kept regardless of its creation date.
', 10, $sort_order2, now(), NULL, NULL)" - ); - define('LOG_MANAGER_KEEP_DAYS', '0'); - define('LOG_MANAGER_KEEP_THESE', 'zcInstall'); -} - // ----- // If the plugin is enabled and current session is associated with a logged-in admin and the plugin's processing hasn't been run // yet for this session ... manage those logs! // -if (isset($_SESSION['admin_id'])) { - if (((int)LOG_MANAGER_KEEP_DAYS) > 0 && !isset($_SESSION['log_managed'])) { +if (isset($_SESSION['admin_id']) && !isset($_SESSION['log_managed'])) { + // ----- + // If the plugin's configuration settings (in Configuration->Logging) haven't been set, set them now! + // + if (!defined('LOG_MANAGER_KEEP_DAYS')) { + $next_sort = $db->ExecuteNoCache( + "SELECT MAX(sort_order) as max_sort + FROM " . TABLE_CONFIGURATION . " + WHERE configuration_group_id = 10", + ); + $sort_order = $next_sort->fields['max_sort'] + 1; + $sort_order2 = $sort_order + 1; + $db->Execute( + "INSERT INTO " . TABLE_CONFIGURATION . " + (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, use_function, set_function) + VALUES + ('Log Manager: Days to Keep', 'LOG_MANAGER_KEEP_DAYS', '0', 'Enter the maximum number of days to keep any file with a .log file extension in your store\'s logs directory.

If the value you enter is non-zero, then any files created prior to that relative date will be permanently removed from your store\'s file-system.
', 10, $sort_order, now(), NULL, NULL), + + ('Log Manager: Logs to Keep', 'LOG_MANAGER_KEEP_THESE', 'zcInstall', 'Enter a comma-separated list of name-prefixes for any log-files that you want to keep, regardless of their age.

The values you enter are case-sensitive, i.e. zcInstall is different than zcinstall. The default setting (zcInstall) results in any file matching /logs/zcInstall*.log being kept regardless of its creation date.
', 10, $sort_order2, now(), NULL, NULL)" + ); + define('LOG_MANAGER_KEEP_DAYS', '0'); + define('LOG_MANAGER_KEEP_THESE', 'zcInstall'); + } + + if (((int)LOG_MANAGER_KEEP_DAYS) > 0) { // ----- // Build up a string-to-match (via preg_match) for the .log files that should be "kept". That string // contains the log-file name prefixes. // $match_string = ''; - if (LOG_MANAGER_KEEP_THESE != '') { + if (LOG_MANAGER_KEEP_THESE !== '') { $logs_to_keep = explode(',', str_replace(' ', '', LOG_MANAGER_KEEP_THESE)); if (count($logs_to_keep) > 1) { $match_string = '/^(' . implode('|', $logs_to_keep) . ').*$/'; @@ -49,13 +45,13 @@ $match_string = '/^' . $logs_to_keep[0] . '.*$/'; } } - + // ----- // Determine the keep-until date (some number of days **prior to** today). // $keep_until = strtotime('-' . LOG_MANAGER_KEEP_DAYS . ' day'); $keep_until_date = date(DATE_FORMAT . ' H:m:i', $keep_until); - + // ----- // Loop through all files present in the /logs directory ... // @@ -84,7 +80,7 @@ } $dir->close(); } - + // ----- // If one or more files was removed, let the admin know (via message) and log the removal action. // @@ -94,7 +90,7 @@ error_log(date(PHP_DATE_TIME_FORMAT) . ', ' . $_SESSION['admin_id'] . ": $logMessage" . PHP_EOL, 3, DIR_FS_LOGS . '/log_manager_removal.log'); } } - + // ----- // Note that the plugin's processing has been run for the current admin session. // diff --git a/docs/log_manager/readme.html b/docs/log_manager/readme.html index 96e7131..0ffac91 100644 --- a/docs/log_manager/readme.html +++ b/docs/log_manager/readme.html @@ -1,14 +1,13 @@ - + - - + + - + Zen Cart Log Manager - - - - - + +