cleanupchannels.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * Script to print out current version of the software
  19. *
  20. * @package Realtime
  21. * @author Mikael Nordfeldth <mmn@hethane.se>
  22. * @copyright 2011-2019 Free Software Foundation, Inc http://www.fsf.org
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. define('INSTALLDIR', dirname(__DIR__, 3));
  26. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  27. $shortoptions = 'u';
  28. $longoptions = ['universe'];
  29. $helptext = <<<END_OF_CLEANUPCHANNELS_HELP
  30. cleanupchannels.php [options]
  31. Garbage-collects old realtime channels
  32. -u --universe Do all sites
  33. END_OF_CLEANUPCHANNELS_HELP;
  34. require_once INSTALLDIR.'/scripts/commandline.inc';
  35. function cleanupChannels()
  36. {
  37. $rc = new Realtime_channel();
  38. $rc->selectAdd();
  39. $rc->selectAdd('channel_key');
  40. $rc->whereAdd(sprintf("modified < TIMESTAMP '%s'", common_sql_date(time() - Realtime_channel::TIMEOUT)));
  41. if ($rc->find()) {
  42. $keys = $rc->fetchAll();
  43. foreach ($keys as $key) {
  44. $rc = Realtime_channel::getKV('channel_key', $key);
  45. if (!empty($rc)) {
  46. printfv("Deleting realtime channel '$key'\n");
  47. $rc->delete();
  48. }
  49. }
  50. }
  51. }
  52. if (have_option('u', 'universe')) {
  53. $sn = new Status_network();
  54. if ($sn->find()) {
  55. while ($sn->fetch()) {
  56. $server = $sn->getServerName();
  57. GNUsocial::init($server);
  58. cleanupChannels();
  59. }
  60. }
  61. } else {
  62. cleanupChannels();
  63. }