]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Treat author just as anyone else (Notice distrib)
[quix0rs-gnu-social.git] / classes / Notice.php
index 4b0db2988da188bd2374cb136efd29407ae0f641..f0a7a85bff3ab64e85baee4b1e07c968413ca60f 100644 (file)
@@ -142,20 +142,20 @@ class Notice extends Managed_DataObject
     const FOLLOWER_SCOPE  = 8;
 
     protected $_profile = -1;
-
+    
     public function getProfile()
     {
         if ($this->_profile === -1) {
             $this->_setProfile(Profile::getKV('id', $this->profile_id));
         }
-        if (!$this->_profile instanceof Profile) {
-            throw new NoProfileException($this->profile_id);
-        }
         return $this->_profile;
     }
     
-    function _setProfile(Profile $profile)
+    public function _setProfile(Profile $profile=null)
     {
+        if (!$profile instanceof Profile) {
+            throw new NoProfileException($this->profile_id);
+        }
         $this->_profile = $profile;
     }
 
@@ -216,6 +216,16 @@ class Notice extends Managed_DataObject
         return $this->url ?: $this->uri;
     }
 
+    public static function getByUri($uri)
+    {
+        $notice = new Notice();
+        $notice->uri = $uri;
+        if (!$notice->find(true)) {
+            throw new NoResultException($notice);
+        }
+        return $notice;
+    }
+
     /**
      * Extract #hashtags from this notice's content and save them to the database.
      */
@@ -577,13 +587,13 @@ class Notice extends Managed_DataObject
             // the beginning of a new conversation.
 
             if (empty($notice->conversation)) {
-                $conv = Conversation::create();
+                $conv = Conversation::create($notice);
                 $notice->conversation = $conv->id;
                 $changed = true;
             }
 
             if ($changed) {
-                if (!$notice->update($orig)) {
+                if ($notice->update($orig) === false) {
                     common_log_db_error($notice, 'UPDATE', __FILE__);
                     // TRANS: Server exception thrown when a notice cannot be updated.
                     throw new ServerException(_('Problem saving notice.'));
@@ -1075,18 +1085,8 @@ class Notice extends Managed_DataObject
 
         $ids = array_keys($ni);
 
-        // We remove the author (if they're a local user),
-        // since we'll have already done this in distribute()
-
-        $i = array_search($this->profile_id, $ids);
-
-        if ($i !== false) {
-            unset($ids[$i]);
-        }
-
         // Bulk insert
-
-        Inbox::bulkInsert($this->id, $ids);
+        Inbox::bulkInsert($this, $ids);
 
         return;
     }
@@ -2056,33 +2056,23 @@ class Notice extends Managed_DataObject
         // have to wait
         Event::handle('StartNoticeDistribute', array($this));
 
-        $user = User::getKV('id', $this->profile_id);
-        if ($user instanceof User) {
-            Inbox::insertNotice($user->id, $this->id);
-        }
-
-        if (common_config('queue', 'inboxes')) {
-            // If there's a failure, we want to _force_
-            // distribution at this point.
+        // If there's a failure, we want to _force_
+        // distribution at this point.
+        try {
+            $qm = QueueManager::get();
+            $qm->enqueue($this, 'distrib');
+        } catch (Exception $e) {
+            // If the exception isn't transient, this
+            // may throw more exceptions as DQH does
+            // its own enqueueing. So, we ignore them!
             try {
-                $qm = QueueManager::get();
-                $qm->enqueue($this, 'distrib');
+                $handler = new DistribQueueHandler();
+                $handler->handle($this);
             } catch (Exception $e) {
-                // If the exception isn't transient, this
-                // may throw more exceptions as DQH does
-                // its own enqueueing. So, we ignore them!
-                try {
-                    $handler = new DistribQueueHandler();
-                    $handler->handle($this);
-                } catch (Exception $e) {
-                    common_log(LOG_ERR, "emergency redistribution resulted in " . $e->getMessage());
-                }
-                // Re-throw so somebody smarter can handle it.
-                throw $e;
+                common_log(LOG_ERR, "emergency redistribution resulted in " . $e->getMessage());
             }
-        } else {
-            $handler = new DistribQueueHandler();
-            $handler->handle($this);
+            // Re-throw so somebody smarter can handle it.
+            throw $e;
         }
     }
 
@@ -2500,10 +2490,15 @@ class Notice extends Managed_DataObject
        {
                $map = self::getProfiles($notices);
                
-               foreach ($notices as $notice) {
-                       if (array_key_exists($notice->profile_id, $map)) {
-                               $notice->_setProfile($map[$notice->profile_id]);    
-                       }
+               foreach ($notices as $entry=>$notice) {
+            try {
+                       if (array_key_exists($notice->profile_id, $map)) {
+                               $notice->_setProfile($map[$notice->profile_id]);
+                       }
+            } catch (NoProfileException $e) {
+                common_log(LOG_WARNING, "Failed to fill profile in Notice with non-existing entry for profile_id: {$e->id}");
+                unset($notices[$entry]);
+            }
                }
                
                return array_values($map);