Follow-up to r51279
[lhc/web/wiklou.git] / maintenance / checkImages.php
1 <?php
2
3 require( 'commandLine.inc' );
4
5 $batchSize = 1000;
6 $start = '';
7 $dbr = wfGetDB( DB_SLAVE );
8 $localRepo = RepoGroup::singleton()->getLocalRepo();
9
10 $numImages = 0;
11 $numGood = 0;
12
13 do {
14 $res = $dbr->select( 'image', '*', array( 'img_name > ' . $dbr->addQuotes( $start ) ),
15 'checkImages.php', array( 'LIMIT' => $batchSize ) );
16 foreach ( $res as $row ) {
17 $numImages++;
18 $start = $row->img_name;
19 $file = $localRepo->newFileFromRow( $row );
20 $path = $file->getPath();
21 if ( !$path ) {
22 echo "{$row->img_name}: not locally accessible\n";
23 continue;
24 }
25 $stat = @stat( $file->getPath() );
26 if ( !$stat ) {
27 echo "{$row->img_name}: missing\n";
28 continue;
29 }
30
31 if ( $stat['mode'] & 040000 ) {
32 echo "{$row->img_name}: is a directory\n";
33 continue;
34 }
35
36 if ( $stat['size'] == 0 && $row->img_size != 0 ) {
37 echo "{$row->img_name}: truncated, was {$row->img_size}\n";
38 continue;
39 }
40
41 if ( $stat['size'] != $row->img_size ) {
42 echo "{$row->img_name}: size mismatch DB={$row->img_size}, actual={$stat['size']}\n";
43 continue;
44 }
45
46 $numGood++;
47 }
48
49 } while ( $res->numRows() );
50
51 echo "Good images: $numGood/$numImages\n";