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 + 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); } 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)