function log_retention_clean() { log_write("debug", "changelog", "Executing log_retention_clean()"); log_write("debug", "changelog", "A retention clean is required - last one was more than 24 hours ago."); // calc date to clean up to $clean_time = time() - $GLOBALS["config"]["LOG_RETENTION_PERIOD"] * 86400; $clean_date = time_format_humandate($clean_time); // clean $obj_sql_clean = new sql_query(); $obj_sql_clean->string = "DELETE FROM logs WHERE timestamp <= '{$clean_time}'"; $obj_sql_clean->execute(); $clean_removed = $obj_sql_clean->fetch_affected_rows(); unset($obj_sql_clean); // update rentention time check $obj_sql_clean = new sql_query(); $obj_sql_clean->string = "UPDATE `config` SET value='" . time() . "' WHERE name='LOG_RETENTION_CHECKTIME' LIMIT 1"; $obj_sql_clean->execute(); unset($obj_sql_clean); // add audit entry - we have to set the LOG_RETENTION_CHECKTIME variable here to avoid // looping the program, as the SQL change above won't be applied until the current transaction // is commited. $GLOBALS["config"]["LOG_RETENTION_CHECKTIME"] = time(); $this->log_post("audit", "Automated log retention clean completed, removed {$clean_removed} records order than {$clean_date}"); // complete log_write("debug", "changelog", "Completed retention log clean, removed {$clean_removed} log records older than {$clean_date}"); return 1; }