- new admin-cli command --add-user like --edit-user, but runs addaccount hook for existing accounts too

- using --add-user instead of --edit-user in setup_cmd_admin
This commit is contained in:
Ralf Becker 2010-08-20 20:28:59 +00:00
parent 9df4f2e93b
commit 442bdbe564
3 changed files with 15 additions and 11 deletions

View File

@ -6,7 +6,7 @@
* @link http://www.egroupware.org * @link http://www.egroupware.org
* @package admin * @package admin
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2006/7 by Ralf Becker <RalfBecker-AT-outdoor-training.de> * @copyright (c) 2006-10 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$ * @version $Id$
*/ */
@ -54,6 +54,9 @@ switch($action)
case '--edit-user': case '--edit-user':
return do_edit_user($arg0s); return do_edit_user($arg0s);
case '--add-user': // like --edit-account, but always runs addaccount hook
return do_edit_user($arg0s,true);
case '--change-pw': case '--change-pw':
return do_change_pw($arg0s); return do_change_pw($arg0s);
@ -280,8 +283,9 @@ function do_change_pw($args)
* Edit or add a user to eGroupWare. If you specify groups, they *replace* the exiting memberships! * Edit or add a user to eGroupWare. If you specify groups, they *replace* the exiting memberships!
* 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12 * 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12
* @param array $args admin-account[@domain],admin-password,account[=new-account-name],first-name,last-name,password,email,expires{never(default)|YYYY-MM-DD|already},can-change-pw{true(default)|false},anon-user{true|false(default)},primary-group{Default(default)|...}[,groups,...][,homedirectory,loginshell] * @param array $args admin-account[@domain],admin-password,account[=new-account-name],first-name,last-name,password,email,expires{never(default)|YYYY-MM-DD|already},can-change-pw{true(default)|false},anon-user{true|false(default)},primary-group{Default(default)|...}[,groups,...][,homedirectory,loginshell]
* @param boolean $run_addaccount_hook=null default run hook depending on account existence, true=allways run addaccount hook
*/ */
function do_edit_user($args) function do_edit_user($args,$run_addaccount_hook=null)
{ {
array_shift($args); // admin-account array_shift($args); // admin-account
array_shift($args); // admin-pw array_shift($args); // admin-pw
@ -321,7 +325,7 @@ function do_edit_user($args)
$data['account_lid'] = $account; $data['account_lid'] = $account;
$account = false; $account = false;
}; };
run_command(new admin_cmd_edit_user($account,$data)); run_command(new admin_cmd_edit_user($account,$data,null,$run_addaccount_hook));
} }
/** /**
@ -412,9 +416,7 @@ function do_subscribe_other($account_lid,$pw=null)
'account_lid' => $account_lid, 'account_lid' => $account_lid,
'passwd' => $pw, 'passwd' => $pw,
); );
include_once(EGW_INCLUDE_ROOT.'/emailadmin/inc/class.bo.inc.php'); $emailadmin = new emailadmin_bo();
$emailadmin = new bo();
$user_profile = $emailadmin->getUserProfile('felamimail'); $user_profile = $emailadmin->getUserProfile('felamimail');
unset($emailadmin); unset($emailadmin);

View File

@ -5,7 +5,7 @@
* @link http://www.egroupware.org * @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @package admin * @package admin
* @copyright (c) 2007 by Ralf Becker <RalfBecker-AT-outdoor-training.de> * @copyright (c) 2007-10 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$ * @version $Id$
*/ */
@ -21,8 +21,9 @@ class admin_cmd_edit_user extends admin_cmd_change_pw
* @param string/int/array $account account name or id (!$account to add a new account), or array with all parameters * @param string/int/array $account account name or id (!$account to add a new account), or array with all parameters
* @param array $set=null array with all data to change * @param array $set=null array with all data to change
* @param string $password=null password * @param string $password=null password
* @param boolean $run_addaccount_hook=null default run addaccount for new accounts and editaccount for existing ones
*/ */
function __construct($account,$set=null,$password=null) function __construct($account,$set=null,$password=null,$run_addaccount_hook=null)
{ {
if (!is_array($account)) if (!is_array($account))
{ {
@ -30,6 +31,7 @@ class admin_cmd_edit_user extends admin_cmd_change_pw
'account' => $account, 'account' => $account,
'set' => $set, 'set' => $set,
'password' => is_null($password) ? $set['account_passwd'] : $password, 'password' => is_null($password) ? $set['account_passwd'] : $password,
'run_addaccount_hook' => $run_addaccount_hook,
); );
} }
admin_cmd::__construct($account); admin_cmd::__construct($account);
@ -167,7 +169,7 @@ class admin_cmd_edit_user extends admin_cmd_change_pw
$data['account_passwd'] = $this->password; $data['account_passwd'] = $this->password;
$GLOBALS['hook_values'] =& $data; $GLOBALS['hook_values'] =& $data;
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array( $GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
'location' => $this->account ? 'editaccount' : 'addaccount' 'location' => $this->account && $this->run_addaccount_hook !== true ? 'editaccount' : 'addaccount'
),False,True); // called for every app now, not only enabled ones) ),False,True); // called for every app now, not only enabled ones)
return lang("Account %1 %2",$this->account ? $this->account : $data['account_lid'], return lang("Account %1 %2",$this->account ? $this->account : $data['account_lid'],

View File

@ -103,9 +103,9 @@ class setup_cmd_admin extends setup_cmd
} }
$this->restore_db(); $this->restore_db();
// run admin/admin-cli.php --edit-user to store the new accounts once in EGroupware // run admin/admin-cli.php --add-user to store the new accounts once in EGroupware
// to run all hooks (some of them can NOT run inside setup) // to run all hooks (some of them can NOT run inside setup)
$cmd = EGW_SERVER_ROOT.'/admin/admin-cli.php --edit-user '. $cmd = EGW_SERVER_ROOT.'/admin/admin-cli.php --add-user '.
escapeshellarg($this->admin_user.'@'.$this->domain.','.$this->admin_password.','.$this->admin_user); escapeshellarg($this->admin_user.'@'.$this->domain.','.$this->admin_password.','.$this->admin_user);
exec($cmd,$output,$ret); exec($cmd,$output,$ret);
$output = implode("\n",$output); $output = implode("\n",$output);