Merge "Language: s/error_log/wfWarn/"
[lhc/web/wiklou.git] / maintenance / findMissingFiles.php
index 4bb9dc7..5f9f643 100644 (file)
@@ -42,26 +42,29 @@ class FindMissingFiles extends Maintenance {
                $mtime1 = $dbr->timestampOrNull( $this->getOption( 'mtimeafter', null ) );
                $mtime2 = $dbr->timestampOrNull( $this->getOption( 'mtimebefore', null ) );
 
-               $tables = array( 'image' );
-               $logJoinOn = array( 'log_namespace' => NS_FILE, 'log_title = img_name' );
-               $logJoinOn['log_type'] = array( 'upload', 'move', 'delete' );
-               if ( $mtime1 ) {
-                       $logJoinOn[] = "log_timestamp > {$dbr->addQuotes($mtime1)}";
-               }
-               if ( $mtime2 ) {
-                       $logJoinOn[] = "log_timestamp < {$dbr->addQuotes($mtime2)}";
-               }
+               $joinTables = array( 'image' );
+               $joinConds = array( 'image' => array( 'INNER JOIN', 'img_name = page_title' ) );
                if ( $mtime1 || $mtime2 ) {
-                       $tables[] = 'logging';
+                       $joinTables[] = 'logging';
+                       $on = array( 'log_page = page_id', 'log_type' => array( 'upload', 'move', 'delete' ) );
+                       if ( $mtime1 ) {
+                               $on[] = "log_timestamp > {$dbr->addQuotes($mtime1)}";
+                       }
+                       if ( $mtime2 ) {
+                               $on[] = "log_timestamp < {$dbr->addQuotes($mtime2)}";
+                       }
+                       $joinConds['logging'] = array( 'INNER JOIN', $on );
                }
 
                do {
-                       $res = $dbr->select( $tables,
-                               array( 'img_name' => 'DISTINCT(img_name)' ),
-                               array( "img_name >= " . $dbr->addQuotes( $lastName ) ),
+                       $res = $dbr->select(
+                               array_merge( array( 'page' ), $joinTables ),
+                               array( 'img_name' => 'DISTINCT(page_title)' ),
+                               array( 'page_namespace' => NS_FILE,
+                                       "page_title >= " . $dbr->addQuotes( $lastName ) ),
                                __METHOD__,
-                               array( 'ORDER BY' => 'img_name', 'LIMIT' => $this->mBatchSize ),
-                               array( 'logging' => array( 'INNER JOIN', $logJoinOn ) )
+                               array( 'ORDER BY' => 'page_title', 'LIMIT' => $this->mBatchSize ),
+                               $joinConds
                        );
 
                        // Check if any of these files are missing...
@@ -85,14 +88,22 @@ class FindMissingFiles extends Maintenance {
                                        array( 'oi_name' => array_keys( $pathsByName ) ),
                                        __METHOD__
                                );
+
+                               $checkPaths = array();
                                foreach ( $ores as $row ) {
                                        if ( !strlen( $row->oi_archive_name ) ) {
                                                continue; // broken row
                                        }
                                        $file = $repo->newFromArchiveName( $row->oi_name, $row->oi_archive_name );
-                                       $path = $file->getPath();
-                                       if ( $be->fileExists( array( 'src' => $path ) ) === false ) {
-                                               $this->output( "$path\n" );
+                                       $checkPaths[] = $file->getPath();
+                               }
+
+                               foreach ( array_chunk( $checkPaths, $this->mBatchSize ) as $paths ) {
+                                       $be->preloadFileStat( array( 'srcs' => $paths ) );
+                                       foreach ( $paths as $path ) {
+                                               if ( $be->fileExists( array( 'src' => $path ) ) === false ) {
+                                                       $this->output( "$path\n" );
+                                               }
                                        }
                                }
                        }