]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #5490 log table deletion works now
authorcash <cash.costello@gmail.com>
Fri, 17 May 2013 18:32:29 +0000 (14:32 -0400)
committercash <cash.costello@gmail.com>
Fri, 17 May 2013 18:32:29 +0000 (14:32 -0400)
mod/logrotate/languages/en.php
mod/logrotate/start.php

index 3af83e553ebb3b89f5a532af18eba6e62489c1ec..d785ad50df3ea567c630c6a2fb1c18484815d812 100644 (file)
@@ -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);
index 313cf1fd5de3322995d47ba5e05cb3b0f1366163..f67e419bcf3644d04b2a8f7153c5650a32906ecb 100644 (file)
@@ -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;
 }