4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2008, 2009, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
23 $shortoptions = 'i:n:a';
24 $longoptions = array('id=', 'nickname=', 'all');
26 $helptext = <<<END_OF_UPDATEOSTATUS_HELP
27 updateostatus.php [options]
28 update the OMB subscriptions of a user to use OStatus if possible
30 -i --id ID of user to update
31 -n --nickname nickname of the user to update
34 END_OF_UPDATEOSTATUS_HELP;
36 require_once INSTALLDIR.'/scripts/commandline.inc';
41 if (have_option('i', 'id')) {
42 $id = get_option_value('i', 'id');
43 $user = User::staticGet('id', $id);
45 throw new Exception("Can't find user with id '$id'.");
47 updateProfileURL($user);
48 } else if (have_option('n', 'nickname')) {
49 $nickname = get_option_value('n', 'nickname');
50 $user = User::staticGet('nickname', $nickname);
52 throw new Exception("Can't find user with nickname '$nickname'");
54 updateProfileURL($user);
55 } else if (have_option('a', 'all')) {
58 while ($user->fetch()) {
66 } catch (Exception $e) {
67 print $e->getMessage()."\n";
71 function updateOStatus($user)
73 if (!have_option('q', 'quiet')) {
74 echo "{$user->nickname}...";
77 $up = $user->getProfile();
79 $sp = $user->getSubscriptions();
83 while ($sp->fetch()) {
84 $remote = Remote_profile::staticGet('id', $sp->id);
86 if (!empty($remote)) {
91 if (!have_option('q', 'quiet')) {
92 echo count($rps) . "\n";
95 foreach ($rps as $rp) {
97 if (!have_option('q', 'quiet')) {
98 echo "Checking {$rp->nickname}...";
101 $op = Ostatus_profile::ensureProfile($rp->profileurl);
104 echo "can't convert.\n";
107 if (!have_option('q', 'quiet')) {
108 echo "Converting...";
110 Subscription::cancel($up, $rp);
111 Subscription::start($up, $op->localProfile());
112 if (!have_option('q', 'quiet')) {
117 } catch (Exception $e) {
118 if (!have_option('q', 'quiet')) {
122 common_log(LOG_WARNING, "Couldn't convert OMB subscription (" . $up->nickname . ", " . $rp->nickname .
123 ") to OStatus: " . $e->getMessage());