summaryrefslogtreecommitdiff
path: root/maintenance/deleteImageMemcached.php
blob: 6af0e3a9fa6136326af28e8358051b2cbe29b150 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
// php deleteImageMemcached.php --until "2005-09-05 00:00:00" --sleep 0 --report 10
$optionsWithArgs = array( 'until', 'sleep', 'report' );

require_once 'commandLine.inc';

class DeleteImageCache {
	var $until, $sleep, $report;

	function DeleteImageCache( $until, $sleep, $report ) {
		$this->until = $until;
		$this->sleep = $sleep;
		$this->report = $report;
	}

	function main() {
		global $wgMemc;
		$fname = 'DeleteImageCache::main';

		ini_set( 'display_errors', false );

		$dbr =& wfGetDB( DB_SLAVE );

		$res = $dbr->select( 'image',
			array( 'img_name' ),
			array( "img_timestamp < {$this->until}" ),
			$fname
		);

		$i = 0;
		$total = $this->getImageCount();

		while ( $row = $dbr->fetchObject( $res ) ) {
			if ($i % $this->report == 0)
				printf("%s: %13s done (%s)\n", wfWikiID(), "$i/$total", wfPercent( $i / $total * 100 ));
			$md5 = md5( $row->img_name );
			$wgMemc->delete( wfMemcKey( 'Image', $md5 ) );

			if ($this->sleep != 0)
				usleep( $this->sleep );

			++$i;
		}
	}

	function getImageCount() {
		$fname = 'DeleteImageCache::getImageCount';

		$dbr =& wfGetDB( DB_SLAVE );
		return $dbr->selectField( 'image', 'COUNT(*)', array(), $fname );
	}
}

$until = preg_replace( "/[^\d]/", '', $options['until'] );
$sleep = (int)$options['sleep'] * 1000; // milliseconds
$report = (int)$options['report'];

$dic = new DeleteImageCache( $until, $sleep, $report );
$dic->main();
?>