rm_bad_feedsubs.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env php
  2. <?php
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. /**
  18. * @copyright 2010 StatusNet, Inc.
  19. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  20. */
  21. /*
  22. * Run this from INSTALLDIR/plugins/OStatus/scripts
  23. */
  24. define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
  25. $shortoptions = 'd';
  26. $longoptions = array('dry-run');
  27. $helptext = <<<END_OF_HELP
  28. rm_bad_feedsubs.php [options]
  29. Deletes feedsub records that are in the inconsistent state of "subscribe"
  30. and are older than one hour. If the hub hasn't answered back in an hour
  31. the hub is probably either broken or doesn't exist.'
  32. Options:
  33. -d --dry-run look but don't mess with it
  34. END_OF_HELP;
  35. require_once INSTALLDIR . '/scripts/commandline.inc';
  36. $dry = false;
  37. if (have_option('d') || have_option('dry-run')) {
  38. $dry = true;
  39. }
  40. echo "Looking for feed subscriptions with dirty no good huburis...\n";
  41. $feedsub = new FeedSub();
  42. $feedsub->sub_state = 'subscribe';
  43. $feedsub->whereAdd("created < (CURRENT_TIMESTAMP - INTERVAL '1' HOUR)");
  44. $feedsub->find();
  45. $cnt = 0;
  46. while ($feedsub->fetch()) {
  47. echo "----------------------------------------------------------------------------------------\n";
  48. echo ' feed: '
  49. . $feedsub->uri . "\n"
  50. . ' hub uri: '
  51. . $feedsub->huburi ."\n"
  52. . ' subscribe date: '
  53. . date('r', strtotime($feedsub->created)) . "\n";
  54. if (!$dry) {
  55. $feedsub->delete();
  56. echo " (DELETED)\n";
  57. } else {
  58. echo " (WOULD BE DELETED)\n";
  59. }
  60. echo "----------------------------------------------------------------------------------------\n";
  61. $cnt++;
  62. }
  63. if ($cnt == 0) {
  64. echo "None found.\n";
  65. } else {
  66. echo "Deleted $cnt bogus hub URIs.\n";
  67. }
  68. echo "Done.\n";