23 require_once __DIR__ .
'/Maintenance.php';
27 parent::__construct();
29 $this->
addDescription(
'Find registered files with no corresponding file.' );
30 $this->
addOption(
'start',
'Start after this file name',
false,
true );
31 $this->
addOption(
'mtimeafter',
'Only include files changed since this time',
false,
true );
32 $this->
addOption(
'mtimebefore',
'Only includes files changed before this time',
false,
true );
37 $lastName = $this->
getOption(
'start',
'' );
39 $repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
40 $dbr = $repo->getReplicaDB();
41 $be = $repo->getBackend();
44 $mtime1 =
$dbr->timestampOrNull( $this->
getOption(
'mtimeafter',
null ) );
45 $mtime2 =
$dbr->timestampOrNull( $this->
getOption(
'mtimebefore',
null ) );
49 if ( $mtime1 || $mtime2 ) {
50 $joinTables[] =
'page';
51 $joinConds[
'page'] = [
'JOIN',
52 [
'page_title = img_name',
'page_namespace' =>
NS_FILE ] ];
53 $joinTables[] =
'logging';
54 $on = [
'log_page = page_id',
'log_type' => [
'upload',
'move',
'delete' ] ];
56 $on[] =
"log_timestamp > {$dbr->addQuotes($mtime1)}";
59 $on[] =
"log_timestamp < {$dbr->addQuotes($mtime2)}";
61 $joinConds[
'logging'] = [
'JOIN', $on ];
66 array_merge( [
'image' ], $joinTables ),
67 [
'name' =>
'img_name' ],
68 [
"img_name > " .
$dbr->addQuotes( $lastName ) ],
71 [
'ORDER BY' =>
'name',
'GROUP BY' =>
'name',
72 'LIMIT' => $batchSize ],
78 foreach (
$res as $row ) {
79 $file = $repo->newFile( $row->name );
80 $pathsByName[$row->name] =
$file->getPath();
81 $lastName = $row->name;
83 $be->preloadFileStat( [
'srcs' => $pathsByName ] );
84 foreach ( $pathsByName as
$path ) {
85 if ( $be->fileExists( [
'src' =>
$path ] ) ===
false ) {
86 $this->
output(
"$path\n" );
91 if ( count( $pathsByName ) ) {
92 $ores =
$dbr->select(
'oldimage',
93 [
'oi_name',
'oi_archive_name' ],
94 [
'oi_name' => array_map(
'strval', array_keys( $pathsByName ) ) ],
99 foreach ( $ores as $row ) {
100 if ( !strlen( $row->oi_archive_name ) ) {
104 $file = $repo->newFromArchiveName( $row->oi_name, $row->oi_archive_name );
105 $checkPaths[] =
$file->getPath();
108 foreach ( array_chunk( $checkPaths, $batchSize ) as $paths ) {
109 $be->preloadFileStat( [
'srcs' => $paths ] );
110 foreach ( $paths as
$path ) {
111 if ( $be->fileExists( [
'src' =>
$path ] ) ===
false ) {
112 $this->
output(
"$path\n" );
117 }
while (
$res->numRows() >= $batchSize );
122 require_once RUN_MAINTENANCE_IF_MAIN;
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.