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/
48 class AccountMover extends QueueHandler
55 function handle($object)
57 list($user, $remote, $password) = $object;
59 $remote = Discovery::normalize($remote);
61 $oprofile = Ostatus_profile::ensureProfileURI($remote);
63 if (empty($oprofile)) {
64 throw new Exception("Can't locate account {$remote}");
67 list($svcDocUrl, $username) = self::getServiceDocument($remote);
69 $sink = new ActivitySink($svcDocUrl, $username, $password);
72 "Moving user {$user->nickname} ".
75 $stream = new UserActivityStream($user);
77 // Reverse activities to run in correct chron order
79 $acts = array_reverse($stream->activities);
82 "Got ".count($acts)." activities ".
83 "for {$user->nickname}.");
85 $qm = QueueManager::get();
87 foreach ($acts as $act) {
88 $qm->enqueue(array($act, $sink, $user->uri, $remote), 'actmove');
92 "Finished moving user {$user->nickname} ".
96 static function getServiceDocument($remote)
98 $discovery = new Discovery();
100 $xrd = $discovery->lookup($remote);
103 throw new Exception("Can't find XRD for $remote");
109 foreach ($xrd->links as $link) {
110 if ($link['rel'] == 'http://apinamespace.org/atom' &&
111 $link['type'] == 'application/atomsvc+xml') {
112 $svcDocUrl = $link['href'];
113 if (!empty($link['property'])) {
114 foreach ($link['property'] as $property) {
115 if ($property['type'] == 'http://apinamespace.org/atom/username') {
116 $username = $property['value'];
125 if (empty($svcDocUrl)) {
126 throw new Exception("No AtomPub API service for $remote.");
129 return array($svcDocUrl, $username);
135 * Add a header for our class so we know who did it.
137 * @param int $level Log level, like LOG_ERR or LOG_INFO
138 * @param string $message Message to log
143 protected function log($level, $message)
145 common_log($level, "AccountMover: " . $message);