]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Notice class local cache fixes
[quix0rs-gnu-social.git] / classes / Notice.php
index 2de4a889fa408ad79dfef2b0871cc7afdb527640..f59946ff465b22b766df6327f849ba543b34b874 100644 (file)
@@ -145,22 +145,18 @@ class Notice extends Managed_DataObject
 
     protected $_profile = -1;
 
-    function getProfile()
+    public function getProfile()
     {
-        if (is_int($this->_profile) && $this->_profile == -1) {
+        if ($this->_profile === -1) {
             $this->_setProfile(Profile::getKV('id', $this->profile_id));
-
-            if (empty($this->_profile)) {
-                // TRANS: Server exception thrown when a user profile for a notice cannot be found.
-                // TRANS: %1$d is a profile ID (number), %2$d is a notice ID (number).
-                throw new ServerException(sprintf(_('No such profile (%1$d) for notice (%2$d).'), $this->profile_id, $this->id));
-            }
         }
-
+        if (!$this->_profile instanceof Profile) {
+            throw new NoProfileException($this->profile_id);
+        }
         return $this->_profile;
     }
     
-    function _setProfile($profile)
+    function _setProfile(Profile $profile)
     {
         $this->_profile = $profile;
     }
@@ -1317,7 +1313,8 @@ class Notice extends Managed_DataObject
 
         // If it's a reply, save for the replied-to author
         try {
-            $author = $this->getParent()->getProfile();
+            $parent = $this->getParent();
+            $author = $parent->getProfile();
             if ($author instanceof Profile) {
                 $this->saveReply($author->id);
                 $replied[$author->id] = 1;
@@ -1507,8 +1504,9 @@ class Notice extends Managed_DataObject
 
         if (Event::handle('StartNoticeAsActivity', array($this, &$act))) {
 
-            $act->id      = TagURI::mint("post:".$this->id);
+            $act->id      = $this->uri;
             $act->time    = strtotime($this->created);
+            $act->link    = $this->bestUrl();
             $act->content = common_xml_safe_str($this->rendered);
 
             $profile = $this->getProfile();
@@ -1602,18 +1600,6 @@ class Notice extends Managed_DataObject
                 break;
             }
 
-            // XXX: deprecated; use ActivityVerb::SHARE instead
-
-            $repeat = null;
-
-            if (!empty($this->repeat_of)) {
-                $repeat = Notice::getKV('id', $this->repeat_of);
-                if (!empty($repeat)) {
-                    $ctx->forwardID  = $repeat->uri;
-                    $ctx->forwardUrl = $repeat->bestUrl();
-                }
-            }
-
             $act->context = $ctx;
 
             $source = $this->getSource();
@@ -2540,21 +2526,15 @@ class Notice extends Managed_DataObject
         return $groups;
     }
 
-    protected $_parent = -1;
-
     public function getParent()
     {
-        if (empty($this->reply_to)) {
-            // Should this also be NoResultException? I don't think so.
-            throw new Exception('Notice has no parent');
-        } elseif ($this->_parent === -1) {    // local object cache
-            $this->_parent = Notice::getKV('id', $this->reply_to);
-        }
+        $parent = Notice::getKV('id', $this->reply_to);
 
-        if (!($this->_parent instanceof Notice)) {
-            throw new NoResultException($this->_parent);
+        if (!$parent instanceof Notice) {
+            throw new ServerException('Notice has no parent');
         }
-        return $this->_parent;
+
+        return $parent;
     }
 
     /**
@@ -2570,7 +2550,7 @@ class Notice extends Managed_DataObject
     function __sleep()
     {
         $vars = parent::__sleep();
-        $skip = array('_parent', '_profile', '_groups', '_attachments', '_faves', '_replies', '_repeats');
+        $skip = array('_profile', '_groups', '_attachments', '_faves', '_replies', '_repeats');
         return array_diff($vars, $skip);
     }