From 1996545947265b92be796d2fff8d2075523cff7c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 27 Dec 2010 22:28:20 -0800 Subject: [PATCH 1/3] add events for restoring activities --- lib/activityimporter.php | 55 +++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/lib/activityimporter.php b/lib/activityimporter.php index 4a76781328..b3b7ffb066 100644 --- a/lib/activityimporter.php +++ b/lib/activityimporter.php @@ -63,31 +63,40 @@ class ActivityImporter extends QueueHandler $this->trusted = $trusted; - try { - switch ($activity->verb) { - case ActivityVerb::FOLLOW: - $this->subscribeProfile($user, $author, $activity); - break; - case ActivityVerb::JOIN: - $this->joinGroup($user, $activity); - break; - case ActivityVerb::POST: - $this->postNote($user, $author, $activity); - break; - default: - throw new Exception("Unknown verb: {$activity->verb}"); + $done = null; + + if (Event::handle('StartImportActivity', + array($user, $author, $activity, $trusted, &$done))) { + + try { + switch ($activity->verb) { + case ActivityVerb::FOLLOW: + $this->subscribeProfile($user, $author, $activity); + break; + case ActivityVerb::JOIN: + $this->joinGroup($user, $activity); + break; + case ActivityVerb::POST: + $this->postNote($user, $author, $activity); + break; + default: + throw new ClientException("Unknown verb: {$activity->verb}"); + } + Event::handle('EndImportActivity', + array($user, $author, $activity, $trusted)); + $done = true; + } catch (ClientException $ce) { + common_log(LOG_WARNING, $ce->getMessage()); + $done = true; + } catch (ServerException $se) { + common_log(LOG_ERR, $se->getMessage()); + $done = false; + } catch (Exception $e) { + common_log(LOG_ERR, $e->getMessage()); + $done = false; } - } catch (ClientException $ce) { - common_log(LOG_WARNING, $ce->getMessage()); - return true; - } catch (ServerException $se) { - common_log(LOG_ERR, $se->getMessage()); - return false; - } catch (Exception $e) { - common_log(LOG_ERR, $e->getMessage()); - return false; } - return true; + return $done; } function subscribeProfile($user, $author, $activity) From c458bafaa1158b5e7224c5d240cb1abc365cce4d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 27 Dec 2010 22:35:57 -0800 Subject: [PATCH 2/3] pass through $idField and $createdField in Notice queries --- classes/Notice.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 50909f9707..14fffe6976 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -2033,7 +2033,7 @@ class Notice extends Memcached_DataObject */ public static function addWhereSinceId(DB_DataObject $obj, $id, $idField='id', $createdField='created') { - $since = self::whereSinceId($id); + $since = self::whereSinceId($id, $idField, $createdField); if ($since) { $obj->whereAdd($since); } @@ -2072,7 +2072,7 @@ class Notice extends Memcached_DataObject */ public static function addWhereMaxId(DB_DataObject $obj, $id, $idField='id', $createdField='created') { - $max = self::whereMaxId($id); + $max = self::whereMaxId($id, $idField, $createdField); if ($max) { $obj->whereAdd($max); } From 3bcfee906abfb86dcb63951ce220d02e1395898b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 27 Dec 2010 22:37:34 -0800 Subject: [PATCH 3/3] document events for activity import --- EVENTS.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/EVENTS.txt b/EVENTS.txt index 74cf720bc0..91008f54fa 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -1026,3 +1026,17 @@ StartActivityObjectFromGroup: When converting a group to an activity:object EndActivityObjectFromGroup: After converting a group to an activity:object - $group: The group being converted - &$object: The finished object. Tweak as needed. + +StartImportActivity: when we start to import an activity +- $user: User to make the author import +- $author: Author of the feed; good for comparisons +- $activity: The current activity +- $trusted: How "trusted" the process is +- &$done: Return value; whether to continue + +EndImportActivity: when we finish importing an activity +- $user: User to make the author import +- $author: Author of the feed; good for comparisons +- $activity: The current activity +- $trusted: How "trusted" the process is +