From 7cd9685d711fde0c4f034db268c49ac0ac0c5ad3 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 20 Nov 2012 09:13:16 +0000 Subject: [PATCH] mail account and addressbook migration in all directions and for dbmailuser schema too --- setup/inc/class.setup_cmd_ldap.inc.php | 59 ++++++++++++++++++++------ 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/setup/inc/class.setup_cmd_ldap.inc.php b/setup/inc/class.setup_cmd_ldap.inc.php index 9134f96b12..1d1aa977a6 100644 --- a/setup/inc/class.setup_cmd_ldap.inc.php +++ b/setup/inc/class.setup_cmd_ldap.inc.php @@ -145,6 +145,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) + { + $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); @@ -196,28 +202,51 @@ class setup_cmd_ldap extends setup_cmd $accounts_created++; // check if we need to migrate mail-account - // todo sql --> ldap and other schemas - if (!$to_ldap && in_array('qmailUser', $account['objectclass'])) + if (!isset($ldap_class)) { - if (!isset($emailadmin_ldap)) + $ldap_class = false; + $ldap = new ldap(); + $ldap->ldapConnect(); + foreach(array( // todo: have these enumerated by emailadmin ... + 'qmailUser' => 'postfixldap', + 'dbMailUser' => 'postfixdbmailuser', + // nothing to migrate for inetOrgPerson ... + ) as $object_class => $class) { - include_once(EGW_INCLUDE_ROOT.'/emailadmin/inc/class.postfixldap.inc.php'); - $emailadmin_ldap = new postfixldap(); - } - if (($mailaccount = $emailadmin_ldap->getUserData($account_id))) - { - echo "

".array2string($mailaccount).': '; - if (!isset($emailadmin_sql)) + if ($ldap->getLDAPServerInfo()->supportsObjectClass($object_class)) { - $emailadmin_sql = new emailadmin_smtp_sql(); + $ldap_class = $class; + break; } - $emailadmin_sql->setUserData($account_id, (array)$mailaccount['mailAlternateAddress'], + } + } + if ($ldap_class) + { + if (!isset($emailadmin_src)) + { + include_once(EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$ldap_class.'.inc.php'); + if ($to_ldap) + { + $emailadmin_src = new emailadmin_smtp_sql(); + $emailadmin_dst = new $ldap_class(); + } + else + { + $emailadmin_src = new $ldap_class(); + $emailadmin_dst = new emailadmin_smtp_sql(); + } + } + if (($mailaccount = $emailadmin_src->getUserData($account_id))) + { + //echo "

".array2string($mailaccount).': '; + $emailadmin_dst->setUserData($account_id, (array)$mailaccount['mailAlternateAddress'], (array)$mailaccount['mailForwardingAddress'], $mailaccount['deliveryMode'], $mailaccount['accountStatus'], $mailaccount['mailLocalAddress'], $mailaccount['quotaLimit']); - echo "mail account migraged
\n"; + + $msg[] = lang("Mail account of %1 migraged", $account['account_lid']); } - else echo "

No mail account data found for #$account_id $account[account_lid]!

\n"; + //else echo "

No mail account data found for #$account_id $account[account_lid]!

\n"; } // should we run any or some addAccount hooks @@ -292,7 +321,9 @@ class setup_cmd_ldap extends setup_cmd $GLOBALS['egw_info']['server'][$name] = $value; } } + ob_start(); $addressbook->migrate2ldap($to_ldap ? 'accounts' : 'accounts-back'); + $msg = array_merge($msg, explode("\n", strip_tags(ob_get_clean()))); $this->restore_db();