aboutsummaryrefslogtreecommitdiff
path: root/mod
diff options
context:
space:
mode:
Diffstat (limited to 'mod')
-rw-r--r--mod/logrotate/languages/en.php2
-rw-r--r--mod/logrotate/start.php46
2 files changed, 23 insertions, 25 deletions
diff --git a/mod/logrotate/languages/en.php b/mod/logrotate/languages/en.php
index 3af83e553..d785ad50d 100644
--- a/mod/logrotate/languages/en.php
+++ b/mod/logrotate/languages/en.php
@@ -23,7 +23,7 @@ $english = array(
'logrotate:never' => 'never',
'logrotate:logdeleted' => "Log deleted\n",
- 'logrotate:lognotdeleted' => "Error deleting log\n",
+ 'logrotate:lognotdeleted' => "No logs deleted\n",
);
add_translation("en", $english);
diff --git a/mod/logrotate/start.php b/mod/logrotate/start.php
index 313cf1fd5..f67e419bc 100644
--- a/mod/logrotate/start.php
+++ b/mod/logrotate/start.php
@@ -21,7 +21,7 @@ function logrotate_init() {
// Register cron hook for archival of logs
elgg_register_plugin_hook_handler('cron', $period, 'logrotate_archive_cron');
-
+
if ($delete != 'never') {
// Register cron hook for deletion of selected archived logs
elgg_register_plugin_hook_handler('cron', $delete, 'logrotate_delete_cron');
@@ -91,34 +91,32 @@ function logrotate_delete_cron($hook, $entity_type, $returnvalue, $params) {
/**
* This function deletes archived copies of the system logs that are older than specified.
*
- * @param int $time_of_delete An offset in seconds from now to delete (useful for log deletion)
+ * @param int $time_of_delete An offset in seconds from now to delete log tables
+ * @return bool Were any log tables deleted
*/
function log_browser_delete_log($time_of_delete) {
global $CONFIG;
- $offset = (int)$time_of_delete;
- $now = time();
-
- $ts = $now - $offset;
-
- $FLAG = 1;
- $result = mysql_query("SHOW TABLES like '{$CONFIG->dbprefix}system_log_%'");
- while ($showtablerow = mysql_fetch_array($result)) {
- //To obtain time of archival
- $log_time = explode("{$CONFIG->dbprefix}system_log_", $showtablerow[0]);
- if ($log_time < $ts) {
- //If the time of archival is before the required offset then delete
- if (!mysql_query("DROP TABLE $showtablerow[0]")) {
- $FLAG = 0;
- }
+ $cutoff = time() - (int)$time_of_delete;
+
+ $deleted_tables = false;
+ $results = get_data("SHOW TABLES like '{$CONFIG->dbprefix}system_log_%'");
+ if ($results) {
+ foreach ($results as $result) {
+ $data = (array)$result;
+ $table_name = array_shift($data);
+ // extract log table rotation time
+ $log_time = str_replace("{$CONFIG->dbprefix}system_log_", '', $table_name);
+ if ($log_time < $cutoff) {
+ if (delete_data("DROP TABLE $table_name") !== false) {
+ // delete_data returns 0 when dropping a table (false for failure)
+ $deleted_tables = true;
+ } else {
+ elgg_log("Failed to delete the log table $table_name", 'ERROR');
+ }
+ }
}
}
- //Check if the appropriate tables have been deleted and return true if yes
- if ($FLAG) {
- return true;
- } else {
- return false;
- }
-
+ return $deleted_tables;
}