* Use double quoted consistently on attributes in linker output; preparing for new...
[mediawiki.git] / maintenance / deleteImageMemcached.php
blob4e17d21eba5aaead57da34a0c0c705a3f6ebd4b9
1 <?php
2 // php deleteImageMemcached.php --until "2005-09-05 00:00:00" --sleep 0 --report 10
3 $optionsWithArgs = array( 'until', 'sleep', 'report' );
5 require_once 'commandLine.inc';
7 class DeleteImageCache {
8 var $until, $sleep, $report;
10 function DeleteImageCache( $until, $sleep, $report ) {
11 $this->until = $until;
12 $this->sleep = $sleep;
13 $this->report = $report;
16 function main() {
17 global $wgMemc, $wgDBname;
18 $fname = 'DeleteImageCache::main';
20 ini_set( 'display_errors', false );
22 $dbr =& wfGetDB( DB_SLAVE );
24 $res = $dbr->select( 'image',
25 array( 'img_name' ),
26 array( "img_timestamp < {$this->until}" ),
27 $fname
30 $i = 0;
31 $total = $this->getImageCount();
33 while ( $row = $dbr->fetchObject( $res ) ) {
34 if ($i % $this->report == 0)
35 printf("%s: %13s done (%s)\n", $wgDBname, "$i/$total", wfPercent( $i / $total * 100 ));
36 $md5 = md5( $row->img_name );
37 $wgMemc->delete( "$wgDBname:Image:$md5" );
39 if ($this->sleep != 0)
40 usleep( $this->sleep );
42 ++$i;
46 function getImageCount() {
47 $fname = 'DeleteImageCache::getImageCount';
49 $dbr =& wfGetDB( DB_SLAVE );
50 return $dbr->selectField( 'image', 'COUNT(*)', array(), $fname );
54 $until = preg_replace( "/[^\d]/", '', $options['until'] );
55 $sleep = (int)$options['sleep'] * 1000; // milliseconds
56 $report = (int)$options['report'];
58 $dic = new DeleteImageCache( $until, $sleep, $report );
59 $dic->main();