Commit 4b41d05a authored by Evan Prodromou's avatar Evan Prodromou

Make restoreuser use new FeedImporter queue handler

parent 044763cf
...@@ -81,10 +81,10 @@ class ActivityImporter extends QueueHandler ...@@ -81,10 +81,10 @@ class ActivityImporter extends QueueHandler
common_log(LOG_WARNING, $ce->getMessage()); common_log(LOG_WARNING, $ce->getMessage());
return true; return true;
} catch (ServerException $se) { } catch (ServerException $se) {
common_log(LOG_ERR, $ce->getMessage()); common_log(LOG_ERR, $se->getMessage());
return false; return false;
} catch (Exception $e) { } catch (Exception $e) {
common_log(LOG_ERR, $ce->getMessage()); common_log(LOG_ERR, $e->getMessage());
return false; return false;
} }
return true; return true;
...@@ -95,6 +95,11 @@ class ActivityImporter extends QueueHandler ...@@ -95,6 +95,11 @@ class ActivityImporter extends QueueHandler
$profile = $user->getProfile(); $profile = $user->getProfile();
if ($activity->objects[0]->id == $author->id) { if ($activity->objects[0]->id == $author->id) {
if (!$this->trusted) {
throw new ClientException(_("Can't force subscription for untrusted user."));
}
$other = $activity->actor; $other = $activity->actor;
$otherUser = User::staticGet('uri', $other->id); $otherUser = User::staticGet('uri', $other->id);
......
...@@ -84,12 +84,12 @@ class FeedImporter extends QueueHandler ...@@ -84,12 +84,12 @@ class FeedImporter extends QueueHandler
if (empty($user)) { if (empty($user)) {
if ($trusted) { if ($trusted) {
$user = $this->userFromAuthor($author); $user = $this->userFromAuthor($author);
} else {
throw new ClientException(_("Can't import without a user."));
} }
} }
$entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry'); $activities = $this->getActivities($feed);
$activities = $this->entriesToActivities($entries, $feed);
$qm = QueueManager::get(); $qm = QueueManager::get();
...@@ -108,6 +108,36 @@ class FeedImporter extends QueueHandler ...@@ -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) function userFromAuthor($author)
{ {
$user = User::staticGet('uri', $author->id); $user = User::staticGet('uri', $author->id);
......
...@@ -75,9 +75,8 @@ try { ...@@ -75,9 +75,8 @@ try {
$user = null; $user = null;
} }
$xml = getActivityStreamDocument(); $xml = getActivityStreamDocument();
$restorer = new AccountRestorer(); $qm = QueueManager::get();
$doc = $restorer->loadXML($xml); $qm->enqueue(array($user, $xml, true), 'feedimp');
$restorer->importActivityStream($user, $doc);
} catch (Exception $e) { } catch (Exception $e) {
print $e->getMessage()."\n"; print $e->getMessage()."\n";
exit(1); exit(1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment