Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / lib / activityutils.php
index bb430c6f7849b8f0818b18933d190f1d7005aab9..76e4777deb5feb471dc69960ff1c1feee64c00f4 100644 (file)
@@ -380,32 +380,33 @@ class ActivityUtils
     }
 
     static function findLocalObject(array $uris, $type=ActivityObject::NOTE) {
-        $object = null;
-        // TODO: Extend this in plugins etc.
-        if (Event::handle('StartFindLocalActivityObject', array($uris, $type, &$object))) {
+        $obj_class = null;
+        // TODO: Extend this in plugins etc. and describe in EVENTS.txt
+        if (Event::handle('StartFindLocalActivityObject', array($uris, $type, &$obj_class))) {
             switch (self::resolveUri($type)) {
             case ActivityObject::PERSON:
                 // GROUP will also be here in due time...
-                $object = new Profile();
+                $obj_class = 'Profile';
                 break;
             default:
-                $object = new Notice();
+                $obj_class = 'Notice';
             }
         }
-        foreach (array_unique($uris) as $uri) {
+        $object = null;
+        $uris = array_unique($uris);
+        foreach ($uris as $uri) {
             try {
                 // the exception thrown will cancel before reaching $object
-                $object = call_user_func(array($object, 'fromUri'), $uri);
+                $object = call_user_func("{$obj_class}::fromUri", $uri);
                 break;
-            } catch (Exception $e) {
-                common_debug('Could not find local activity object from uri: '.$uri);
+            } catch (UnknownUriException $e) {
+                common_debug('Could not find local activity object from uri: '.$e->object_uri);
             }
         }
-        if (!empty($object)) {
-            Event::handle('EndFindLocalActivityObject', array($object->getUri(), $type, $object));
-        } else {
-            throw new ServerException('Could not find any activityobject stored locally with given URI');
+        if (!$object instanceof Managed_DataObject) {
+            throw new ServerException('Could not find any activityobject stored locally with given URIs: '.var_export($uris,true));
         }
+        Event::handle('EndFindLocalActivityObject', array($object->getUri(), $object->getObjectType(), $object));
         return $object;
     }