123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
- $shortoptions = 'u';
- $longoptions = array('universe');
- $helptext = <<<END_OF_CLEANUPCHANNELS_HELP
- cleanupchannels.php [options]
- Garbage-collects old realtime channels
- -u --universe Do all sites
- END_OF_CLEANUPCHANNELS_HELP;
- require_once INSTALLDIR.'/scripts/commandline.inc';
- function cleanupChannels()
- {
- $rc = new Realtime_channel();
- $rc->selectAdd();
- $rc->selectAdd('channel_key');
- $rc->whereAdd('modified < "' . common_sql_date(time() - Realtime_channel::TIMEOUT) . '"');
- if ($rc->find()) {
- $keys = $rc->fetchAll();
- foreach ($keys as $key) {
- $rc = Realtime_channel::getKV('channel_key', $key);
- if (!empty($rc)) {
- printfv("Deleting realtime channel '$key'\n");
- $rc->delete();
- }
- }
- }
- }
- if (have_option('u', 'universe')) {
- $sn = new Status_network();
- if ($sn->find()) {
- while ($sn->fetch()) {
- $server = $sn->getServerName();
- StatusNet::init($server);
- cleanupChannels();
- }
- }
- } else {
- cleanupChannels();
- }
|