Abolished $wgDBname as a unique wiki identifier, it doesn't work with the new-fangled...
[lhc/web/wiklou.git] / maintenance / deleteImageMemcached.php
1 <?php
2 // php deleteImageMemcached.php --until "2005-09-05 00:00:00" --sleep 0 --report 10
3 $optionsWithArgs = array( 'until', 'sleep', 'report' );
4
5 require_once 'commandLine.inc';
6
7 class DeleteImageCache {
8 var $until, $sleep, $report;
9
10 function DeleteImageCache( $until, $sleep, $report ) {
11 $this->until = $until;
12 $this->sleep = $sleep;
13 $this->report = $report;
14 }
15
16 function main() {
17 global $wgMemc;
18 $fname = 'DeleteImageCache::main';
19
20 ini_set( 'display_errors', false );
21
22 $dbr =& wfGetDB( DB_SLAVE );
23
24 $res = $dbr->select( 'image',
25 array( 'img_name' ),
26 array( "img_timestamp < {$this->until}" ),
27 $fname
28 );
29
30 $i = 0;
31 $total = $this->getImageCount();
32
33 while ( $row = $dbr->fetchObject( $res ) ) {
34 if ($i % $this->report == 0)
35 printf("%s: %13s done (%s)\n", wfWikiID(), "$i/$total", wfPercent( $i / $total * 100 ));
36 $md5 = md5( $row->img_name );
37 $wgMemc->delete( wfMemcKey( 'Image', $md5 ) );
38
39 if ($this->sleep != 0)
40 usleep( $this->sleep );
41
42 ++$i;
43 }
44 }
45
46 function getImageCount() {
47 $fname = 'DeleteImageCache::getImageCount';
48
49 $dbr =& wfGetDB( DB_SLAVE );
50 return $dbr->selectField( 'image', 'COUNT(*)', array(), $fname );
51 }
52 }
53
54 $until = preg_replace( "/[^\d]/", '', $options['until'] );
55 $sleep = (int)$options['sleep'] * 1000; // milliseconds
56 $report = (int)$options['report'];
57
58 $dic = new DeleteImageCache( $until, $sleep, $report );
59 $dic->main();
60 ?>