]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
Reworked the ActivityContext->attention structure
[quix0rs-gnu-social.git] / classes / Profile.php
index cafaec5a3d18559ea12bc41ae2397d0686e848c2..b2dab519a1599940733f0c1a9853860db52eeb3c 100644 (file)
@@ -842,6 +842,33 @@ class Profile extends Managed_DataObject
         return ($biolimit > 0 && !empty($bio) && (mb_strlen($bio) > $biolimit));
     }
 
+    function update($dataObject=false)
+    {
+        if (is_object($dataObject) && $this->nickname != $dataObject->nickname) {
+            try {
+                $local = $this->getUser();
+                common_debug("Updating User ({$this->id}) nickname from {$dataObject->nickname} to {$this->nickname}");
+                $origuser = clone($local);
+                $local->nickname = $this->nickname;
+                $result = $local->updateKeys($origuser);
+                if ($result === false) {
+                    common_log_db_error($local, 'UPDATE', __FILE__);
+                    // TRANS: Server error thrown when user profile settings could not be updated.
+                    throw new ServerException(_('Could not update user nickname.'));
+                }
+
+                // Clear the site owner, in case nickname changed
+                if ($local->hasRole(Profile_role::OWNER)) {
+                    User::blow('user:site_owner');
+                }
+            } catch (NoSuchUserException $e) {
+                // Nevermind...
+            }
+        }
+
+        return parent::update($dataObject);
+    }
+
     function delete()
     {
         $this->_deleteNotices();
@@ -1324,6 +1351,26 @@ class Profile extends Managed_DataObject
         return $uri;
     }
 
+    /**
+     * Returns an assumed acct: URI for a profile. Plugins are required.
+     *
+     * @return string $uri
+     */
+    public function getAcctUri()
+    {
+        $acct = null;
+
+        if (Event::handle('StartGetProfileAcctUri', array($this, &$acct))) {
+            Event::handle('EndGetProfileAcctUri', array($this, &$acct));
+        }
+
+        if ($acct === null) {
+            throw new ProfileNoAcctUriException($this);
+        }
+
+        return $acct;
+    }
+
     function hasBlocked($other)
     {
         $block = Profile_block::exists($this, $other);
@@ -1351,7 +1398,7 @@ class Profile extends Managed_DataObject
         $profile = null;
 
         if (Event::handle('StartGetProfileFromURI', array($uri, &$profile))) {
-            // Get a local user or remote (OMB 0.1) profile
+            // Get a local user
             $user = User::getKV('uri', $uri);
             if (!empty($user)) {
                 $profile = $user->getProfile();