39 $subdir = $this->getOption(
'subdir',
'' );
40 $verbose = $this->hasOption(
'verbose' );
42 $repo = $this->getServiceContainer()->getRepoGroup()->getLocalRepo();
43 if ( $repo->hasSha1Storage() ) {
44 $this->fatalError(
"Local repo uses SHA-1 file storage names; aborting." );
47 $directory = $repo->getZonePath(
'public' );
48 if ( $subdir !=
'' ) {
49 $directory .=
"/$subdir/";
53 $this->output(
"Scanning files under $directory:\n" );
56 $list = $repo->getBackend()->getFileList( [
'dir' => $directory ] );
57 if ( $list ===
null ) {
58 $this->fatalError(
"Could not get file listing." );
62 foreach ( $list as
$path ) {
63 if ( preg_match(
'#^(thumb|deleted)/#',
$path ) ) {
68 if ( count( $pathBatch ) >= $this->getBatchSize() ) {
69 $this->
checkFiles( $repo, $pathBatch, $verbose );
73 $this->
checkFiles( $repo, $pathBatch, $verbose );
77 if ( !count( $paths ) ) {
87 foreach ( $paths as
$path ) {
88 $name = basename(
$path );
89 if ( preg_match(
'#^archive/#',
$path ) ) {
91 $this->output(
"Checking old file $name\n" );
95 [ , $base ] = explode(
'!', $name, 2 );
96 $oiWheres[] = $dbr->expr(
'oi_name',
'=', $base )->and(
'oi_archive_name',
'=', $name );
99 $this->output(
"Checking current file $name\n" );
106 $uqb = $dbr->newUnionQueryBuilder();
108 $dbr->newSelectQueryBuilder()
109 ->select( [
'name' =>
'img_name',
'old' =>
'0' ] )
111 ->where( $imgIN ? [
'img_name' => $imgIN ] :
'1=0' )
114 $dbr->newSelectQueryBuilder()
115 ->select( [
'name' =>
'oi_archive_name',
'old' =>
'1' ] )
117 ->where( $oiWheres ? $dbr->orExpr( $oiWheres ) :
'1=0' )
120 $res = $uqb->all()->caller( __METHOD__ )->fetchResultSet();
124 foreach ( $res as $row ) {
126 $oldNamesFound[] = $row->name;
128 $curNamesFound[] = $row->name;
132 foreach ( array_diff( $curNames, $curNamesFound ) as $name ) {
133 $file = $repo->
newFile( $name );
136 $this->output( $name .
"\n" . $file->getCanonicalUrl() .
"\n\n" );
138 $this->error(
"Cannot get URL for bad file title '$name'" );
142 foreach ( array_diff( $oldNames, $oldNamesFound ) as $name ) {
143 [ , $base ] = explode(
'!', $name, 2 );
146 $this->output( $name .
"\n" . $file->getCanonicalUrl() .
"\n\n" );