]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
When updating a User_group nickname, correlate Local_group and Profile
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 17 Oct 2013 11:00:13 +0000 (13:00 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 17 Oct 2013 11:49:20 +0000 (13:49 +0200)
...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
actions/editgroup.php
classes/User_group.php

index 2f4d07b7a4f4287e8abe278646cfebed92c91d28..c3ceb92a3863d9a83155628d005995713430e711 100644 (file)
@@ -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) {
index 10ce4a211236e33e1bf14ac651e3584f79afdf56..1f7788068422bd926223384412fbd4139033c60a 100644 (file)
@@ -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));
index 92092588746b10d2b0e70cbc45a0c450383f38a7..af1f3a68466fe688527e8850b5f1e2ca0a4f471e 100644 (file)
@@ -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 &&