summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-12-17 16:27:20 -0500
committerEvan Prodromou <evan@status.net>2010-12-17 16:27:20 -0500
commit4b41d05a13cc8d49871687b767640fbcd15eb05c (patch)
tree8a55167bf3f201757ff609e0bf8cc2c76fd0d311 /lib
parent044763cf06b1fb99cd8246dcbb8bb4a3e545d3ed (diff)
Make restoreuser use new FeedImporter queue handler
Diffstat (limited to 'lib')
-rw-r--r--lib/activityimporter.php9
-rw-r--r--lib/feedimporter.php36
2 files changed, 40 insertions, 5 deletions
diff --git a/lib/activityimporter.php b/lib/activityimporter.php
index 07a6b0e77..e936449c8 100644
--- a/lib/activityimporter.php
+++ b/lib/activityimporter.php
@@ -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);
diff --git a/lib/feedimporter.php b/lib/feedimporter.php
index e2c9df72f..0b94eeb9b 100644
--- a/lib/feedimporter.php
+++ b/lib/feedimporter.php
@@ -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);