resub-feed.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 PuSH 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. if (empty($args[0]) || !Validate::uri($args[0])) {
  32. print "$helptext";
  33. exit(1);
  34. }
  35. $feedurl = $args[0];
  36. $sub = FeedSub::getKV('uri', $feedurl);
  37. if (!$sub) {
  38. print "Feed $feedurl is not subscribed.\n";
  39. exit(1);
  40. }
  41. print "Old state:\n";
  42. showSub($sub);
  43. try {
  44. echo "\n";
  45. if (have_option('u') || have_option('--unsub')) {
  46. echo "Pinging hub {$sub->huburi} with unsubscription for {$sub->uri}\n";
  47. $sub->unsubscribe();
  48. } else {
  49. echo "Pinging hub {$sub->huburi} with new subscription for {$sub->uri}\n";
  50. $sub->subscribe();
  51. }
  52. echo "ok\n";
  53. } catch (Exception $e) {
  54. echo 'Could not confirm. '.get_class($e).': '.$e->getMessage()."\n";
  55. }
  56. $sub2 = FeedSub::getKV('uri', $feedurl);
  57. print "\n";
  58. print "New state:\n";
  59. showSub($sub2);
  60. function showSub($sub)
  61. {
  62. print " Subscription state: $sub->sub_state\n";
  63. print " Verify token: $sub->verify_token\n";
  64. print " Signature secret: $sub->secret\n";
  65. print " Sub start date: $sub->sub_start\n";
  66. print " Record created: $sub->created\n";
  67. print " Record modified: $sub->modified\n";
  68. }