13require_once __DIR__ .
'/Maintenance.php';
19 parent::__construct();
21 $this->
addDescription(
"Find unregistered files in the 'public' repo zone." );
23 'Only scan files in this subdirectory (e.g. "a/a0")',
false,
true );
24 $this->
addOption(
'verbose',
"Mention file paths checked" );
29 $subdir = $this->
getOption(
'subdir',
'' );
33 if ( $repo->hasSha1Storage() ) {
34 $this->
fatalError(
"Local repo uses SHA-1 file storage names; aborting." );
37 $directory = $repo->getZonePath(
'public' );
38 if ( $subdir !=
'' ) {
39 $directory .=
"/$subdir/";
43 $this->
output(
"Scanning files under $directory:\n" );
46 $list = $repo->getBackend()->getFileList( [
'dir' => $directory ] );
47 if ( $list ===
null ) {
48 $this->
fatalError(
"Could not get file listing." );
52 foreach ( $list as
$path ) {
53 if ( preg_match(
'#^(thumb|deleted)/#',
$path ) ) {
59 $this->
checkFiles( $repo, $pathBatch, $verbose );
63 $this->
checkFiles( $repo, $pathBatch, $verbose );
67 if ( !count( $paths ) ) {
77 foreach ( $paths as
$path ) {
78 $name = basename(
$path );
79 if ( preg_match(
'#^archive/#',
$path ) ) {
81 $this->
output(
"Checking old file $name\n" );
85 [ , $base ] = explode(
'!', $name, 2 );
86 $oiWheres[] = $dbr->expr(
'oi_name',
'=', $base )->and(
'oi_archive_name',
'=', $name );
89 $this->
output(
"Checking current file $name\n" );
97 $res1 = FileSelectQueryBuilder::newForFile( $dbr )
98 ->where( $imgIN ? [
'img_name' => $imgIN ] :
'1=0' )
99 ->caller( __METHOD__ )
101 $res2 = FileSelectQueryBuilder::newForOldFile( $dbr )
102 ->where( $oiWheres ? $dbr->orExpr( $oiWheres ) :
'1=0' )
103 ->caller( __METHOD__ )
109 foreach ( $res1 as $row ) {
110 $curNamesFound[] = $row->img_name;
112 foreach ( $res2 as $row ) {
113 $oldNamesFound[] = $row->oi_name;
116 foreach ( array_diff( $curNames, $curNamesFound ) as $name ) {
117 $file = $repo->
newFile( $name );
120 $this->
output( $name .
"\n" . $file->getCanonicalUrl() .
"\n\n" );
122 $this->
error(
"Cannot get URL for bad file title '$name'" );
126 foreach ( array_diff( $oldNames, $oldNamesFound ) as $name ) {
127 [ , $base ] = explode(
'!', $name, 2 );
130 $this->
output( $name .
"\n" . $file->getCanonicalUrl() .
"\n\n" );
137require_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.