]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Realtime/scripts/cleanupchannels.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / Realtime / scripts / cleanupchannels.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - a distributed open-source microblogging tool
5  * Copyright (C) 2011, StatusNet, Inc.
6  *
7  * Script to print out current version of the software
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
24
25 $shortoptions = 'u';
26 $longoptions = array('universe');
27
28 $helptext = <<<END_OF_CLEANUPCHANNELS_HELP
29 cleanupchannels.php [options]
30 Garbage-collects old realtime channels
31
32 -u --universe Do all sites
33
34 END_OF_CLEANUPCHANNELS_HELP;
35
36 require_once INSTALLDIR.'/scripts/commandline.inc.php';
37
38 function cleanupChannels()
39 {
40     $rc = new Realtime_channel();
41
42     $rc->selectAdd();
43     $rc->selectAdd('channel_key');
44
45     $rc->whereAdd('modified < "' . common_sql_date(time() - Realtime_channel::TIMEOUT) . '"');
46
47     if ($rc->find()) {
48         $keys = $rc->fetchAll();
49
50         foreach ($keys as $key) {
51             $rc = Realtime_channel::getKV('channel_key', $key);
52             if (!empty($rc)) {
53                 printfv("Deleting realtime channel '$key'\n");
54                 $rc->delete();
55             }
56         }
57     }
58 }
59
60 if (have_option('u', 'universe')) {
61     $sn = new Status_network();
62     if ($sn->find()) {
63         while ($sn->fetch()) {
64             $server = $sn->getServerName();
65             GNUsocial::init($server);
66             cleanupChannels();
67         }
68     }
69 } else {
70     cleanupChannels();
71 }