When updating a User_group nickname, correlate Local_group and Profile
...no need to make a separate call to Local_group's setNickname all the time, or a bunch of redundant code for the Profile table. Next up is User->update()...
This commit is contained in:
parent
6ed66d9c76
commit
274b70784f
|
@ -170,12 +170,6 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
|
|||
$this->serverError(_('Could not create aliases.'));
|
||||
}
|
||||
|
||||
if (!empty($this->nickname) && ($this->nickname != $orig->nickname)) {
|
||||
common_log(LOG_INFO, "Saving local group info.");
|
||||
$local = Local_group::getKV('group_id', $this->group->id);
|
||||
$local->setNickname($this->nickname);
|
||||
}
|
||||
|
||||
$this->group->query('COMMIT');
|
||||
|
||||
switch($this->format) {
|
||||
|
|
|
@ -270,12 +270,6 @@ class EditgroupAction extends GroupAction
|
|||
$this->serverError(_('Could not create aliases.'));
|
||||
}
|
||||
|
||||
if ($nickname != $orig->nickname) {
|
||||
common_log(LOG_INFO, "Saving local group info.");
|
||||
$local = Local_group::getKV('group_id', $this->group->id);
|
||||
$local->setNickname($nickname);
|
||||
}
|
||||
|
||||
$this->group->query('COMMIT');
|
||||
|
||||
Event::handle('EndGroupSaveForm', array($this));
|
||||
|
|
|
@ -782,6 +782,40 @@ class User_group extends Managed_DataObject
|
|||
return parent::delete();
|
||||
}
|
||||
|
||||
public function update($orig)
|
||||
{
|
||||
// Whenever the User_group is updated, find the Local_group
|
||||
// and updates it nickname too.
|
||||
if ($this->nickname != $orig->nickname) {
|
||||
$local = Local_group::getKV('group_id', $this->id);
|
||||
if ($local instanceof Local_group) {
|
||||
common_debug("Updating Local_group ({$this->id}) nickname from {$orig->nickname} to {$this->nickname}");
|
||||
$local->setNickname($this->nickname);
|
||||
}
|
||||
}
|
||||
|
||||
$fields = array(/*group field => profile field*/
|
||||
'nickname' => 'nickname',
|
||||
'fullname' => 'fullname',
|
||||
'mainpage' => 'profileurl',
|
||||
'homepage' => 'homepage',
|
||||
'description' => 'bio',
|
||||
'location' => 'location',
|
||||
'created' => 'created',
|
||||
'modified' => 'modified',
|
||||
);
|
||||
$profile = $this->getProfile();
|
||||
$origpro = clone($profile);
|
||||
foreach ($fields as $gf=>$pf) {
|
||||
$profile->$pf = $this->$gf;
|
||||
}
|
||||
if ($profile->update($origpro) === false) {
|
||||
throw new ServerException(_('Unable to update profile'));
|
||||
}
|
||||
|
||||
return parent::update($orig);
|
||||
}
|
||||
|
||||
function isPrivate()
|
||||
{
|
||||
return ($this->join_policy == self::JOIN_POLICY_MODERATE &&
|
||||
|
|
Loading…
Reference in New Issue
Block a user