From 78384c98f4da4bbadd58f9d703111593eae6abcd Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 23 May 2013 14:33:34 +0000 Subject: [PATCH] offer to delete all existing accounts from SQL tables, before migration to it --- setup/account_migration.php | 9 ++++++++- setup/inc/class.setup_cmd_ldap.inc.php | 12 ++++++++---- setup/templates/default/account_migration.tpl | 8 ++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/setup/account_migration.php b/setup/account_migration.php index 684e7ff888..a1a74cb080 100644 --- a/setup/account_migration.php +++ b/setup/account_migration.php @@ -64,6 +64,7 @@ $cmd = new setup_cmd_ldap(array( 'ldap_admin' => !empty($_POST['ldap_admin']) ? $_POST['ldap_admin'] : $GLOBALS['egw_info']['server']['ldap_root_dn'], 'ldap_admin_pw' => !empty($_POST['ldap_admin']) ? $_POST['ldap_admin_pw'] : $GLOBALS['egw_info']['server']['ldap_root_pw'], 'ldap_base' => implode(',',$base_parts), + 'truncate_egw_accounts' => !empty($_POST['truncate_egw_accounts']), )+$GLOBALS['egw_info']['server']); if (!$_POST['migrate']) @@ -77,6 +78,7 @@ if (!$_POST['migrate']) $setup_tpl->set_block('migration','ldap_admin','ldap_admin'); $setup_tpl->set_block('migration','submit','submit'); $setup_tpl->set_block('migration','footer','footer'); + $setup_tpl->set_block('migration','truncate_egw_accounts','truncate_egw_accounts'); foreach($accounts as $account_id => $account) { @@ -99,7 +101,7 @@ if (!$_POST['migrate']) $setup_tpl->set_var('users',$user_list); $setup_tpl->set_var('groups',$group_list); - $setup_tpl->set_var('description',lang('Migration between eGroupWare account repositories').': '.$direction); + $setup_tpl->set_var('description',lang('Migration between EGroupware account repositories').': '.$direction); $setup_tpl->set_var('select_users',lang('Select which user(s) will be exported')); $setup_tpl->set_var('select_groups',lang('Select which group(s) will be exported')); $setup_tpl->set_var('memberships',$identical_account_id_warning ? @@ -124,6 +126,11 @@ if (!$_POST['migrate']) { $setup_tpl->pfp('out','ldap_admin'); } + if ($to == 'sql') + { + $setup_tpl->set_var('truncate_egw_accounts_message', lang('Delete all existing accounts from SQL database')); + $setup_tpl->pfp('out','truncate_egw_accounts'); + } $setup_tpl->pfp('out','submit'); $setup_tpl->pfp('out','footer'); } diff --git a/setup/inc/class.setup_cmd_ldap.inc.php b/setup/inc/class.setup_cmd_ldap.inc.php index 653f0927ea..03293b6c29 100644 --- a/setup/inc/class.setup_cmd_ldap.inc.php +++ b/setup/inc/class.setup_cmd_ldap.inc.php @@ -48,10 +48,11 @@ class setup_cmd_ldap extends setup_cmd * @param string $ldap_group_context=null ou for groups, default "ou=groups,$base" * @param string $sub_command='create_ldap' 'create_ldap', 'test_ldap', 'test_ldap_root', see exec method * @param string $ldap_encryption_type='des' + * @param boolean $truncate_egw_accounts=false truncate accounts table before migration to SQL */ function __construct($domain,$ldap_host=null,$ldap_suffix=null,$ldap_admin=null,$ldap_admin_pw=null, $ldap_base=null,$ldap_root_dn=null,$ldap_root_pw=null,$ldap_context=null,$ldap_search_filter=null, - $ldap_group_context=null,$sub_command='create_ldap',$ldap_encryption_type='des') + $ldap_group_context=null,$sub_command='create_ldap',$ldap_encryption_type='des',$truncate_egw_accounts=false) { if (!is_array($domain)) { @@ -69,6 +70,7 @@ class setup_cmd_ldap extends setup_cmd 'ldap_group_context' => $ldap_group_context, 'sub_command' => $sub_command, 'ldap_encryption_type' => $ldap_encryption_type, + 'truncate_egw_accounts' => $truncate_egw_accounts, ); } //echo __CLASS__.'::__construct()'; _debug_array($domain); @@ -145,12 +147,12 @@ class setup_cmd_ldap extends setup_cmd // read accounts from old store $accounts = $this->accounts(!$to_ldap); - /* uncomment if you want to have SQL cleaned up before migration - if (!$to_ldap) + // clean up SQL before migration + if (!$to_ldap && $this->truncate_egw_accounts) { $GLOBALS['egw']->db->query('TRUNCATE TABLE egw_accounts', __LINE__, __FILE__); $GLOBALS['egw']->db->query('DELETE FROM egw_addressbook WHERE account_id IS NOT NULL', __LINE__, __FILE__); - }*/ + } // instanciate accounts obj for new store $accounts_obj = $this->accounts_obj($to_ldap); @@ -224,6 +226,8 @@ class setup_cmd_ldap extends setup_cmd { if (!isset($emailadmin_src)) { + // add egw-pear to include_path, as setup does NOT do it (only includes common_functions.inc.php from API) + set_include_path(EGW_SERVER_ROOT.'/egw-pear'.PATH_SEPARATOR.get_include_path()); include_once(EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$ldap_class.'.inc.php'); if ($to_ldap) { diff --git a/setup/templates/default/account_migration.tpl b/setup/templates/default/account_migration.tpl index 6498ef64b7..d0c1c243e4 100644 --- a/setup/templates/default/account_migration.tpl +++ b/setup/templates/default/account_migration.tpl @@ -37,6 +37,14 @@ + + + + + + + +