3 * This script delete image information from memcached.
6 * php deleteImageMemcached.php --until "2005-09-05 00:00:00" --sleep 0 --report 10
12 $optionsWithArgs = array( 'until', 'sleep', 'report' );
14 require_once 'commandLine.inc';
17 * @ingroup Maintenance
19 class DeleteImageCache
{
20 var $until, $sleep, $report;
22 function DeleteImageCache( $until, $sleep, $report ) {
23 $this->until
= $until;
24 $this->sleep
= $sleep;
25 $this->report
= $report;
30 $fname = 'DeleteImageCache::main';
32 ini_set( 'display_errors', false );
34 $dbr = wfGetDB( DB_SLAVE
);
36 $res = $dbr->select( 'image',
38 array( "img_timestamp < {$this->until}" ),
43 $total = $this->getImageCount();
45 while ( $row = $dbr->fetchObject( $res ) ) {
46 if ($i %
$this->report
== 0)
47 printf("%s: %13s done (%s)\n", wfWikiID(), "$i/$total", wfPercent( $i / $total * 100 ));
48 $md5 = md5( $row->img_name
);
49 $wgMemc->delete( wfMemcKey( 'Image', $md5 ) );
51 if ($this->sleep
!= 0)
52 usleep( $this->sleep
);
58 function getImageCount() {
59 $fname = 'DeleteImageCache::getImageCount';
61 $dbr = wfGetDB( DB_SLAVE
);
62 return $dbr->selectField( 'image', 'COUNT(*)', array(), $fname );
66 $until = preg_replace( "/[^\d]/", '', $options['until'] );
67 $sleep = (int)$options['sleep'] * 1000; // milliseconds
68 $report = (int)$options['report'];
70 $dic = new DeleteImageCache( $until, $sleep, $report );