26require_once __DIR__ .
'/Maintenance.php';
31 parent::__construct();
33 $this->
addDescription(
"Find unregistered files in the 'public' repo zone." );
35 'Only scan files in this subdirectory (e.g. "a/a0")',
false,
true );
36 $this->
addOption(
'verbose',
"Mention file paths checked" );
41 $subdir = $this->
getOption(
'subdir',
'' );
45 if ( $repo->hasSha1Storage() ) {
46 $this->
fatalError(
"Local repo uses SHA-1 file storage names; aborting." );
49 $directory = $repo->getZonePath(
'public' );
50 if ( $subdir !=
'' ) {
51 $directory .=
"/$subdir/";
55 $this->
output(
"Scanning files under $directory:\n" );
58 $list = $repo->getBackend()->getFileList( [
'dir' => $directory ] );
59 if ( $list ===
null ) {
60 $this->
fatalError(
"Could not get file listing." );
64 foreach ( $list as
$path ) {
65 if ( preg_match(
'#^(thumb|deleted)/#',
$path ) ) {
71 $this->
checkFiles( $repo, $pathBatch, $verbose );
75 $this->
checkFiles( $repo, $pathBatch, $verbose );
79 if ( !count( $paths ) ) {
89 foreach ( $paths as
$path ) {
90 $name = basename(
$path );
91 if ( preg_match(
'#^archive/#',
$path ) ) {
93 $this->
output(
"Checking old file $name\n" );
97 [ , $base ] = explode(
'!', $name, 2 );
98 $oiWheres[] = $dbr->expr(
'oi_name',
'=', $base )->and(
'oi_archive_name',
'=', $name );
101 $this->
output(
"Checking current file $name\n" );
108 $uqb = $dbr->newUnionQueryBuilder();
110 $dbr->newSelectQueryBuilder()
111 ->select( [
'name' =>
'img_name',
'old' =>
'0' ] )
113 ->where( $imgIN ? [
'img_name' => $imgIN ] :
'1=0' )
116 $dbr->newSelectQueryBuilder()
117 ->select( [
'name' =>
'oi_archive_name',
'old' =>
'1' ] )
119 ->where( $oiWheres ? $dbr->orExpr( $oiWheres ) :
'1=0' )
122 $res = $uqb->all()->caller( __METHOD__ )->fetchResultSet();
126 foreach ( $res as $row ) {
128 $oldNamesFound[] = $row->name;
130 $curNamesFound[] = $row->name;
134 foreach ( array_diff( $curNames, $curNamesFound ) as $name ) {
135 $file = $repo->
newFile( $name );
138 $this->
output( $name .
"\n" . $file->getCanonicalUrl() .
"\n\n" );
140 $this->
error(
"Cannot get URL for bad file title '$name'" );
144 foreach ( array_diff( $oldNames, $oldNamesFound ) as $name ) {
145 [ , $base ] = explode(
'!', $name, 2 );
148 $this->
output( $name .
"\n" . $file->getCanonicalUrl() .
"\n\n" );
155require_once RUN_MAINTENANCE_IF_MAIN;
execute()
Do the actual work.
__construct()
Default constructor.
checkFiles(LocalRepo $repo, array $paths, bool $verbose)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.