MediaWiki  REL1_21
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                         $md5 = md5( $row->img_name );
00065                         $wgMemc->delete( wfMemcKey( 'Image', $md5 ) );
00066 
00067                         if ( $sleep != 0 )
00068                                 usleep( $sleep );
00069 
00070                         ++$i;
00071                 }
00072         }
00073 
00074         private function getImageCount() {
00075                 $dbr = wfGetDB( DB_SLAVE );
00076                 return $dbr->selectField( 'image', 'COUNT(*)', array(), __METHOD__ );
00077         }
00078 }
00079 
00080 $maintClass = "DeleteImageCache";
00081 require_once( RUN_MAINTENANCE_IF_MAIN );