* Copyright (C) 2010, StatusNet, Inc.
*
* Title of module
- *
+ *
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
-
class ActivityMover extends QueueHandler
{
function transport()
{
return 'actmove';
}
-
+
function handle($data)
{
list ($act, $sink, $userURI, $remoteURI) = $data;
- $user = User::staticGet('uri', $userURI);
- $remote = Profile::fromURI($remoteURI);
+ $user = User::getKV('uri', $userURI);
+ try {
+ $remote = Profile::fromUri($remoteURI);
+ } catch (UnknownUriException $e) {
+ // Don't retry. It's hard to tell whether it's because of
+ // lookup failures or because the URI is permanently gone.
+ // If we knew it was temporary, we'd return false here.
+ return true;
+ }
try {
$this->moveActivity($act, $sink, $user, $remote);
function moveActivity($act, $sink, $user, $remote)
{
if (empty($user)) {
- throw new Exception("No such user {$act->actor->id}");
+ // TRANS: Exception thrown if a non-existing user is provided. %s is a user ID.
+ throw new Exception(sprintf(_('No such user "%s".'),$act->actor->id));
}
switch ($act->verb) {
- case ActivityVerb::FAVORITE:
+/* case ActivityVerb::FAVORITE:
$this->log(LOG_INFO,
"Moving favorite of {$act->objects[0]->id} by ".
"{$act->actor->id} to {$remote->nickname}.");
// push it, then delete local
$sink->postActivity($act);
- $notice = Notice::staticGet('uri', $act->objects[0]->id);
+ $notice = Notice::getKV('uri', $act->objects[0]->id);
if (!empty($notice)) {
$fave = Fave::pkeyGet(array('user_id' => $user->id,
'notice_id' => $notice->id));
$fave->delete();
}
- break;
+ break;*/
case ActivityVerb::POST:
$this->log(LOG_INFO,
"Moving notice {$act->objects[0]->id} by ".
"{$act->actor->id} to {$remote->nickname}.");
// XXX: send a reshare, not a post
$sink->postActivity($act);
- $notice = Notice::staticGet('uri', $act->objects[0]->id);
+ $notice = Notice::getKV('uri', $act->objects[0]->id);
if (!empty($notice)) {
$notice->delete();
}
"Moving group join of {$act->objects[0]->id} by ".
"{$act->actor->id} to {$remote->nickname}.");
$sink->postActivity($act);
- $group = User_group::staticGet('uri', $act->objects[0]->id);
+ $group = User_group::getKV('uri', $act->objects[0]->id);
if (!empty($group)) {
- Group_member::leave($group->id, $user->id);
+ $user->leaveGroup($group);
}
break;
case ActivityVerb::FOLLOW:
- if ($act->actor->id == $user->uri) {
+ if ($act->actor->id === $user->getUri()) {
$this->log(LOG_INFO,
"Moving subscription to {$act->objects[0]->id} by ".
"{$act->actor->id} to {$remote->nickname}.");
$sink->postActivity($act);
- $other = Profile::fromURI($act->objects[0]->id);
- if (!empty($other)) {
+ try {
+ $other = Profile::fromUri($act->objects[0]->id);
Subscription::cancel($user->getProfile(), $other);
+ } catch (UnknownUriException $e) {
+ // Can't cancel subscription if we don't know who to alert
}
} else {
- $otherUser = User::staticGet('uri', $act->actor->id);
+ $otherUser = User::getKV('uri', $act->actor->id);
if (!empty($otherUser)) {
$this->log(LOG_INFO,
"Changing sub to {$act->objects[0]->id}".
/**
* Log some data
- *
+ *
* Add a header for our class so we know who did it.
*
* @param int $level Log level, like LOG_ERR or LOG_INFO
*
* @return void
*/
-
protected function log($level, $message)
{
common_log($level, "ActivityMover: " . $message);