MediaWiki  REL1_22
deleteImageMemcached.php
Go to the documentation of this file.
00001 <?php
00027 require_once __DIR__ . '/Maintenance.php';
00028 
00034 class DeleteImageCache extends Maintenance {
00035     public function __construct() {
00036         parent::__construct();
00037         $this->mDescription = "Delete image information from the cache";
00038         $this->addOption( 'sleep', 'How many seconds to sleep between deletions', true, true );
00039         $this->addOption( 'until', 'Timestamp to delete all entries prior to', true, true );
00040     }
00041 
00042     public function execute() {
00043         global $wgMemc;
00044 
00045         $until = preg_replace( "/[^\d]/", '', $this->getOption( 'until' ) );
00046         $sleep = (int)$this->getOption( 'sleep' ) * 1000; // milliseconds
00047 
00048         ini_set( 'display_errors', false );
00049 
00050         $dbr = wfGetDB( DB_SLAVE );
00051 
00052         $res = $dbr->select( 'image',
00053             array( 'img_name' ),
00054             array( "img_timestamp < {$until}" ),
00055             __METHOD__
00056         );
00057 
00058         $i = 0;
00059         $total = $this->getImageCount();
00060 
00061         foreach ( $res as $row ) {
00062             if ( $i % $this->report == 0 ) {
00063                 $this->output( sprintf( "%s: %13s done (%s)\n", wfWikiID(), "$i/$total", wfPercent( $i / $total * 100 ) ) );
00064             }
00065             $md5 = md5( $row->img_name );
00066             $wgMemc->delete( wfMemcKey( 'Image', $md5 ) );
00067 
00068             if ( $sleep != 0 ) {
00069                 usleep( $sleep );
00070             }
00071 
00072             ++$i;
00073         }
00074     }
00075 
00076     private function getImageCount() {
00077         $dbr = wfGetDB( DB_SLAVE );
00078         return $dbr->selectField( 'image', 'COUNT(*)', array(), __METHOD__ );
00079     }
00080 }
00081 
00082 $maintClass = "DeleteImageCache";
00083 require_once RUN_MAINTENANCE_IF_MAIN;