rm_bad_feedsubs.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /*
  21. * Run this from INSTALLDIR/plugins/OStatus/scripts
  22. */
  23. define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
  24. $shortoptions = 'd';
  25. $longoptions = array('dry-run');
  26. $helptext = <<<END_OF_HELP
  27. rm_bad_feedsubs.php [options]
  28. Deletes feedsub records that are in the inconsistent state of "subscribe"
  29. and are older than one hour. If the hub hasn't answered back in an hour
  30. the hub is probably either broken or doesn't exist.'
  31. Options:
  32. -d --dry-run look but don't mess with it
  33. END_OF_HELP;
  34. require_once INSTALLDIR . '/scripts/commandline.inc';
  35. $dry = false;
  36. if (have_option('d') || have_option('dry-run')) {
  37. $dry = true;
  38. }
  39. echo "Looking for feed subscriptions with dirty no good huburis...\n";
  40. $feedsub = new FeedSub();
  41. $feedsub->sub_state = 'subscribe';
  42. $feedsub->whereAdd('created < DATE_SUB(NOW(), INTERVAL 1 HOUR)');
  43. $feedsub->find();
  44. $cnt = 0;
  45. while ($feedsub->fetch()) {
  46. echo "----------------------------------------------------------------------------------------\n";
  47. echo ' feed: '
  48. . $feedsub->uri . "\n"
  49. . ' hub uri: '
  50. . $feedsub->huburi ."\n"
  51. . ' subscribe date: '
  52. . date('r', strtotime($feedsub->created)) . "\n";
  53. if (!$dry) {
  54. $feedsub->delete();
  55. echo " (DELETED)\n";
  56. } else {
  57. echo " (WOULD BE DELETED)\n";
  58. }
  59. echo "----------------------------------------------------------------------------------------\n";
  60. $cnt++;
  61. }
  62. if ($cnt == 0) {
  63. echo "None found.\n";
  64. } else {
  65. echo "Deleted $cnt bogus hub URIs.\n";
  66. }
  67. echo "Done.\n";