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:
-rw-r--r--CHANGELOG.md1
-rw-r--r--INSTALL2
-rw-r--r--SQL/mssql.initial.sql2
-rw-r--r--SQL/mssql/2021100300.sql1
-rw-r--r--SQL/mysql.initial.sql2
-rw-r--r--SQL/mysql/2021100300.sql1
-rw-r--r--SQL/oracle.initial.sql2
-rw-r--r--SQL/oracle/2021100300.sql1
-rw-r--r--SQL/postgres.initial.sql2
-rw-r--r--SQL/postgres/2021100300.sql1
-rw-r--r--SQL/sqlite.initial.sql84
-rw-r--r--SQL/sqlite/2021100300.sql211
-rwxr-xr-xbin/deluser.sh7
-rw-r--r--program/include/rcmail_utils.php31
-rw-r--r--program/lib/Roundcube/db/sqlite.php5
15 files changed, 279 insertions, 74 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 742375fd3..9f2dc0d23 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
- Dropped support for PHP < 7.3 (#7976)
- Dropped support for strftime-like format (with % sign) in date and time format configuration
+- SQLite: Use foreign keys, require SQLite >= 3.6.19
- Replace Endroid QrCode with BaconQrCode (#8173)
- Support responses (snippets) in HTML format (#5315)
- Add option to purge deleted mails older than 30, 60 or 90 days (#5493)
diff --git a/INSTALL b/INSTALL
index ce9a8df39..49929ba1b 100644
--- a/INSTALL
+++ b/INSTALL
@@ -119,7 +119,7 @@ the database engine with:
* SQLite
--------
-Versions of sqlite database engine older than 3.0 aren't supported.
+Versions of sqlite database engine older than 3.6.19 aren't supported.
Database file and structure is created automatically by Roundcube.
Make sure your configuration points to some file location and that the
webserver can write to the file and the directory containing the file.
diff --git a/SQL/mssql.initial.sql b/SQL/mssql.initial.sql
index 67c461c20..f7a301761 100644
--- a/SQL/mssql.initial.sql
+++ b/SQL/mssql.initial.sql
@@ -486,6 +486,6 @@ CREATE TRIGGER [contact_delete_member] ON [dbo].[contacts]
WHERE [contact_id] IN (SELECT [contact_id] FROM deleted)
GO
-INSERT INTO [dbo].[system] ([name], [value]) VALUES ('roundcube-version', '2021081000')
+INSERT INTO [dbo].[system] ([name], [value]) VALUES ('roundcube-version', '2021100300')
GO
\ No newline at end of file
diff --git a/SQL/mssql/2021100300.sql b/SQL/mssql/2021100300.sql
new file mode 100644
index 000000000..49daeda32
--- /dev/null
+++ b/SQL/mssql/2021100300.sql
@@ -0,0 +1 @@
+-- SQLite only \ No newline at end of file
diff --git a/SQL/mysql.initial.sql b/SQL/mysql.initial.sql
index 05822158b..8958cb244 100644
--- a/SQL/mysql.initial.sql
+++ b/SQL/mysql.initial.sql
@@ -260,4 +260,4 @@ CREATE TABLE `system` (
/*!40014 SET FOREIGN_KEY_CHECKS=1 */;
-INSERT INTO `system` (`name`, `value`) VALUES ('roundcube-version', '2021081000');
+INSERT INTO `system` (`name`, `value`) VALUES ('roundcube-version', '2021100300');
diff --git a/SQL/mysql/2021100300.sql b/SQL/mysql/2021100300.sql
new file mode 100644
index 000000000..49daeda32
--- /dev/null
+++ b/SQL/mysql/2021100300.sql
@@ -0,0 +1 @@
+-- SQLite only \ No newline at end of file
diff --git a/SQL/oracle.initial.sql b/SQL/oracle.initial.sql
index e08654378..60446dd44 100644
--- a/SQL/oracle.initial.sql
+++ b/SQL/oracle.initial.sql
@@ -285,4 +285,4 @@ CREATE TABLE "system" (
"value" long
);
-INSERT INTO "system" ("name", "value") VALUES ('roundcube-version', '2021081000');
+INSERT INTO "system" ("name", "value") VALUES ('roundcube-version', '2021100300');
diff --git a/SQL/oracle/2021100300.sql b/SQL/oracle/2021100300.sql
new file mode 100644
index 000000000..49daeda32
--- /dev/null
+++ b/SQL/oracle/2021100300.sql
@@ -0,0 +1 @@
+-- SQLite only \ No newline at end of file
diff --git a/SQL/postgres.initial.sql b/SQL/postgres.initial.sql
index 9b336a711..7bbbbbc17 100644
--- a/SQL/postgres.initial.sql
+++ b/SQL/postgres.initial.sql
@@ -375,4 +375,4 @@ CREATE TABLE "system" (
value text
);
-INSERT INTO "system" (name, value) VALUES ('roundcube-version', '2021081000');
+INSERT INTO "system" (name, value) VALUES ('roundcube-version', '2021100300');
diff --git a/SQL/postgres/2021100300.sql b/SQL/postgres/2021100300.sql
new file mode 100644
index 000000000..49daeda32
--- /dev/null
+++ b/SQL/postgres/2021100300.sql
@@ -0,0 +1 @@
+-- SQLite only \ No newline at end of file
diff --git a/SQL/sqlite.initial.sql b/SQL/sqlite.initial.sql
index 4094456f3..5c317f5e0 100644
--- a/SQL/sqlite.initial.sql
+++ b/SQL/sqlite.initial.sql
@@ -1,12 +1,31 @@
-- Roundcube Webmail initial database structure
--
+-- Table structure for table users
+--
+
+CREATE TABLE users (
+ user_id integer NOT NULL PRIMARY KEY,
+ username varchar(128) NOT NULL default '',
+ mail_host varchar(128) NOT NULL default '',
+ created datetime NOT NULL default '0000-00-00 00:00:00',
+ last_login datetime DEFAULT NULL,
+ failed_login datetime DEFAULT NULL,
+ failed_login_counter integer DEFAULT NULL,
+ language varchar(16),
+ preferences text DEFAULT NULL
+);
+
+CREATE UNIQUE INDEX ix_users_username ON users(username, mail_host);
+
+--
-- Table structure for table contacts and related
--
CREATE TABLE contacts (
contact_id integer NOT NULL PRIMARY KEY,
- user_id integer NOT NULL,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
changed datetime NOT NULL default '0000-00-00 00:00:00',
del tinyint NOT NULL default '0',
name varchar(128) NOT NULL default '',
@@ -22,7 +41,8 @@ CREATE INDEX ix_contacts_user_id ON contacts(user_id, del);
CREATE TABLE contactgroups (
contactgroup_id integer NOT NULL PRIMARY KEY,
- user_id integer NOT NULL default '0',
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
changed datetime NOT NULL default '0000-00-00 00:00:00',
del tinyint NOT NULL default '0',
name varchar(128) NOT NULL default ''
@@ -32,8 +52,10 @@ CREATE INDEX ix_contactgroups_user_id ON contactgroups(user_id, del);
CREATE TABLE contactgroupmembers (
- contactgroup_id integer NOT NULL,
- contact_id integer NOT NULL default '0',
+ contactgroup_id integer NOT NULL
+ REFERENCES contactgroups(contactgroup_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ contact_id integer NOT NULL
+ REFERENCES contacts(contact_id) ON DELETE CASCADE ON UPDATE CASCADE,
created datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (contactgroup_id, contact_id)
);
@@ -46,7 +68,8 @@ CREATE INDEX ix_contactgroupmembers_contact_id ON contactgroupmembers (contact_i
CREATE TABLE collected_addresses (
address_id integer NOT NULL PRIMARY KEY,
- user_id integer NOT NULL,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
changed datetime NOT NULL default '0000-00-00 00:00:00',
name varchar(255) NOT NULL default '',
email varchar(255) NOT NULL,
@@ -61,7 +84,8 @@ CREATE UNIQUE INDEX ix_collected_addresses_user_id ON collected_addresses(user_i
CREATE TABLE identities (
identity_id integer NOT NULL PRIMARY KEY,
- user_id integer NOT NULL default '0',
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
changed datetime NOT NULL default '0000-00-00 00:00:00',
del tinyint NOT NULL default '0',
standard tinyint NOT NULL default '0',
@@ -83,7 +107,8 @@ CREATE INDEX ix_identities_email ON identities(email, del);
CREATE TABLE responses (
response_id integer NOT NULL PRIMARY KEY,
- user_id integer NOT NULL default '0',
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
changed datetime NOT NULL default '0000-00-00 00:00:00',
del tinyint NOT NULL default '0',
name varchar(255) NOT NULL,
@@ -94,24 +119,6 @@ CREATE TABLE responses (
CREATE INDEX ix_responses_user_id ON responses(user_id, del);
--
--- Table structure for table users
---
-
-CREATE TABLE users (
- user_id integer NOT NULL PRIMARY KEY,
- username varchar(128) NOT NULL default '',
- mail_host varchar(128) NOT NULL default '',
- created datetime NOT NULL default '0000-00-00 00:00:00',
- last_login datetime DEFAULT NULL,
- failed_login datetime DEFAULT NULL,
- failed_login_counter integer DEFAULT NULL,
- language varchar(16),
- preferences text DEFAULT NULL
-);
-
-CREATE UNIQUE INDEX ix_users_username ON users(username, mail_host);
-
---
-- Table structure for table session
--
@@ -129,9 +136,10 @@ CREATE INDEX ix_session_changed ON session (changed);
--
CREATE TABLE dictionary (
- user_id integer DEFAULT NULL,
- language varchar(16) NOT NULL,
- data text NOT NULL
+ user_id integer DEFAULT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ language varchar(16) NOT NULL,
+ data text NOT NULL
);
CREATE UNIQUE INDEX ix_dictionary_user_language ON dictionary (user_id, language);
@@ -142,7 +150,8 @@ CREATE UNIQUE INDEX ix_dictionary_user_language ON dictionary (user_id, language
CREATE TABLE searches (
search_id integer NOT NULL PRIMARY KEY,
- user_id integer NOT NULL DEFAULT '0',
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
"type" smallint NOT NULL DEFAULT '0',
name varchar(128) NOT NULL,
data text NOT NULL
@@ -155,7 +164,8 @@ CREATE UNIQUE INDEX ix_searches_user_type_name ON searches (user_id, type, name)
--
CREATE TABLE cache (
- user_id integer NOT NULL default 0,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
cache_key varchar(128) NOT NULL default '',
expires datetime DEFAULT NULL,
data text NOT NULL,
@@ -182,7 +192,8 @@ CREATE INDEX ix_cache_shared_expires ON cache_shared(expires);
--
CREATE TABLE cache_index (
- user_id integer NOT NULL,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
mailbox varchar(255) NOT NULL,
expires datetime DEFAULT NULL,
valid smallint NOT NULL DEFAULT '0',
@@ -197,7 +208,8 @@ CREATE INDEX ix_cache_index_expires ON cache_index (expires);
--
CREATE TABLE cache_thread (
- user_id integer NOT NULL,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
mailbox varchar(255) NOT NULL,
expires datetime DEFAULT NULL,
data text NOT NULL,
@@ -211,7 +223,8 @@ CREATE INDEX ix_cache_thread_expires ON cache_thread (expires);
--
CREATE TABLE cache_messages (
- user_id integer NOT NULL,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
mailbox varchar(255) NOT NULL,
uid integer NOT NULL,
expires datetime DEFAULT NULL,
@@ -228,7 +241,8 @@ CREATE INDEX ix_cache_messages_expires ON cache_messages (expires);
CREATE TABLE filestore (
file_id integer NOT NULL PRIMARY KEY,
- user_id integer NOT NULL,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
context varchar(32) NOT NULL,
filename varchar(128) NOT NULL,
mtime integer NOT NULL,
@@ -246,4 +260,4 @@ CREATE TABLE system (
value text NOT NULL
);
-INSERT INTO system (name, value) VALUES ('roundcube-version', '2021081000');
+INSERT INTO system (name, value) VALUES ('roundcube-version', '2021100300');
diff --git a/SQL/sqlite/2021100300.sql b/SQL/sqlite/2021100300.sql
new file mode 100644
index 000000000..2a547a6cb
--- /dev/null
+++ b/SQL/sqlite/2021100300.sql
@@ -0,0 +1,211 @@
+-- Add foreign keys
+
+DELETE FROM contacts WHERE user_id NOT IN (SELECT user_id FROM users);
+ALTER TABLE contacts RENAME TO old_contacts;
+DROP INDEX ix_contacts_user_id;
+CREATE TABLE contacts (
+ contact_id integer NOT NULL PRIMARY KEY,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ changed datetime NOT NULL default '0000-00-00 00:00:00',
+ del tinyint NOT NULL default '0',
+ name varchar(128) NOT NULL default '',
+ email text NOT NULL default '',
+ firstname varchar(128) NOT NULL default '',
+ surname varchar(128) NOT NULL default '',
+ vcard text NOT NULL default '',
+ words text NOT NULL default ''
+);
+CREATE INDEX ix_contacts_user_id ON contacts(user_id, del);
+INSERT INTO contacts (contact_id, user_id, changed, del, name, email, firstname, surname, vcard, words)
+ SELECT contact_id, user_id, changed, del, name, email, firstname, surname, vcard, words FROM old_contacts;
+DROP TABLE old_contacts;
+
+DELETE FROM contactgroups WHERE user_id NOT IN (SELECT user_id FROM users);
+ALTER TABLE contactgroups RENAME TO old_contactgroups;
+DROP INDEX ix_contactgroups_user_id;
+CREATE TABLE contactgroups (
+ contactgroup_id integer NOT NULL PRIMARY KEY,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ changed datetime NOT NULL default '0000-00-00 00:00:00',
+ del tinyint NOT NULL default '0',
+ name varchar(128) NOT NULL default ''
+);
+CREATE INDEX ix_contactgroups_user_id ON contactgroups(user_id, del);
+INSERT INTO contactgroups (contactgroup_id, user_id, changed, del, name)
+ SELECT contactgroup_id, user_id, changed, del, name FROM old_contactgroups;
+DROP TABLE old_contactgroups;
+
+DELETE FROM contactgroupmembers WHERE contact_id NOT IN (SELECT contact_id FROM contacts);
+DELETE FROM contactgroupmembers WHERE contactgroup_id NOT IN (SELECT contactgroup_id FROM contactgroups);
+ALTER TABLE contactgroupmembers RENAME TO old_contactgroupmembers;
+DROP INDEX ix_contactgroupmembers_contact_id;
+CREATE TABLE contactgroupmembers (
+ contactgroup_id integer NOT NULL
+ REFERENCES contactgroups (contactgroup_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ contact_id integer NOT NULL
+ REFERENCES contacts (contact_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ created datetime NOT NULL default '0000-00-00 00:00:00',
+ PRIMARY KEY (contactgroup_id, contact_id)
+);
+INSERT INTO contactgroupmembers (contactgroup_id, contact_id, created)
+ SELECT contactgroup_id, contact_id, created FROM old_contactgroupmembers;
+CREATE INDEX ix_contactgroupmembers_contact_id ON contactgroupmembers (contact_id);
+DROP TABLE old_contactgroupmembers;
+
+DELETE FROM collected_addresses WHERE user_id NOT IN (SELECT user_id FROM users);
+ALTER TABLE collected_addresses RENAME TO old_collected_addresses;
+DROP INDEX ix_collected_addresses_user_id;
+CREATE TABLE collected_addresses (
+ address_id integer NOT NULL PRIMARY KEY,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ changed datetime NOT NULL default '0000-00-00 00:00:00',
+ name varchar(255) NOT NULL default '',
+ email varchar(255) NOT NULL,
+ "type" integer NOT NULL
+);
+CREATE UNIQUE INDEX ix_collected_addresses_user_id ON collected_addresses(user_id, "type", email);
+INSERT INTO collected_addresses (address_id, user_id, changed, name, email, "type")
+ SELECT address_id, user_id, changed, name, email, "type" FROM old_collected_addresses;
+DROP TABLE old_collected_addresses;
+
+DELETE FROM identities WHERE user_id NOT IN (SELECT user_id FROM users);
+ALTER TABLE identities RENAME TO old_identities;
+DROP INDEX ix_identities_user_id;
+DROP INDEX ix_identities_email;
+CREATE TABLE identities (
+ identity_id integer NOT NULL PRIMARY KEY,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ changed datetime NOT NULL default '0000-00-00 00:00:00',
+ del tinyint NOT NULL default '0',
+ standard tinyint NOT NULL default '0',
+ name varchar(128) NOT NULL default '',
+ organization varchar(128) default '',
+ email varchar(128) NOT NULL default '',
+ "reply-to" varchar(128) NOT NULL default '',
+ bcc varchar(128) NOT NULL default '',
+ signature text NOT NULL default '',
+ html_signature tinyint NOT NULL default '0'
+);
+CREATE INDEX ix_identities_user_id ON identities(user_id, del);
+CREATE INDEX ix_identities_email ON identities(email, del);
+INSERT INTO identities (identity_id, user_id, changed, del, standard, name, organization, email, "reply-to", bcc, signature, html_signature)
+ SELECT identity_id, user_id, changed, del, standard, name, organization, email, "reply-to", bcc, signature, html_signature FROM old_identities;
+DROP TABLE old_identities;
+
+DELETE FROM responses WHERE user_id NOT IN (SELECT user_id FROM users);
+ALTER TABLE responses RENAME TO old_responses;
+DROP INDEX ix_responses_user_id;
+CREATE TABLE responses (
+ response_id integer NOT NULL PRIMARY KEY,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ changed datetime NOT NULL default '0000-00-00 00:00:00',
+ del tinyint NOT NULL default '0',
+ name varchar(255) NOT NULL,
+ data text NOT NULL,
+ is_html tinyint NOT NULL default '0'
+);
+CREATE INDEX ix_responses_user_id ON responses(user_id, del);
+INSERT INTO responses (response_id, user_id, changed, del, name, data, is_html)
+ SELECT response_id, user_id, changed, del, name, data, is_html FROM old_responses;
+DROP TABLE old_responses;
+
+DELETE FROM dictionary WHERE user_id IS NOT NULL AND user_id NOT IN (SELECT user_id FROM users);
+ALTER TABLE dictionary RENAME TO old_dictionary;
+DROP INDEX ix_dictionary_user_language;
+CREATE TABLE dictionary (
+ user_id integer DEFAULT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ language varchar(16) NOT NULL,
+ data text NOT NULL
+);
+CREATE UNIQUE INDEX ix_dictionary_user_language ON dictionary (user_id, language);
+INSERT INTO dictionary (user_id, language, data)
+ SELECT user_id, language, data FROM old_dictionary;
+DROP TABLE old_dictionary;
+
+DELETE FROM searches WHERE user_id NOT IN (SELECT user_id FROM users);
+ALTER TABLE searches RENAME TO old_searches;
+DROP INDEX ix_searches_user_type_name;
+CREATE TABLE searches (
+ search_id integer NOT NULL PRIMARY KEY,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ "type" smallint NOT NULL DEFAULT '0',
+ name varchar(128) NOT NULL,
+ data text NOT NULL
+);
+CREATE UNIQUE INDEX ix_searches_user_type_name ON searches (user_id, type, name);
+INSERT INTO searches (search_id, user_id, "type", name, data)
+ SELECT search_id, user_id, "type", name, data FROM old_searches;
+DROP TABLE old_searches;
+
+DELETE FROM filestore WHERE user_id NOT IN (SELECT user_id FROM users);
+ALTER TABLE filestore RENAME TO old_filestore;
+DROP INDEX ix_filestore_user_id;
+CREATE TABLE filestore (
+ file_id integer NOT NULL PRIMARY KEY,
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ context varchar(32) NOT NULL,
+ filename varchar(128) NOT NULL,
+ mtime integer NOT NULL,
+ data text NOT NULL
+);
+CREATE UNIQUE INDEX ix_filestore_user_id ON filestore(user_id, context, filename);
+INSERT INTO filestore (file_id, user_id, context, filename, mtime, data)
+ SELECT file_id, user_id, context, filename, mtime, data FROM old_filestore;
+DROP TABLE old_filestore;
+
+
+DROP TABLE cache;
+CREATE TABLE cache (
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ cache_key varchar(128) NOT NULL default '',
+ expires datetime DEFAULT NULL,
+ data text NOT NULL,
+ PRIMARY KEY (user_id, cache_key)
+);
+CREATE INDEX ix_cache_expires ON cache(expires);
+
+DROP TABLE cache_index;
+CREATE TABLE cache_index (
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ mailbox varchar(255) NOT NULL,
+ expires datetime DEFAULT NULL,
+ valid smallint NOT NULL DEFAULT '0',
+ data text NOT NULL,
+ PRIMARY KEY (user_id, mailbox)
+);
+CREATE INDEX ix_cache_index_expires ON cache_index (expires);
+
+DROP TABLE cache_thread;
+CREATE TABLE cache_thread (
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ mailbox varchar(255) NOT NULL,
+ expires datetime DEFAULT NULL,
+ data text NOT NULL,
+ PRIMARY KEY (user_id, mailbox)
+);
+CREATE INDEX ix_cache_thread_expires ON cache_thread (expires);
+
+DROP TABLE cache_messages;
+CREATE TABLE cache_messages (
+ user_id integer NOT NULL
+ REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ mailbox varchar(255) NOT NULL,
+ uid integer NOT NULL,
+ expires datetime DEFAULT NULL,
+ data text NOT NULL,
+ flags integer NOT NULL DEFAULT '0',
+ PRIMARY KEY (user_id, mailbox, uid)
+);
+
+CREATE INDEX ix_cache_messages_expires ON cache_messages (expires);
diff --git a/bin/deluser.sh b/bin/deluser.sh
index d9eb191b7..9797af139 100755
--- a/bin/deluser.sh
+++ b/bin/deluser.sh
@@ -112,17 +112,14 @@ if (!$plugin['abort']) {
}
if ($plugin['abort']) {
+ unset($plugin['abort']);
if ($transaction) {
$db->rollbackTransaction();
}
_die("User deletion aborted by plugin");
}
-// deleting the user record should be sufficient due to ON DELETE CASCADE foreign key references
-// but not all database backends actually support this so let's do it by hand
-foreach (['identities','responses','contacts','contactgroups','dictionary','cache','cache_index','cache_messages','cache_thread','searches','users'] as $table) {
- $db->query('DELETE FROM ' . $db->table_name($table, true) . ' WHERE `user_id` = ?', $user->ID);
-}
+$db->query('DELETE FROM ' . $db->table_name('users', true) . ' WHERE `user_id` = ?', $user->ID);
if ($db->is_error()) {
$rcmail->plugins->exec_hook('user_delete_rollback', $plugin);
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);
diff --git a/program/lib/Roundcube/db/sqlite.php b/program/lib/Roundcube/db/sqlite.php
index 4182f7535..87e9c8384 100644
--- a/program/lib/Roundcube/db/sqlite.php
+++ b/program/lib/Roundcube/db/sqlite.php
@@ -76,7 +76,10 @@ class rcube_db_sqlite extends rcube_db
}
// Enable WAL mode to fix locking issues like #8035.
- $dbh->query("PRAGMA journal_mode=WAL");
+ $dbh->query("PRAGMA journal_mode = WAL");
+
+ // Enable foreign keys (requires sqlite 3.6.19 compiled with FK support)
+ $dbh->query("PRAGMA foreign_keys = ON");
}
/**