moved saving of account contact-data to accounts class

This commit is contained in:
Ralf Becker 2006-07-08 00:20:27 +00:00
parent 236ed1e3df
commit ad7972870c
2 changed files with 35 additions and 30 deletions

View File

@ -298,12 +298,40 @@ class accounts extends accounts_backend
}
}
}
if (($id = parent::save($data)) && $data['account_type'] == 'u' && $data['account_primary_group'] &&
(!($memberships = $this->memberships($id,true)) || !in_array($data['account_primary_group'],$memberships)))
if (($id = parent::save($data)) && $data['account_type'] != 'g')
{
$this->cache_invalidate($data['account_id']);
$memberships[] = $data['account_primary_group'];
$this->set_memberships($memberships,$id);
// if we are not on a pure LDAP system, we have to write the account-date via the contacts class now
if (($GLOBALS['egw_info']['server']['account_repository'] != 'ldap' ||
$GLOBALS['egw_info']['server']['contact_repository'] != 'ldap') &&
(!($old = $this->read($data['account_id'])) || // only for new account or changed contact-data
$old['account_firstname'] != $data['account_firstname'] ||
$old['account_lastname'] != $data['account_lastname'] ||
$old['account_email'] != $data['account_email']))
{
if (!$data['person_id']) $data['person_id'] = $old['person_id'];
if (!is_object($GLOBALS['egw']->contacts))
{
$GLOBALS['egw']->contacts =& CreateObject('phpgwapi.contacts');
}
$contact = array(
'n_given' => $data['account_firstname'],
'n_family' => $data['account_lastname'],
'email' => $data['account_email'],
'account_id' => $data['account_id'],
'id' => $data['person_id'],
'owner' => 0,
);
$GLOBALS['egw']->contacts->save($contact,true); // true = ignore addressbook acl
}
// save primary group if necessary
if ($data['account_primary_group'] && (!($memberships = $this->memberships($id,true)) ||
!in_array($data['account_primary_group'],$memberships)))
{
$this->cache_invalidate($data['account_id']);
$memberships[] = $data['account_primary_group'];
$this->set_memberships($memberships,$id);
}
}
$this->cache_invalidate($data['account_id']);

View File

@ -5,7 +5,7 @@
* The SQL backend stores the group memberships via the ACL class (location 'phpgw_group')
*
* The (positive) account_id's of groups are mapped in this class to negative numeric
* account_id's, to conform wit the way we handle groups in LDAP!
* account_id's, to conform with the way we handle groups in LDAP!
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> complete rewrite in 6/2006 and
@ -186,30 +186,7 @@ class accounts_backend
{
return false;
}
// check if account and the contact-data changed
if ($data['account_type'] == 'g' || ($old = $this->read($data['account_id'])) &&
$old['account_firstname'] == $data['account_firstname'] &&
$old['account_lastname'] == $data['account_lastname'] &&
$old['account_email'] == $data['account_email'])
{
return $data['account_id']; // group or no change --> no need to update the contact
}
if (!$data['person_id']) $data['person_id'] = $old['person_id'];
}
if (!is_object($GLOBALS['egw']->contacts))
{
$GLOBALS['egw']->contacts =& CreateObject('phpgwapi.contacts');
}
$contact = array(
'n_given' => $data['account_firstname'],
'n_family' => $data['account_lastname'],
'email' => $data['account_email'],
'account_id' => $data['account_id'],
'id' => $data['person_id'],
'owner' => 0,
);
$GLOBALS['egw']->contacts->save($contact,true); // true = ignore addressbook acl
return $data['account_id'];
}