123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <?php
- define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
- $helptext = <<<END_OF_HELP
- update-profile.php [options] http://example.com/profile/url
- Rerun profile and feed info discovery for the given OStatus remote profile,
- and reinitialize its WebSub subscription for the given feed. This may help get
- things restarted if the hub or feed URLs have changed for the profile.
- END_OF_HELP;
- require_once INSTALLDIR.'/scripts/commandline.inc';
- $validate = new Validate();
- if (empty($args[0]) || !$validate->uri($args[0])) {
- print "$helptext";
- exit(1);
- }
- $uri = $args[0];
- $oprofile = Ostatus_profile::getKV('uri', $uri);
- if (!$oprofile) {
- print "No OStatus remote profile known for URI $uri\n";
- exit(1);
- }
- print "Old profile state for $oprofile->uri\n";
- showProfile($oprofile);
- print "\n";
- print "Re-running feed discovery for profile URL $oprofile->uri\n";
- $feedurl = null;
- $salmonuri = null;
- $discover = new FeedDiscovery();
- try {
- $feedurl = $discover->discoverFromURL($oprofile->uri);
- $salmonuri = $discover->getAtomLink(Salmon::REL_SALMON)
- ?: $discover->getAtomLink(Salmon::NS_REPLIES);
- if (empty($salmonuri) ) {
- throw new FeedSubNoSalmonException('No salmon upstream URI was found');
- }
- } catch (FeedSubException $e) {
- $acct = $oprofile->localProfile()->getAcctUri();
- print "Could not discover feeds HTML response, trying reconstructed acct URI: {$acct}\n";
- $disco = new Discovery();
- $xrd = $disco->lookup($acct);
- $hints = DiscoveryHints::fromXRD($xrd);
- if (array_key_exists('feedurl', $hints)) {
-
- $feedurl = $hints['feedurl'];
- } elseif (empty($feedurl)) {
-
- throw new FeedSubNoFeedException($acct);
- }
- $salmonuri = array_key_exists('salmon', $hints) ? $hints['salmon'] : $salmonuri;
-
- $discover->discoverFromFeedUrl($feedurl);
- }
- $huburi = $discover->getHubLink();
- print " Feed URL: $feedurl\n";
- print " Hub URL: $huburi\n";
- print " Salmon URL: $salmonuri\n";
- if ($feedurl != $oprofile->feeduri || $salmonuri != $oprofile->salmonuri) {
- print "\n";
- print "Updating...\n";
-
-
-
-
-
- $ok = $oprofile->query('UPDATE ostatus_profile SET ' .
- 'feeduri=\'' . $oprofile->escape($feedurl) . '\',' .
- 'salmonuri=\'' . $oprofile->escape($salmonuri) . '\' ' .
- 'WHERE uri=\'' . $oprofile->escape($uri) . '\'');
- if (!$ok) {
- print "Failed to update profile record...\n";
- exit(1);
- }
- $oprofile->decache();
- } else {
- print "\n";
- print "Ok, ostatus_profile record unchanged.\n\n";
- }
- $sub = FeedSub::ensureFeed($feedurl);
- if ($huburi != $sub->huburi) {
- print "\n";
- print "Updating hub record for feed; was $sub->huburi\n";
- $orig = clone($sub);
- $sub->huburi = $huburi;
- $ok = $sub->update($orig);
- if (!$ok) {
- print "Failed to update sub record...\n";
- exit(1);
- }
- } else {
- print "\n";
- print "Feed record ok, not changing.\n\n";
- }
- echo "\n";
- echo "Pinging hub {$sub->huburi} with new subscription for {$sub->uri}\n";
- try {
- $sub->subscribe();
- echo "ok\n";
- } catch (Exception $e) {
- echo 'Could not confirm. '.get_class($e).': '.$e->getMessage()."\n";
- }
- $o2 = Ostatus_profile::getKV('uri', $uri);
- print "\n";
- print "New profile state:\n";
- showProfile($o2);
- print "\n";
- print "New feed state:\n";
- $sub2 = FeedSub::ensureFeed($feedurl);
- showSub($sub2);
- function showProfile($oprofile)
- {
- print " Feed URL: $oprofile->feeduri\n";
- print " Salmon URL: $oprofile->salmonuri\n";
- print " Avatar URL: $oprofile->avatar\n";
- print " Profile ID: $oprofile->profile_id\n";
- print " Group ID: $oprofile->group_id\n";
- print " Record created: $oprofile->created\n";
- print " Record modified: $oprofile->modified\n";
- }
- function showSub($sub)
- {
- print " Subscription state: $sub->sub_state\n";
- print " Signature secret: $sub->secret\n";
- print " Sub start date: $sub->sub_start\n";
- print " Record created: $sub->created\n";
- print " Record modified: $sub->modified\n";
- }
|