* Updates to Dutch (nl) translations
[mediawiki.git] / maintenance / deleteImageMemcached.php
blob7ec9953c58e283df5e5d3b07e28ef4091388c801
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;
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", wfWikiID(), "$i/$total", wfPercent( $i / $total * 100 ));
36 $md5 = md5( $row->img_name );
37 $wgMemc->delete( wfMemcKey( '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();