]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Make restoreuser use new FeedImporter queue handler
authorEvan Prodromou <evan@status.net>
Fri, 17 Dec 2010 21:27:20 +0000 (16:27 -0500)
committerEvan Prodromou <evan@status.net>
Fri, 17 Dec 2010 21:27:20 +0000 (16:27 -0500)
lib/activityimporter.php
lib/feedimporter.php
scripts/restoreuser.php

index 07a6b0e77b315ce18c74c1041b63172fa6470411..e936449c86bbc2848bc8ecd16c855a36f3d05357 100644 (file)
@@ -81,10 +81,10 @@ class ActivityImporter extends QueueHandler
             common_log(LOG_WARNING, $ce->getMessage());
             return true;
         } catch (ServerException $se) {
-            common_log(LOG_ERR, $ce->getMessage());
+            common_log(LOG_ERR, $se->getMessage());
             return false;
         } catch (Exception $e) {
-            common_log(LOG_ERR, $ce->getMessage());
+            common_log(LOG_ERR, $e->getMessage());
             return false;
         }
         return true;
@@ -95,6 +95,11 @@ class ActivityImporter extends QueueHandler
         $profile = $user->getProfile();
 
         if ($activity->objects[0]->id == $author->id) {
+
+            if (!$this->trusted) {
+                throw new ClientException(_("Can't force subscription for untrusted user."));
+            }
+
             $other = $activity->actor;
             $otherUser = User::staticGet('uri', $other->id);
             
index e2c9df72fd9f3e69515779e45e1870ce8b1d76df..0b94eeb9b85843688619eec0e0be76ecad6bad3e 100644 (file)
@@ -84,12 +84,12 @@ class FeedImporter extends QueueHandler
             if (empty($user)) {
                 if ($trusted) {
                     $user = $this->userFromAuthor($author);
+                } else {
+                    throw new ClientException(_("Can't import without a user."));
                 }
             }
 
-            $entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry');
-
-            $activities = $this->entriesToActivities($entries, $feed);
+            $activities = $this->getActivities($feed);
 
             $qm = QueueManager::get();
 
@@ -108,6 +108,36 @@ class FeedImporter extends QueueHandler
         }
     }
 
+    function getActivities($feed)
+    {
+        $entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry');
+
+        $activities = array();
+
+        for ($i = 0; $i < $entries->length; $i++) {
+            $activities[] = new Activity($entries->item($i));
+        }
+
+        usort($activities, array("FeedImporter", "activitySort"));
+
+        return $activities;
+    }
+
+    /**
+     * Sort activities oldest-first
+     */
+
+    static function activitySort($a, $b)
+    {
+        if ($a->time == $b->time) {
+            return 0;
+        } else if ($a->time < $b->time) {
+            return -1;
+        } else {
+            return 1;
+        }
+    }
+
     function userFromAuthor($author)
     {
         $user = User::staticGet('uri', $author->id);
index eac7e5cf2902cef005f47b4015cabfe33cc240ad..17f007b41206406c36d13e6711f7bda7d8535d71 100644 (file)
@@ -75,9 +75,8 @@ try {
         $user = null;
     }
     $xml = getActivityStreamDocument();
-    $restorer = new AccountRestorer();
-    $doc = $restorer->loadXML($xml);
-    $restorer->importActivityStream($user, $doc);
+    $qm = QueueManager::get();
+    $qm->enqueue(array($user, $xml, true), 'feedimp');
 } catch (Exception $e) {
     print $e->getMessage()."\n";
     exit(1);