added $attributes argument to pre/postModifyActions

This commit is contained in:
Roland Gruber 2009-05-21 16:33:50 +00:00
parent 13472acf8d
commit 0d986e228d
7 changed files with 60 additions and 28 deletions

View File

@ -1012,9 +1012,10 @@ abstract class baseModule {
* An error message should be printed if the function returns false. * An error message should be printed if the function returns false.
* *
* @param boolean $newAccount new account * @param boolean $newAccount new account
* @param array $attributes LDAP attributes of this entry
* @return boolean true, if no problems occured * @return boolean true, if no problems occured
*/ */
public function preModifyActions($newAccount) { public function preModifyActions($newAccount, $attributes) {
return true; return true;
} }
@ -1024,8 +1025,9 @@ abstract class baseModule {
* Calling this method requires the existence of an enclosing {@link accountContainer}. * Calling this method requires the existence of an enclosing {@link accountContainer}.
* *
* @param boolean $newAccount new account * @param boolean $newAccount new account
* @param array $attributes LDAP attributes of this entry
*/ */
public function postModifyActions($newAccount) { public function postModifyActions($newAccount, $attributes) {
return; return;
} }

View File

@ -1684,7 +1684,33 @@ class accountContainer {
$attributes[$this->dn_orig] = $attributes[$this->finalDN]; $attributes[$this->dn_orig] = $attributes[$this->finalDN];
unset ($attributes[$this->finalDN]); unset ($attributes[$this->finalDN]);
$this->finalDN = $this->dn_orig; $this->finalDN = $this->dn_orig;
}
// pre modify actions
$currentAccountAttributes = array();
if (isset($attributes[$this->finalDN]) && is_array($attributes[$this->finalDN])) {
if (isset($attributes[$this->finalDN]['modify'])) {
$currentAccountAttributes = array_merge($currentAccountAttributes, $attributes[$this->finalDN]['modify']);
} }
if (isset($attributes[$this->finalDN]['add'])) {
$currentAccountAttributes = array_merge($currentAccountAttributes, $attributes[$this->finalDN]['add']);
}
if (isset($attributes[$this->finalDN]['notchanged'])) {
$currentAccountAttributes = array_merge($currentAccountAttributes, $attributes[$this->finalDN]['notchanged']);
}
}
$currentAccountAttributes['dn'] = $this->finalDN;
$preModifyOk = true;
foreach ($module as $singlemodule) {
$result = $this->module[$singlemodule]->preModifyActions($this->isNewAccount, $currentAccountAttributes);
if (!$result) {
$preModifyOk = false;
break;
}
}
if (!$preModifyOk) {
$errors[] = array('ERROR', _('The operation was stopped because of the above errors.'));
return $errors;
}
// Set to true if an real error has happened // Set to true if an real error has happened
$stopprocessing = false; $stopprocessing = false;
if (strtolower($this->finalDN) != strtolower($this->dn_orig)) { if (strtolower($this->finalDN) != strtolower($this->dn_orig)) {
@ -1763,7 +1789,7 @@ class accountContainer {
if (!$stopprocessing) { if (!$stopprocessing) {
// post modify actions // post modify actions
foreach ($module as $singlemodule) { foreach ($module as $singlemodule) {
$this->module[$singlemodule]->postModifyActions($this->isNewAccount); $this->module[$singlemodule]->postModifyActions($this->isNewAccount, $currentAccountAttributes);
} }
} }
$_SESSION['cache']->refresh_cache(true); $_SESSION['cache']->refresh_cache(true);

View File

@ -437,11 +437,15 @@ class fixed_ip extends baseModule {
} }
/** /**
* This function will be overwrite, because this function * This function is overwritten because the fixed IPs are set after the ldap_add command.
* creates the fixed ips after ldap_add command. *
**/ * @see baseModule::postModifyActions()
public function postModifyActions($newAccount) { *
if ($_SESSION['account']->getAccountModule('dhcp_settings')->dn!=$_SESSION['config']->get_suffix('dhcp')) { * @param boolean $newAccount
* @param array $attributes LDAP attributes of this entry
*/
public function postModifyActions($newAccount, $attributes) {
if ($_SESSION['account']->getAccountModule('dhcp_settings')->dn!=$_SESSION['config']->get_suffix('dhcp')) {
$add = array(); $add = array();
$delete = array(); $delete = array();
// Which dns are to delete and to add // Which dns are to delete and to add

View File

@ -170,22 +170,21 @@ class phpGroupwareGroup extends baseModule {
} }
/** /**
* Allows the module to run commands after the LDAP entry is changed or created. * @see baseModule::postModifyActions()
*
* Calling this method requires the existence of an enclosing {@link accountContainer}.
* *
* @param boolean $newAccount new account * @param boolean $newAccount
* @param array $attributes LDAP attributes of this entry
*/ */
public function postModifyActions($newAccount) { public function postModifyActions($newAccount, $attributes) {
// check if extension was removed // check if extension was removed
if (!$newAccount && if (!$newAccount &&
(in_array('phpgwGroup', $this->orig['objectClass']) && !in_array('phpgwGroup', $this->attributes['objectClass']))) { (in_array('phpgwGroup', $this->orig['objectClass']) && !in_array('phpgwGroup', $this->attributes['objectClass']))) {
$dn = $this->getAccountContainer()->finalDN; $dn = $this->getAccountContainer()->finalDN;
$attributes = array( $myattributes = array(
'objectClass' => array('phpgwGroup'), 'objectClass' => array('phpgwGroup'),
'phpgwGroupID' => $this->attributes['phpgwGroupID'] 'phpgwGroupID' => $this->attributes['phpgwGroupID']
); );
$success = @ldap_mod_del($_SESSION['ldap']->server(), $dn, $attributes); $success = @ldap_mod_del($_SESSION['ldap']->server(), $dn, $myattributes);
if (!$success) { if (!$success) {
StatusMessage('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $dn), ldap_error($_SESSION['ldap']->server())); StatusMessage('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $dn), ldap_error($_SESSION['ldap']->server()));
} }

View File

@ -316,19 +316,18 @@ class phpGroupwareUser extends baseModule {
} }
/** /**
* Allows the module to run commands after the LDAP entry is changed or created. * @see baseModule::postModifyActions()
*
* Calling this method requires the existence of an enclosing {@link accountContainer}.
* *
* @param boolean $newAccount new account * @param boolean $newAccount
* @param array $attributes LDAP attributes of this entry
*/ */
public function postModifyActions($newAccount) { public function postModifyActions($newAccount, $attributes) {
// check if extension was removed // check if extension was removed
if (!$newAccount && if (!$newAccount &&
(in_array('phpgwAccount', $this->orig['objectClass']) && !in_array('phpgwAccount', $this->attributes['objectClass']))) { (in_array('phpgwAccount', $this->orig['objectClass']) && !in_array('phpgwAccount', $this->attributes['objectClass']))) {
$dn = $this->getAccountContainer()->finalDN; $dn = $this->getAccountContainer()->finalDN;
$attributes = array_merge(array('objectClass'), $this->meta['attributes']); $myattributes = array_merge(array('objectClass'), $this->meta['attributes']);
$sr = @ldap_read($_SESSION['ldap']->server(), $dn, 'objectClass=*', $attributes); $sr = @ldap_read($_SESSION['ldap']->server(), $dn, 'objectClass=*', $myattributes);
if (!$sr) { if (!$sr) {
StatusMessage('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $dn), ldap_error($_SESSION['ldap']->server())); StatusMessage('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $dn), ldap_error($_SESSION['ldap']->server()));
return; return;

View File

@ -550,11 +550,12 @@ class posixAccount extends baseModule {
} }
/** /**
* Allows the module to run commands after the LDAP entry was changed or created. * @see baseModule::postModifyActions()
* *
* @param boolean $newAccount new account * @param boolean $newAccount
* @param array $attributes LDAP attributes of this entry
*/ */
function postModifyActions($newAccount) { public function postModifyActions($newAccount, $attributes) {
// create home directory if needed // create home directory if needed
if ($this->createhomedir) { if ($this->createhomedir) {
$server = null; $server = null;

View File

@ -223,11 +223,12 @@ class quota extends baseModule {
} }
/** /**
* Allows the module to run commands after the LDAP entry is changed or created. * @see baseModule::postModifyActions()
* *
* @param boolean $newAccount new account * @param boolean $newAccount
* @param array $attributes LDAP attributes of this entry
*/ */
function postModifyActions($newAccount) { public function postModifyActions($newAccount, $attributes) {
if (!isset($this->quota) || !is_array($this->quota)) return; if (!isset($this->quota) || !is_array($this->quota)) return;
// determine if this is a user or group account // determine if this is a user or group account
if ($this->get_scope()=='user') { if ($this->get_scope()=='user') {