diff options
Diffstat (limited to 'program/include/rcmail_utils.php')
-rw-r--r-- | program/include/rcmail_utils.php | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/program/include/rcmail_utils.php b/program/include/rcmail_utils.php index 2de6009d3..9036cbcfb 100644 --- a/program/include/rcmail_utils.php +++ b/program/include/rcmail_utils.php @@ -277,43 +277,18 @@ class rcmail_utils */ public static function db_clean($days) { - $db = self::db(); - - // mapping for table name => primary key - $primary_keys = [ - 'contacts' => 'contact_id', - 'contactgroups' => 'contactgroup_id', - ]; - - $tables = [ + $db = self::db(); + $threshold = date('Y-m-d 00:00:00', time() - $days * 86400); + $tables = [ 'contacts', 'contactgroups', 'identities', 'responses', ]; - $threshold = date('Y-m-d 00:00:00', time() - $days * 86400); - foreach ($tables as $table) { $sqltable = $db->table_name($table, true); - // also delete linked records - // could be skipped for databases which respect foreign key constraints - if ($db->db_provider == 'sqlite' && ($table == 'contacts' || $table == 'contactgroups')) { - $pk = $primary_keys[$table]; - $memberstable = $db->table_name('contactgroupmembers'); - - $db->query( - "DELETE FROM " . $db->quote_identifier($memberstable) - . " WHERE `$pk` IN (" - . "SELECT `$pk` FROM $sqltable" - . " WHERE `del` = 1 AND `changed` < ?" - . ")", - $threshold); - - echo $db->affected_rows() . " records deleted from '$memberstable'\n"; - } - // delete outdated records $db->query("DELETE FROM $sqltable WHERE `del` = 1 AND `changed` < ?", $threshold); |