aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/lib/system_log.php9
-rw-r--r--mod/logrotate/start.php15
2 files changed, 21 insertions, 3 deletions
diff --git a/engine/lib/system_log.php b/engine/lib/system_log.php
index 2c07d8489..c6a91364f 100644
--- a/engine/lib/system_log.php
+++ b/engine/lib/system_log.php
@@ -234,15 +234,20 @@
/**
* This function creates an archive copy of the system log.
+ *
+ * @param int $offset An offset in seconds from now to archive (useful for log rotation)
*/
- function archive_log()
+ function archive_log($offset = 0)
{
global $CONFIG;
+ $offset = (int)$offset;
$now = time(); // Take a snapshot of now
+
+ $ts = $now - $offset;
// create table
- if (!update_data("CREATE TABLE {$CONFIG->dbprefix}system_log_$now as SELECT * from {$CONFIG->dbprefix}system_log WHERE time_created<=$now"))
+ if (!update_data("CREATE TABLE {$CONFIG->dbprefix}system_log_$now as SELECT * from {$CONFIG->dbprefix}system_log WHERE time_created<=$ts"))
return false;
// alter table to engine
diff --git a/mod/logrotate/start.php b/mod/logrotate/start.php
index f9a9a0449..349b5ad84 100644
--- a/mod/logrotate/start.php
+++ b/mod/logrotate/start.php
@@ -36,7 +36,20 @@
function logrotate_cron($hook, $entity_type, $returnvalue, $params)
{
$resulttext = elgg_echo("logrotate:logrotated");
- if (!archive_log())
+
+ $day = 86400;
+
+ $offset = 0;
+ $period = get_plugin_setting('period','logrotate');
+ switch ($period)
+ {
+ case 'weekly': $offset = $day * 7; break;
+ case 'yearly' : $offset = $day * 365; break;
+ case 'monthly' : // assume 28 days even if a month is longer. Won't cause data loss.
+ default: $offset = $day * 28;;
+ }
+
+ if (!archive_log($offset))
$resulttext = elgg_echo("logrotate:lognotrotated");
return $returnvalue . $resulttext;