ImportImages: Exit with non-zero code if import fails

When scripting, folks generally check the exit code of a program to be
zero if it is successful, and non-zero if it isn't. Since importImages
can be used in third-party scripts to automate wiki imports, it is
paramount that import failures are detected.

However, since it doesn't exit with a failure code (i.e. a non-zero
exit code) when a file fails to import or when there are no files
found, it is much more difficult to detect import failures.

Therefore, we exit with a non-zero return code to make import failures
much more easier to detect for scripts.

Bug: T388296
Change-Id: I5d9ede123355d63267793133287253a86faecda5
(cherry picked from commit 5a7c5491775ebf97f60fc7067d3d41c609358534)
This commit is contained in:
BlankEclair 2025-03-08 16:58:44 +11:00
parent 332d1dfd83
commit 4990c51d62

View file

@ -168,7 +168,7 @@ class ImportImages extends Maintenance {
$files = $this->findFiles( $dir, $extensions, $this->hasOption( 'search-recursively' ) );
if ( !$files->valid() ) {
$this->output( "No suitable files could be found for import.\n" );
return;
return false;
}
# Initialise the user for this operation
@ -428,6 +428,10 @@ class ImportImages extends Maintenance {
$this->output( ucfirst( $desc ) . ": $number\n" );
}
}
// Return true if there are no failed imports (= zero exit code), or
// return false if there are any failed imports (= non-zero exit code)
return $statistics['failed'] === 0;
}
/**