From bb2b07496302d3e3de5f835194263985fddd3419 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sat, 7 Apr 2018 12:20:00 +0200 Subject: [PATCH] untested code to make LDAP --> SQL migration work by automatically renumbering groups with identical nummeric ID as users --- .../class.admin_cmd_change_account_id.inc.php | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/admin/inc/class.admin_cmd_change_account_id.inc.php b/admin/inc/class.admin_cmd_change_account_id.inc.php index 52f6ed024d..f554f1e8da 100644 --- a/admin/inc/class.admin_cmd_change_account_id.inc.php +++ b/admin/inc/class.admin_cmd_change_account_id.inc.php @@ -5,9 +5,8 @@ * @link http://www.egroupware.org * @author Ralf Becker * @package admin - * @copyright (c) 2007-17 by Ralf Becker + * @copyright (c) 2007-18 by Ralf Becker * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License - * @version $Id$ */ use EGroupware\Api; @@ -15,6 +14,9 @@ use EGroupware\Api; /** * admin command: change an account_id + * + * @property boolean $group_renumbered =false true: group(s) have been renumbered by LDAP --> SQL migration, + * do NOT change egw_accounts.account_id and egw_acl where acl_appname='phpgw_group' */ class admin_cmd_change_account_id extends admin_cmd { @@ -116,29 +118,37 @@ class admin_cmd_change_account_id extends admin_cmd */ protected function exec($check_only=false) { + $errors = array(); foreach($this->change as $from => $to) { if (!(int)$from || !(int)$to) { - throw new Api\Exception\WrongUserinput(lang("Account-id's have to be integers!"),16); + $errors[] = lang("Account-id's have to be integers!"); } if (($from < 0) != ($to < 0)) { - throw new Api\Exception\WrongUserinput(lang("Can NOT change users into groups, same sign required!"),17); + $errors[] = lang("Can NOT change users into groups, same sign required!"); } - if (!($from_exists = $GLOBALS['egw']->accounts->exists($from))) + if (!$this->group_renumbered) { - throw new Api\Exception\WrongUserinput(lang("Source account #%1 does NOT exist!", $from),18); - } - if ($from_exists !== ($from > 0 ? 1 : 2)) - { - throw new Api\Exception\WrongUserinput(lang("Group #%1 must have negative sign!", $from),19); - } - if ($GLOBALS['egw']->accounts->exists($to) && !isset($this->change[$to])) - { - throw new Api\Exception\WrongUserinput(lang("Destination account #%1 does exist and is NOT renamed itself! Can not merge Api\Accounts, it will violate unique contains. Delete with transfer of data instead.", $to),20); + if (!($from_exists = $GLOBALS['egw']->accounts->exists($from))) + { + $errors[] = lang("Source account #%1 does NOT exist!", $from); + } + if ($from_exists !== ($from > 0 ? 1 : 2)) + { + $errors[] = lang("Group #%1 must have negative sign!", $from); + } + if ($GLOBALS['egw']->accounts->exists($to) && !isset($this->change[$to])) + { + $errors[] = lang("Destination account #%1 does exist and is NOT renamed itself! Can not merge Api\Accounts, it will violate unique contains. Delete with transfer of data instead.", $to); + } } } + if ($errors) + { + throw new Api\Exception\WrongUserinput(implode("\n", $errors), 16); + } $columns2change = $this->get_changes(); $total = 0; foreach($columns2change as $app => $data) @@ -170,6 +180,14 @@ class admin_cmd_change_account_id extends admin_cmd $where = $column; $column = array_shift($where); } + if ($this->group_renumbered && $table == 'egw_accounts' && $column == 'account_id') + { + continue; + } + if ($this->group_renumbered && $table == 'egw_acl') + { + $where[] = "acl_appname != 'phpgw_group'"; + } $total += ($changed = self::_update_account_id($this->change,$db,$table,$column,$where,$type)); if (!$check_only && $changed) echo "$app:\t$table.$column $changed id's changed\n"; }