4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2010, 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 $helptext = <<<END_OF_HELP
24 update-profile.php [options] http://example.com/profile/url
26 Rerun profile and feed info discovery for the given OStatus remote profile,
27 and reinitialize its PuSH subscription for the given feed. This may help get
28 things restarted if the hub or feed URLs have changed for the profile.
33 require_once INSTALLDIR.'/scripts/commandline.inc';
35 if (empty($args[0]) || !Validate::uri($args[0])) {
43 $oprofile = Ostatus_profile::getKV('uri', $uri);
46 print "No OStatus remote profile known for URI $uri\n";
50 print "Old profile state for $oprofile->uri\n";
51 showProfile($oprofile);
54 print "Re-running feed discovery for profile URL $oprofile->uri\n";
55 // @fixme will bork where the URI isn't the profile URL for now
56 $discover = new FeedDiscovery();
58 $feedurl = $discover->discoverFromURL($oprofile->uri);
59 $salmonuri = $discover->getAtomLink(Salmon::REL_SALMON)
60 ?: $discover->getAtomLink(Salmon::NS_REPLIES); // NS_REPLIES is deprecated
61 } catch (FeedSubException $e) {
62 $acct = $oprofile->localProfile()->getAcctUri();
63 print "Could not discover feeds HTML response, trying reconstructed acct URI: " . $acct;
64 $disco = new Discovery();
65 $xrd = $disco->lookup($acct);
66 $hints = DiscoveryHints::fromXRD($xrd);
68 if (!array_key_exists('feedurl', $hints)) {
69 throw new FeedSubNoFeedException($acct);
71 $feedurl = $hints['feedurl'];
72 $salmonuri = array_key_exists('salmon', $hints) ? $hints['salmon'] : null;
74 // get the hub data too and put it in the FeedDiscovery object
75 $discover->discoverFromFeedUrl($feedurl);
78 $huburi = $discover->getHubLink();
80 print " Feed URL: $feedurl\n";
81 print " Hub URL: $huburi\n";
82 print " Salmon URL: $salmonuri\n";
84 if ($feedurl != $oprofile->feeduri || $salmonuri != $oprofile->salmonuri) {
86 print "Updating...\n";
87 // @fixme update keys :P
88 #$orig = clone($oprofile);
89 #$oprofile->feeduri = $feedurl;
90 #$oprofile->salmonuri = $salmonuri;
91 #$ok = $oprofile->update($orig);
92 $ok = $oprofile->query('UPDATE ostatus_profile SET ' .
93 'feeduri=\'' . $oprofile->escape($feedurl) . '\',' .
94 'salmonuri=\'' . $oprofile->escape($salmonuri) . '\' ' .
95 'WHERE uri=\'' . $oprofile->escape($uri) . '\'');
98 print "Failed to update profile record...\n";
102 $oprofile->decache();
105 print "Ok, ostatus_profile record unchanged.\n\n";
108 $sub = FeedSub::ensureFeed($feedurl);
110 if ($huburi != $sub->huburi) {
112 print "Updating hub record for feed; was $sub->huburi\n";
114 $sub->huburi = $huburi;
115 $ok = $sub->update($orig);
118 print "Failed to update sub record...\n";
123 print "Feed record ok, not changing.\n\n";
127 echo "Pinging hub {$sub->huburi} with new subscription for {$sub->uri}\n";
131 } catch (Exception $e) {
132 echo 'Could not confirm. '.get_class($e).': '.$e->getMessage()."\n";
135 $o2 = Ostatus_profile::getKV('uri', $uri);
138 print "New profile state:\n";
142 print "New feed state:\n";
143 $sub2 = FeedSub::ensureFeed($feedurl);
146 function showProfile($oprofile)
148 print " Feed URL: $oprofile->feeduri\n";
149 print " Salmon URL: $oprofile->salmonuri\n";
150 print " Avatar URL: $oprofile->avatar\n";
151 print " Profile ID: $oprofile->profile_id\n";
152 print " Group ID: $oprofile->group_id\n";
153 print " Record created: $oprofile->created\n";
154 print " Record modified: $oprofile->modified\n";
157 function showSub($sub)
159 print " Subscription state: $sub->sub_state\n";
160 print " Verify token: $sub->verify_token\n";
161 print " Signature secret: $sub->secret\n";
162 print " Sub start date: $sub->sub_start\n";
163 print " Record created: $sub->created\n";
164 print " Record modified: $sub->modified\n";