From cf32369b5d9f5c69e678ad515add8a912aa3ecbf Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 12 Jul 2004 22:06:13 +0000 Subject: [PATCH] stoping account or group creation process, if there is an error and therefor no id (else the acl or preference class assumes to change the current user) --- admin/inc/class.boaccounts.inc.php | 97 +++++++++++++++--------------- setup/lang/phpgw_de.lang | 2 + setup/lang/phpgw_en.lang | 2 + setup/ldapimport.php | 16 +++-- setup/setup_demo.php | 21 ++++++- 5 files changed, 81 insertions(+), 57 deletions(-) diff --git a/admin/inc/class.boaccounts.inc.php b/admin/inc/class.boaccounts.inc.php index 059ebb7bda..9e40db1481 100755 --- a/admin/inc/class.boaccounts.inc.php +++ b/admin/inc/class.boaccounts.inc.php @@ -238,62 +238,64 @@ 'account_expires' => -1 // 'account_file_space' => $account_file_space_number . "-" . $account_file_space_type, ); - $group->create($account_info); - $group_info['account_id'] = $GLOBALS['phpgw']->accounts->name2id($group_info['account_name']); - - $apps = CreateObject('phpgwapi.applications',$group_info['account_id']); - $apps->update_data(Array()); - reset($group_info['account_apps']); - while(list($app,$value) = each($group_info['account_apps'])) + $group_info['account_id'] = $group->create($account_info); + // do the following only if we got an id - the create succided + if ($group_info['account_id']) { - $apps->add($app); - $new_apps[] = $app; - } - $apps->save_repository(); - - $acl = CreateObject('phpgwapi.acl',$group_info['account_id']); - $acl->read_repository(); - - @reset($group_info['account_user']); - while(list($user_id,$dummy) = each($group_info['account_user'])) - { - if(!$dummy) + $apps = CreateObject('phpgwapi.applications',$group_info['account_id']); + $apps->update_data(Array()); + reset($group_info['account_apps']); + while(list($app,$value) = each($group_info['account_apps'])) { - continue; + $apps->add($app); + $new_apps[] = $app; } - $acl->add_repository('phpgw_group',$group_info['account_id'],$user_id,1); - - $docommit = False; - $GLOBALS['pref'] = CreateObject('phpgwapi.preferences',$user_id); - $t = $GLOBALS['pref']->read_repository(); - @reset($new_apps); - while(is_array($new_apps) && list($app_key,$app_name) = each($new_apps)) + $apps->save_repository(); + + $acl = CreateObject('phpgwapi.acl',$group_info['account_id']); + $acl->read_repository(); + + @reset($group_info['account_user']); + while(list($user_id,$dummy) = each($group_info['account_user'])) { - if (!$t[($app_name=='admin'?'common':$app_name)]) + if(!$dummy) { - $GLOBALS['phpgw']->hooks->single('add_def_pref', $app_name); - $docommit = True; + continue; + } + $acl->add_repository('phpgw_group',$group_info['account_id'],$user_id,1); + + $docommit = False; + $GLOBALS['pref'] = CreateObject('phpgwapi.preferences',$user_id); + $t = $GLOBALS['pref']->read_repository(); + @reset($new_apps); + while(is_array($new_apps) && list($app_key,$app_name) = each($new_apps)) + { + if (!$t[($app_name=='admin'?'common':$app_name)]) + { + $GLOBALS['phpgw']->hooks->single('add_def_pref', $app_name); + $docommit = True; + } + } + if ($docommit) + { + $GLOBALS['pref']->save_repository(); } } - if ($docommit) + + $acl->save_repository(); + + $basedir = $GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'groups' . SEP; + $cd = 31; + umask(000); + if (! @mkdir ($basedir . $group_info['account_name'], 0707)) { - $GLOBALS['pref']->save_repository(); + $cd = 37; } + + $GLOBALS['phpgw']->db->unlock(); } - - $acl->save_repository(); - - $basedir = $GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'groups' . SEP; - $cd = 31; - umask(000); - if (! @mkdir ($basedir . $group_info['account_name'], 0707)) - { - $cd = 37; - } - - $GLOBALS['phpgw']->db->unlock(); - ExecMethod('admin.uiaccounts.list_groups'); + return False; } @@ -357,10 +359,9 @@ } // do we have all needed data?? - if (!$errors = $this->validate_user($userData)) + if (!($errors = $this->validate_user($userData)) && + ($userData['account_id'] = $account_id = $this->so->add_user($userData))) // no error in the creation { - $userData['account_id'] = $account_id = $this->so->add_user($userData); - if ($userData['anonymous']) { $GLOBALS['phpgw']->acl->add_repository('phpgwapi','anonymous',$account_id,1); diff --git a/setup/lang/phpgw_de.lang b/setup/lang/phpgw_de.lang index de586548e5..b1f91a347d 100644 --- a/setup/lang/phpgw_de.lang +++ b/setup/lang/phpgw_de.lang @@ -156,6 +156,8 @@ enter your http proxy server setup de HTTP-Proxy-Server enter your http proxy server password setup de Passwort des HTTP-Proxy-Servers enter your http proxy server port setup de Port des HTTP-Proxy-Servers enter your http proxy server username setup de Benutzername des HTTP-Proxy-Servers +error in admin-creation !!! setup de Fehler beim Anlegen des Admin-Kontos !!! +error in group-creation !!! setup de Fehler beim Anlegen der Gruppen !!! export egroupware accounts from sql to ldap setup de eGroupWare Benutzerkonten von SQL nach LDAP exportieren export has been completed! you will need to set the user passwords manually. setup de Export ist abgeschlossen! Sie müssen die Benutzerpasswörter manuell setzen. export sql users to ldap setup de SQL-Benutzer in LDAP exportieren diff --git a/setup/lang/phpgw_en.lang b/setup/lang/phpgw_en.lang index 1cdc583294..e8934e3342 100644 --- a/setup/lang/phpgw_en.lang +++ b/setup/lang/phpgw_en.lang @@ -152,6 +152,8 @@ enter your http proxy server setup en Enter your HTTP proxy server enter your http proxy server password setup en Enter your HTTP proxy server password enter your http proxy server port setup en Enter your HTTP proxy server port enter your http proxy server username setup en Enter your HTTP proxy server username +error in admin-creation !!! setup en Error in admin-creation !!! +error in group-creation !!! setup en Error in group-creation !!! export egroupware accounts from sql to ldap setup en Export eGroupWare accounts from SQL to LDAP export has been completed! you will need to set the user passwords manually. setup en Export has been completed! You will need to set the user passwords manually. export sql users to ldap setup en Export SQL users to LDAP diff --git a/setup/ldapimport.php b/setup/ldapimport.php index a04d62c5b5..0230a72849 100644 --- a/setup/ldapimport.php +++ b/setup/ldapimport.php @@ -199,10 +199,12 @@ 'account_status' => 'A', 'account_expires' => -1 ); - $accounts->create($thisaccount_info); - $thisacctid = $acct->name2id($thisacctlid); + $thisacctid = $accounts->create($thisaccount_info); + } + if (!$thisacctid) // if we have no account_id, we cant continue + { + continue; } - // Insert default acls for this user. // Since the group has app rights, we don't need to give users // these rights. Instead, we make the user a member of the Default group @@ -279,10 +281,12 @@ 'account_status' => 'A', 'account_expires' => -1 ); - $groups->create($thisgroup_info); - $thisacctid = $acct->name2id($thisacctlid); + $thisacctid = $groups->create($thisgroup_info); + } + if (!$thisacctid) // if we have no account_id, we cant continue + { + continue; } - // Now make them a member of this group in phpgw. while(list($key,$members) = each($thismembers)) { diff --git a/setup/setup_demo.php b/setup/setup_demo.php index 0a855d583a..54cdb0cfe0 100644 --- a/setup/setup_demo.php +++ b/setup/setup_demo.php @@ -97,6 +97,14 @@ /* Create the demo groups */ $defaultgroupid = (int)$GLOBALS['phpgw_setup']->add_account('Default','Default','Group',False,False); $admingroupid = (int)$GLOBALS['phpgw_setup']->add_account('Admins','Admin','Group',False,False); + + if (!$defaultgroupid || !$admingroupid) + { + echo '

'.lang('Error in group-creation !!!')."

\n"; + echo '

'.lang('click here to return to setup.')."

\n"; + $GLOBALS['phpgw_setup']->db->transaction_abort(); + exit; + } /* Group perms for the default group */ $GLOBALS['phpgw_setup']->add_acl(array('addressbook','calendar','infolog','email','preferences'),'run',$defaultgroupid); @@ -147,13 +155,20 @@ if(get_var('create_demo',Array('POST'))) { // Create 3 demo accounts - $accountid = $GLOBALS['phpgw_setup']->add_account('demo','Demo','Account','guest'); - $accountid = $GLOBALS['phpgw_setup']->add_account('demo2','Demo2','Account','guest'); - $accountid = $GLOBALS['phpgw_setup']->add_account('demo3','Demo3','Account','guest'); + $GLOBALS['phpgw_setup']->add_account('demo','Demo','Account','guest'); + $GLOBALS['phpgw_setup']->add_account('demo2','Demo2','Account','guest'); + $GLOBALS['phpgw_setup']->add_account('demo3','Demo3','Account','guest'); } /* Create records for administrator account, with Admins as primary and Default as additional group */ $accountid = $GLOBALS['phpgw_setup']->add_account($username,$fname,$lname,$passwd,'Admins',True); + if (!$accountid) + { + echo '

'.lang('Error in admin-creation !!!')."

\n"; + echo '

'.lang('click here to return to setup.')."

\n"; + $GLOBALS['phpgw_setup']->db->transaction_abort(); + exit; + } $GLOBALS['phpgw_setup']->add_acl('phpgw_group',$admingroupid,$accountid); $GLOBALS['phpgw_setup']->add_acl('phpgw_group',$defaultgroupid,$accountid);