diff --git a/html/inc/forum_db.inc b/html/inc/forum_db.inc index c63c4a74cb..3cf5fd53ce 100644 --- a/html/inc/forum_db.inc +++ b/html/inc/forum_db.inc @@ -190,26 +190,27 @@ class BoincForumLogging { } self::$cache[$threadid] = $x; } - static function cleanup() { - // TODO - clean this up - + static function delete_aux($clause) { $db = BoincDb::get(); - $sql = "SELECT timestamp FROM ".$db->db_name.".forum_logging where userid=0 and threadid=0"; - $result=$db->do_query($sql); - if (mysql_num_rows($result)>0) { - $data=mysql_fetch_object($result); - if ($data->timestampdb_name.".forum_logging where timestamp<'".(time()-MAX_FORUM_LOGGING_TIME)."' and userid != 0"; - $db->do_query($sql); - echo mysql_error(); - $sql = "REPLACE INTO ".$db->db_name.".forum_logging set userid=0, threadid=0, timestamp='".time()."'"; - $db->do_query($sql); + return $db->delete_aux('forum_logging', $clause); + } + static function cleanup() { + // Every 28 days, delete records older than 28 days. + // Keep track of the last time we did this in a special record + // with userid = threadid = 0. + // This gets called from forum_index.php + // (i.e. each time the forum main page is loaded). + // + $fl = BoincForumLogging::lookup(0, 0); + if ($fl) { + if ($fl->timestampdb_name.".forum_logging set userid=0, threadid=0, timestamp=0"; - $db->do_query($sql); - echo mysql_error(); + // No cleanup timestamp found, make one + // + BoincForumLogging::replace(0, 0, 0); } } }