3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * A class for moving an account to a new server
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2010 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
38 * Moves an account from this server to another
42 * @author Evan Prodromou <evan@status.net>
43 * @copyright 2010 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
47 class AccountMover extends QueueHandler
54 function handle($object)
56 list($user, $remote, $password) = $object;
58 $remote = Discovery::normalize($remote);
60 $oprofile = Ostatus_profile::ensureProfileURI($remote);
62 if (empty($oprofile)) {
63 // TRANS: Exception thrown when an account could not be located when it should be moved.
64 // TRANS: %s is the remote site.
65 throw new Exception(sprintf(_("Cannot locate account %s."),$remote));
68 list($svcDocUrl, $username) = self::getServiceDocument($remote);
70 $sink = new ActivitySink($svcDocUrl, $username, $password);
73 "Moving user {$user->nickname} ".
76 $stream = new UserActivityStream($user);
78 // Reverse activities to run in correct chron order
80 $acts = array_reverse($stream->activities);
83 "Got ".count($acts)." activities ".
84 "for {$user->nickname}.");
86 $qm = QueueManager::get();
88 foreach ($acts as $act) {
89 $qm->enqueue(array($act, $sink, $user->uri, $remote), 'actmove');
93 "Finished moving user {$user->nickname} ".
97 static function getServiceDocument($remote)
99 $discovery = new Discovery();
101 $xrd = $discovery->lookup($remote);
104 // TRANS: Exception thrown when a service document could not be located account move.
105 // TRANS: %s is the remote site.
106 throw new Exception(sprintf(_("Cannot find XRD for %s."),$remote));
112 foreach ($xrd->links as $link) {
113 if ($link['rel'] == 'http://apinamespace.org/atom' &&
114 $link['type'] == 'application/atomsvc+xml') {
115 $svcDocUrl = $link['href'];
116 if (!empty($link['property'])) {
117 foreach ($link['property'] as $property) {
118 if ($property['type'] == 'http://apinamespace.org/atom/username') {
119 $username = $property['value'];
128 if (empty($svcDocUrl)) {
129 // TRANS: Exception thrown when an account could not be located when it should be moved.
130 // TRANS: %s is the remote site.
131 throw new Exception(sprintf(_("No AtomPub API service for %s."),$remote));
134 return array($svcDocUrl, $username);
140 * Add a header for our class so we know who did it.
142 * @param int $level Log level, like LOG_ERR or LOG_INFO
143 * @param string $message Message to log
147 protected function log($level, $message)
149 common_log($level, "AccountMover: " . $message);