Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/roundcube/roundcubemail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2021-10-03 13:10:14 +0300
committerAleksander Machniak <alec@alec.pl>2021-10-03 13:10:14 +0300
commit48fbf110af3f76128de7bbe7f6ce0e48247513e4 (patch)
treef6a361b7b4dfe522f52f6091e7f7bb3a676610eb /program/include/rcmail_utils.php
parent626332d42a6c4d12389b40ae57113e95f3b2ce56 (diff)
SQLite: Use foreign keys, require SQLite >= 3.6.19 (#8159)
Diffstat (limited to 'program/include/rcmail_utils.php')
-rw-r--r--program/include/rcmail_utils.php31
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);