From 274b70784fa75f6d8cb647e6378110fc34240abc Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Thu, 17 Oct 2013 13:00:13 +0200 Subject: [PATCH] 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()... --- actions/apigroupprofileupdate.php | 6 ------ actions/editgroup.php | 6 ------ classes/User_group.php | 34 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/actions/apigroupprofileupdate.php b/actions/apigroupprofileupdate.php index 2f4d07b7a4..c3ceb92a38 100644 --- a/actions/apigroupprofileupdate.php +++ b/actions/apigroupprofileupdate.php @@ -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) { diff --git a/actions/editgroup.php b/actions/editgroup.php index 10ce4a2112..1f77880684 100644 --- a/actions/editgroup.php +++ b/actions/editgroup.php @@ -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)); diff --git a/classes/User_group.php b/classes/User_group.php index 9209258874..af1f3a6846 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -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 && -- 2.39.5