Localisation updates from http://translatewiki.net.
[mediawiki.git] / maintenance / deleteImageMemcached.php
blob835de352d239e7f7060db20c4c07774244f92e08
1 <?php
2 /**
3 * Delete image information from the object cache.
5 * Usage example:
6 * php deleteImageMemcached.php --until "2005-09-05 00:00:00" --sleep 0
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
23 * @file
24 * @ingroup Maintenance
27 require_once __DIR__ . '/Maintenance.php';
29 /**
30 * Maintenance script that deletes image information from the object cache.
32 * @ingroup Maintenance
34 class DeleteImageCache extends Maintenance {
35 public function __construct() {
36 parent::__construct();
37 $this->mDescription = "Delete image information from the cache";
38 $this->addOption( 'sleep', 'How many seconds to sleep between deletions', true, true );
39 $this->addOption( 'until', 'Timestamp to delete all entries prior to', true, true );
42 public function execute() {
43 global $wgMemc;
45 $until = preg_replace( "/[^\d]/", '', $this->getOption( 'until' ) );
46 $sleep = (int)$this->getOption( 'sleep' ) * 1000; // milliseconds
48 ini_set( 'display_errors', false );
50 $dbr = wfGetDB( DB_SLAVE );
52 $res = $dbr->select( 'image',
53 array( 'img_name' ),
54 array( "img_timestamp < {$until}" ),
55 __METHOD__
58 $i = 0;
59 $total = $this->getImageCount();
61 foreach ( $res as $row ) {
62 if ( $i % $this->report == 0 ) {
63 $this->output( sprintf( "%s: %13s done (%s)\n", wfWikiID(), "$i/$total", wfPercent( $i / $total * 100 ) ) );
65 $md5 = md5( $row->img_name );
66 $wgMemc->delete( wfMemcKey( 'Image', $md5 ) );
68 if ( $sleep != 0 ) {
69 usleep( $sleep );
72 ++$i;
76 private function getImageCount() {
77 $dbr = wfGetDB( DB_SLAVE );
78 return $dbr->selectField( 'image', 'COUNT(*)', array(), __METHOD__ );
82 $maintClass = "DeleteImageCache";
83 require_once RUN_MAINTENANCE_IF_MAIN;