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