Merge "Make update.php file executable"
[mediawiki.git] / maintenance / deleteImageMemcached.php
blob4799e5e0d7eeda584d5ce28f24cd4429fdf9b74a
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(
64 "%s: %13s done (%s)\n",
65 wfWikiID(),
66 "$i/$total",
67 wfPercent( $i / $total * 100 )
68 ) );
70 $md5 = md5( $row->img_name );
71 $wgMemc->delete( wfMemcKey( 'Image', $md5 ) );
73 if ( $sleep != 0 ) {
74 usleep( $sleep );
77 ++$i;
81 private function getImageCount() {
82 $dbr = wfGetDB( DB_SLAVE );
84 return $dbr->selectField( 'image', 'COUNT(*)', array(), __METHOD__ );
88 $maintClass = "DeleteImageCache";
89 require_once RUN_MAINTENANCE_IF_MAIN;