Merge "Follow-up I0b781c11 (2a55449): use User::getAutomaticGroups()."
[lhc/web/wiklou.git] / maintenance / purgeStaleMemcachedText.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Maintenance Memcached
20 */
21
22 require_once( __DIR__ . '/commandLine.inc' );
23
24 function purgeStaleMemcachedText() {
25 global $wgMemc, $wgDBname;
26 $db = wfGetDB( DB_MASTER );
27 $maxTextId = $db->selectField( 'text', 'max(old_id)' );
28 $latestReplicatedTextId = $db->selectField( array( 'recentchanges', 'revision' ), 'rev_text_id',
29 array( 'rev_id = rc_this_oldid', "rc_timestamp < '20101225183000'"), 'purgeStaleMemcachedText',
30 array( 'ORDER BY' => 'rc_timestamp DESC' ) );
31 $latestReplicatedTextId -= 100; # A bit of paranoia
32
33 echo "Going to purge text entries from $latestReplicatedTextId to $maxTextId in $wgDBname\n";
34
35 for ( $i = $latestReplicatedTextId; $i < $maxTextId; $i++ ) {
36 $key = wfMemcKey( 'revisiontext', 'textid', $i );
37
38 while (1) {
39 if (! $wgMemc->delete( $key ) ) {
40 echo "Memcache delete for $key returned false\n";
41 }
42 if ( $wgMemc->get( $key ) ) {
43 echo "There's still content in $key!\n";
44 } else {
45 break;
46 }
47 }
48
49 }
50 }
51
52 purgeStaleMemcachedText();
53