X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=maintenance%2FcheckImages.php;h=484217d972f254397fccc15dc7f72ccee9b778bb;hb=fc7532449dfa54077c1698e0f34a2738fa336c26;hp=994cd5b9f23163d2bfc1780c1bccea48ef1d6333;hpb=b63ea56e49373afaf3faa486229a71785ba917bc;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/checkImages.php b/maintenance/checkImages.php index 994cd5b9f2..484217d972 100644 --- a/maintenance/checkImages.php +++ b/maintenance/checkImages.php @@ -1,45 +1,85 @@ getLocalRepo(); - -$numImages = 0; -$numGood = 0; - -do { - $res = $dbr->select( 'image', '*', array( 'img_name > ' . $dbr->addQuotes( $start ) ) ); - foreach ( $res as $row ) { - $numImages++; - $start = $row->img_name; - $file = $localRepo->newFileFromRow( $row ); - $path = $file->getPath(); - if ( !$path ) { - echo "{$row->img_name}: not locally accessible\n"; - continue; - } - $stat = @stat( $file->getPath() ); - if ( !$stat ) { - echo "{$row->img_name}: missing\n"; - continue; - } - - if ( $stat['size'] == 0 && $row->img_size != 0 ) { - echo "{$row->img_name}: truncated, was {$row->img_size}\n"; - continue; - } - - if ( $stat['size'] != $row->img_size ) { - echo "{$row->img_name}: size mismatch DB={$row->img_size}, actual={$stat['size']}\n"; - continue; - } - - $numGood++; +class CheckImages extends Maintenance { + + public function __construct() { + parent::__construct(); + $this->mDescription = "Check images to see if they exist, are readable, etc"; + $this->setBatchSize( 1000 ); } -} while ( $res->numRows() ); + public function execute() { + $start = ''; + $dbr = wfGetDB( DB_SLAVE ); + + $numImages = 0; + $numGood = 0; + + do { + $res = $dbr->select( 'image', '*', array( 'img_name > ' . $dbr->addQuotes( $start ) ), + __METHOD__, array( 'LIMIT' => $this->mBatchSize ) ); + foreach ( $res as $row ) { + $numImages++; + $start = $row->img_name; + $file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row ); + $path = $file->getPath(); + if ( !$path ) { + $this->output( "{$row->img_name}: not locally accessible\n" ); + continue; + } + wfSuppressWarnings(); + $stat = stat( $file->getPath() ); + wfRestoreWarnings(); + if ( !$stat ) { + $this->output( "{$row->img_name}: missing\n" ); + continue; + } + + if ( $stat['mode'] & 040000 ) { + $this->output( "{$row->img_name}: is a directory\n" ); + continue; + } + + if ( $stat['size'] == 0 && $row->img_size != 0 ) { + $this->output( "{$row->img_name}: truncated, was {$row->img_size}\n" ); + continue; + } + + if ( $stat['size'] != $row->img_size ) { + $this->output( "{$row->img_name}: size mismatch DB={$row->img_size}, actual={$stat['size']}\n" ); + continue; + } + + $numGood++; + } + + } while ( $res->numRows() ); + + $this->output( "Good images: $numGood/$numImages\n" ); + } +} -echo "Good images: $numGood/$numImages\n"; +$maintClass = "CheckImages"; +require_once( RUN_MAINTENANCE_IF_MAIN );