37 $lastName = $this->getOption(
'start',
'' );
39 $repo = $this->getServiceContainer()->getRepoGroup()->getLocalRepo();
40 $dbr = $repo->getReplicaDB();
41 $be = $repo->getBackend();
42 $batchSize = $this->getBatchSize();
44 $mtime1 = $dbr->timestampOrNull( $this->getOption(
'mtimeafter',
null ) );
45 $mtime2 = $dbr->timestampOrNull( $this->getOption(
'mtimebefore',
null ) );
47 $queryBuilder = $dbr->newSelectQueryBuilder()
48 ->select( [
'name' =>
'img_name' ] )
50 ->where( $dbr->expr(
'img_name',
'>', $lastName ) )
53 ->limit( $batchSize );
55 if ( $mtime1 || $mtime2 ) {
56 $queryBuilder->join(
'page',
null,
'page_title = img_name' );
57 $queryBuilder->andWhere( [
'page_namespace' =>
NS_FILE ] );
59 $queryBuilder->join(
'logging',
null,
'log_page = page_id' );
60 $queryBuilder->andWhere( [
'log_type' => [
'upload',
'move',
'delete' ] ] );
62 $queryBuilder->andWhere( $dbr->expr(
'log_timestamp',
'>', $mtime1 ) );
65 $queryBuilder->andWhere( $dbr->expr(
'log_timestamp',
'<', $mtime2 ) );
70 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
74 foreach ( $res as $row ) {
75 $file = $repo->newFile( $row->name );
76 $pathsByName[$row->name] = $file->getPath();
77 $lastName = $row->name;
79 $be->preloadFileStat( [
'srcs' => $pathsByName ] );
80 foreach ( $pathsByName as
$path ) {
81 if ( $be->fileExists( [
'src' =>
$path ] ) ===
false ) {
82 $this->output(
"$path\n" );
87 if ( count( $pathsByName ) ) {
88 $ores = $dbr->newSelectQueryBuilder()
89 ->select( [
'oi_name',
'oi_archive_name' ] )
91 ->where( [
'oi_name' => array_map(
'strval', array_keys( $pathsByName ) ) ] )
92 ->caller( __METHOD__ )->fetchResultSet();
95 foreach ( $ores as $row ) {
96 if ( !strlen( $row->oi_archive_name ) ) {
100 $file = $repo->newFromArchiveName( $row->oi_name, $row->oi_archive_name );
101 $checkPaths[] = $file->getPath();
104 foreach ( array_chunk( $checkPaths, $batchSize ) as $paths ) {
105 $be->preloadFileStat( [
'srcs' => $paths ] );
106 foreach ( $paths as
$path ) {
107 if ( $be->fileExists( [
'src' =>
$path ] ) ===
false ) {
108 $this->output(
"$path\n" );
113 }
while ( $res->numRows() >= $batchSize );