[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/maintenance/ -> deleteImageMemcached.php (source)

   1  <?php
   2  /**
   3   * Delete image information from the object cache.
   4   *
   5   * Usage example:
   6   * php deleteImageMemcached.php --until "2005-09-05 00:00:00" --sleep 0
   7   *
   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.
  12   *
  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.
  17   *
  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
  22   *
  23   * @file
  24   * @ingroup Maintenance
  25   */
  26  
  27  require_once  __DIR__ . '/Maintenance.php';
  28  
  29  /**
  30   * Maintenance script that deletes image information from the object cache.
  31   *
  32   * @ingroup Maintenance
  33   */
  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 );
  40      }
  41  
  42  	public function execute() {
  43          global $wgMemc;
  44  
  45          $until = preg_replace( "/[^\d]/", '', $this->getOption( 'until' ) );
  46          $sleep = (int)$this->getOption( 'sleep' ) * 1000; // milliseconds
  47  
  48          ini_set( 'display_errors', false );
  49  
  50          $dbr = wfGetDB( DB_SLAVE );
  51  
  52          $res = $dbr->select( 'image',
  53              array( 'img_name' ),
  54              array( "img_timestamp < {$until}" ),
  55              __METHOD__
  56          );
  57  
  58          $i = 0;
  59          $total = $this->getImageCount();
  60  
  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                  ) );
  69              }
  70              $md5 = md5( $row->img_name );
  71              $wgMemc->delete( wfMemcKey( 'Image', $md5 ) );
  72  
  73              if ( $sleep != 0 ) {
  74                  usleep( $sleep );
  75              }
  76  
  77              ++$i;
  78          }
  79      }
  80  
  81  	private function getImageCount() {
  82          $dbr = wfGetDB( DB_SLAVE );
  83  
  84          return $dbr->selectField( 'image', 'COUNT(*)', array(), __METHOD__ );
  85      }
  86  }
  87  
  88  $maintClass = "DeleteImageCache";
  89  require_once RUN_MAINTENANCE_IF_MAIN;


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1