cleanupchannels.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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, StatusNet, Inc.
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. define('INSTALLDIR', realpath(__DIR__ . '/../../..'));
  26. $shortoptions = 'u';
  27. $longoptions = array('universe');
  28. $helptext = <<<END_OF_CLEANUPCHANNELS_HELP
  29. cleanupchannels.php [options]
  30. Garbage-collects old realtime channels
  31. -u --universe Do all sites
  32. END_OF_CLEANUPCHANNELS_HELP;
  33. require_once INSTALLDIR.'/scripts/commandline.inc';
  34. function cleanupChannels()
  35. {
  36. $rc = new Realtime_channel();
  37. $rc->selectAdd();
  38. $rc->selectAdd('channel_key');
  39. $rc->whereAdd(sprintf("modified < TIMESTAMP '%s'", common_sql_date(time() - Realtime_channel::TIMEOUT)));
  40. if ($rc->find()) {
  41. $keys = $rc->fetchAll();
  42. foreach ($keys as $key) {
  43. $rc = Realtime_channel::getKV('channel_key', $key);
  44. if (!empty($rc)) {
  45. printfv("Deleting realtime channel '$key'\n");
  46. $rc->delete();
  47. }
  48. }
  49. }
  50. }
  51. if (have_option('u', 'universe')) {
  52. $sn = new Status_network();
  53. if ($sn->find()) {
  54. while ($sn->fetch()) {
  55. $server = $sn->getServerName();
  56. GNUsocial::init($server);
  57. cleanupChannels();
  58. }
  59. }
  60. } else {
  61. cleanupChannels();
  62. }