$this->mDescription = 'Find registered files with no corresponding file.';
$this->addOption( 'start', 'Starting file name', false, true );
- $this->setBatchSize( 200 );
+ $this->addOption( 'mtimeafter', 'Only include files changed since this time', false, true );
+ $this->addOption( 'mtimebefore', 'Only includes files changed before this time', false, true );
+ $this->setBatchSize( 300 );
}
function execute() {
$dbr = $repo->getSlaveDB();
$be = $repo->getBackend();
+ $mtime1 = $dbr->timestampOrNull( $this->getOption( 'mtimeafter', null ) );
+ $mtime2 = $dbr->timestampOrNull( $this->getOption( 'mtimebefore', null ) );
+
+ $joinTables = array( 'image' );
+ $joinConds = array( 'image' => array( 'INNER JOIN', 'img_name = page_title' ) );
+ if ( $mtime1 || $mtime2 ) {
+ $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( 'image',
- '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( 'ORDER BY' => 'page_title', 'LIMIT' => $this->mBatchSize ),
+ $joinConds
);
// Check if any of these files are missing...
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" );
+ }
}
}
}