21 require_once __DIR__ .
'/Maintenance.php';
25 parent::__construct();
27 $this->
addDescription(
'Find registered files with no corresponding file.' );
28 $this->
addOption(
'start',
'Start after this file name',
false,
true );
29 $this->
addOption(
'mtimeafter',
'Only include files changed since this time',
false,
true );
30 $this->
addOption(
'mtimebefore',
'Only includes files changed before this time',
false,
true );
35 $lastName = $this->
getOption(
'start',
'' );
38 $dbr = $repo->getReplicaDB();
39 $be = $repo->getBackend();
42 $mtime1 =
$dbr->timestampOrNull( $this->
getOption(
'mtimeafter', null ) );
43 $mtime2 =
$dbr->timestampOrNull( $this->
getOption(
'mtimebefore', null ) );
47 if ( $mtime1 || $mtime2 ) {
48 $joinTables[] =
'page';
49 $joinConds[
'page'] = [
'JOIN',
50 [
'page_title = img_name',
'page_namespace' =>
NS_FILE ] ];
51 $joinTables[] =
'logging';
52 $on = [
'log_page = page_id',
'log_type' => [
'upload',
'move',
'delete' ] ];
54 $on[] =
"log_timestamp > {$dbr->addQuotes($mtime1)}";
57 $on[] =
"log_timestamp < {$dbr->addQuotes($mtime2)}";
59 $joinConds[
'logging'] = [
'JOIN', $on ];
64 array_merge( [
'image' ], $joinTables ),
65 [
'name' =>
'img_name' ],
66 [
"img_name > " .
$dbr->addQuotes( $lastName ) ],
69 [
'ORDER BY' =>
'name',
'GROUP BY' =>
'name',
70 'LIMIT' => $batchSize ],
76 foreach (
$res as $row ) {
77 $file = $repo->newFile( $row->name );
78 $pathsByName[$row->name] =
$file->getPath();
79 $lastName = $row->name;
81 $be->preloadFileStat( [
'srcs' => $pathsByName ] );
82 foreach ( $pathsByName as
$path ) {
83 if ( $be->fileExists( [
'src' => $path ] ) === false ) {
84 $this->
output(
"$path\n" );
89 if ( count( $pathsByName ) ) {
90 $ores =
$dbr->select(
'oldimage',
91 [
'oi_name',
'oi_archive_name' ],
92 [
'oi_name' => array_keys( $pathsByName ) ],
97 foreach ( $ores as $row ) {
98 if ( !strlen( $row->oi_archive_name ) ) {
101 $file = $repo->newFromArchiveName( $row->oi_name, $row->oi_archive_name );
102 $checkPaths[] =
$file->getPath();
105 foreach ( array_chunk( $checkPaths, $batchSize ) as $paths ) {
106 $be->preloadFileStat( [
'srcs' => $paths ] );
107 foreach ( $paths as $path ) {
108 if ( $be->fileExists( [
'src' => $path ] ) === false ) {
109 $this->
output(
"$path\n" );
114 }
while (
$res->numRows() >= $batchSize );
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
const RUN_MAINTENANCE_IF_MAIN
getOption( $name, $default=null)
Get an option, or return the default.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
setBatchSize( $s=0)
Set the batch size.
addDescription( $text)
Set the description text.
output( $out, $channel=null)
Throw some output to the user.
getBatchSize()
Returns batch size.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.