resub-feed.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * StatusNet - a distributed open-source microblogging tool
  5. * Copyright (C) 2010, StatusNet, Inc.
  6. *
  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.
  11. *
  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.
  16. *
  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/>.
  19. */
  20. define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
  21. $longoptions = array('unsub');
  22. $shortoptions = 'u';
  23. $helptext = <<<END_OF_HELP
  24. resub-feed.php [options] http://example.com/atom-feed-url
  25. Reinitialize the WebSub subscription for the given feed. This may help get
  26. things restarted if we and the hub have gotten our states out of sync.
  27. Options:
  28. -u --unsub Unsubscribe instead of subscribing.
  29. END_OF_HELP;
  30. require_once INSTALLDIR.'/scripts/commandline.inc';
  31. $validate = new Validate();
  32. if (empty($args[0]) || !$validate->uri($args[0])) {
  33. print "$helptext";
  34. exit(1);
  35. }
  36. $feedurl = $args[0];
  37. $sub = FeedSub::getKV('uri', $feedurl);
  38. if (!$sub) {
  39. print "Feed $feedurl is not subscribed.\n";
  40. exit(1);
  41. }
  42. print "Old state:\n";
  43. showSub($sub);
  44. try {
  45. echo "\n";
  46. if (have_option('u') || have_option('--unsub')) {
  47. echo "Pinging hub {$sub->huburi} with unsubscription for {$sub->uri}\n";
  48. $sub->unsubscribe();
  49. } else {
  50. echo "Pinging hub {$sub->huburi} with new subscription for {$sub->uri}\n";
  51. $sub->subscribe();
  52. }
  53. echo "ok\n";
  54. } catch (Exception $e) {
  55. echo 'Could not confirm. '.get_class($e).': '.$e->getMessage()."\n";
  56. }
  57. $sub2 = FeedSub::getKV('uri', $feedurl);
  58. print "\n";
  59. print "New state:\n";
  60. showSub($sub2);
  61. function showSub($sub)
  62. {
  63. print " Subscription state: $sub->sub_state\n";
  64. print " Verify token: $sub->verify_token\n";
  65. print " Signature secret: $sub->secret\n";
  66. print " Sub start date: $sub->sub_start\n";
  67. print " Sub end date: $sub->sub_end\n";
  68. print " Sub lease remaining: {$sub->getLeaseRemaining()}\n";
  69. print " Record created: $sub->created\n";
  70. print " Record modified: $sub->modified\n";
  71. }