From 67f71992eeb87c0effe24e4537c5219d95dc7dcf Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 19 Nov 2012 09:59:00 +0000 Subject: [PATCH] first take on migrating mail accounts from LDAP to SQL (only qmailUser schema) --- setup/account_migration.php | 2 +- setup/inc/class.setup_cmd_ldap.inc.php | 29 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/setup/account_migration.php b/setup/account_migration.php index 2bfb813dd7..89b158cec9 100644 --- a/setup/account_migration.php +++ b/setup/account_migration.php @@ -37,7 +37,7 @@ if (!is_object($GLOBALS['egw_setup']->db)) } // Load configuration values account_repository and auth_type, as setup has not yet done so foreach($GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->config_table,'config_name,config_value', - "config_name LIKE 'ldap%' OR config_name LIKE 'account_%' OR config_name LIKE '%encryption%' OR config_name='auth_type'", + "config_name LIKE 'ldap%' OR config_name LIKE 'account_%' OR config_name LIKE '%encryption%' OR config_name='auth_type' OR config_name='mail_suffix'", __LINE__,__FILE__) as $row) { $GLOBALS['egw_info']['server'][$row['config_name']] = $row['config_value']; diff --git a/setup/inc/class.setup_cmd_ldap.inc.php b/setup/inc/class.setup_cmd_ldap.inc.php index ca14453554..9134f96b12 100644 --- a/setup/inc/class.setup_cmd_ldap.inc.php +++ b/setup/inc/class.setup_cmd_ldap.inc.php @@ -195,6 +195,31 @@ class setup_cmd_ldap extends setup_cmd $msg[] = lang('%1 created in %2.',$what,$target); $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($emailadmin_ldap)) + { + 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)) + { + $emailadmin_sql = new emailadmin_smtp_sql(); + } + $emailadmin_sql->setUserData($account_id, (array)$mailaccount['mailAlternateAddress'], + (array)$mailaccount['mailForwardingAddress'], $mailaccount['deliveryMode'], + $mailaccount['accountStatus'], $mailaccount['mailLocalAddress'], + $mailaccount['quotaLimit']); + echo "mail account migraged
\n"; + } + else echo "

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

\n"; + } + // should we run any or some addAccount hooks if ($this->add_account_hook) { @@ -334,7 +359,7 @@ class setup_cmd_ldap extends setup_cmd $accounts_obj = $this->accounts_obj($from_ldap); //error_log(__METHOD__."(from_ldap=".array2string($from_ldap).') get_class(accounts_obj->backend)='.get_class($accounts_obj->backend)); - $accounts = $accounts_obj->search(array('type' => 'both')); + $accounts = $accounts_obj->search(array('type' => 'both', 'objectclass' => true)); foreach($accounts as $account_id => &$account) { @@ -343,7 +368,7 @@ class setup_cmd_ldap extends setup_cmd unset($account); $account_id = $account['account_id']; } - $account = $accounts_obj->read($account_id); + $account += $accounts_obj->read($account_id); if ($account['account_type'] == 'g') {