]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/scripts/update-profile.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / OStatus / scripts / update-profile.php
old mode 100644 (file)
new mode 100755 (executable)
index a0d007a..40adda1
@@ -30,9 +30,11 @@ things restarted if the hub or feed URLs have changed for the profile.
 
 END_OF_HELP;
 
-require_once INSTALLDIR.'/scripts/commandline.inc';
+require_once INSTALLDIR.'/scripts/commandline.inc.php';
 
-if (empty($args[0]) || !Validate::uri($args[0])) {
+$validate = new Validate();
+
+if (empty($args[0]) || !$validate->uri($args[0])) {
     print "$helptext";
     exit(1);
 }
@@ -52,12 +54,37 @@ showProfile($oprofile);
 
 print "\n";
 print "Re-running feed discovery for profile URL $oprofile->uri\n";
+
+$feedurl = null;
+$salmonuri = null;
+
 // @fixme will bork where the URI isn't the profile URL for now
 $discover = new FeedDiscovery();
-$feedurl = $discover->discoverFromURL($oprofile->uri);
+try {
+    $feedurl = $discover->discoverFromURL($oprofile->uri);
+    $salmonuri = $discover->getAtomLink(Salmon::REL_SALMON)
+                    ?: $discover->getAtomLink(Salmon::NS_REPLIES);  // NS_REPLIES is deprecated
+    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 (empty($feedurl) && !array_key_exists('feedurl', $hints)) {
+        throw new FeedSubNoFeedException($acct);
+    }
+    $feedurl = $feedurl ?: $hints['feedurl'];
+    $salmonuri = array_key_exists('salmon', $hints) ? $hints['salmon'] : $salmonuri;
+
+    // get the hub data too and put it in the FeedDiscovery object
+    $discover->discoverFromFeedUrl($feedurl);
+}
+
 $huburi = $discover->getHubLink();
-$salmonuri = $discover->getAtomLink(Salmon::REL_SALMON)
-                ?: $discover->getAtomLink(Salmon::NS_REPLIES);
 
 print "  Feed URL: $feedurl\n";
 print "  Hub URL: $huburi\n";
@@ -105,14 +132,13 @@ if ($huburi != $sub->huburi) {
     print "Feed record ok, not changing.\n\n";
 }
 
-print "\n";
-print "Pinging hub $sub->huburi with new subscription for $sub->uri\n";
-$ok = $sub->subscribe();
-
-if ($ok) {
-    print "ok\n";
-} else {
-    print "Could not confirm.\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);