From 3d0d5dbd0f35c47b21e2e574703a08f07ce677dd Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Sun, 08 May 2016 08:27:56 -0400 Subject: [PATCH] Performance improvements in format_flowed() and unfold_flowed() --- bin/deluser.sh | 34 ++++++++++++++++++++++++++++------ 1 files changed, 28 insertions(+), 6 deletions(-) diff --git a/bin/deluser.sh b/bin/deluser.sh index f12ec90..06505ef 100755 --- a/bin/deluser.sh +++ b/bin/deluser.sh @@ -20,7 +20,7 @@ +-----------------------------------------------------------------------+ */ -define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' ); +define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); require_once INSTALL_PATH . 'program/include/clisetup.php'; @@ -37,7 +37,7 @@ exit(1); } -$rcmail = rcmail::get_instance(); +$rcmail = rcube::get_instance(); // get arguments $args = rcube_utils::get_opt(array('h' => 'host')); @@ -69,6 +69,7 @@ // connect to DB $db = $rcmail->get_dbh(); $db->db_connect('w'); +$transaction = false; if (!$db->is_connected() || $db->is_error()) { _die("No DB connection\n" . $db->is_error()); @@ -81,23 +82,44 @@ die("User not found.\n"); } +// inform plugins about approaching user deletion +$plugin = $rcmail->plugins->exec_hook('user_delete_prepare', array('user' => $user, 'username' => $username, 'host' => $args['host'])); + // let plugins cleanup their own user-related data -$plugin = $rcmail->plugins->exec_hook('user_delete', array('user' => $user, 'username' => $username, 'host' => $args['host'])); +if (!$plugin['abort']) { + $transaction = $db->startTransaction(); + $plugin = $rcmail->plugins->exec_hook('user_delete', $plugin); +} if ($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 (array('identities','contacts','contactgroups','dictionaries','cache','cache_index','cache_messages','cache_thread','searches','users') as $table) { - $db->query('DELETE FROM ' . $db->table_name($table) . ' WHERE user_id=?', $user->ID); +foreach (array('identities','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); } if ($db->is_error()) { + $rcmail->plugins->exec_hook('user_delete_rollback', $plugin); _die("DB error occurred: " . $db->is_error()); } else { - echo "Successfully deleted user $user->ID\n"; + // inform plugins about executed user deletion + $plugin = $rcmail->plugins->exec_hook('user_delete_commit', $plugin); + + if ($plugin['abort']) { + unset($plugin['abort']); + $db->rollbackTransaction(); + $rcmail->plugins->exec_hook('user_delete_rollback', $plugin); + } + else { + $db->endTransaction(); + echo "Successfully deleted user $user->ID\n"; + } } -- Gitblit v1.9.1