diff options
author | BlankEclair <blankeclair@disroot.org> | 2025-03-08 16:58:44 +1100 |
---|---|---|
committer | BlankEclair <blankeclair@disroot.org> | 2025-03-08 17:32:58 +1100 |
commit | 5a7c5491775ebf97f60fc7067d3d41c609358534 (patch) | |
tree | 0edb49ef38c8151ecbe8315e2fa4e3c0bf852254 /maintenance | |
parent | 1103f2b18aaa14050cdd9602daf21569fb9a4636 (diff) | |
download | mediawikicore-5a7c5491775ebf97f60fc7067d3d41c609358534.tar.gz mediawikicore-5a7c5491775ebf97f60fc7067d3d41c609358534.zip |
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
Diffstat (limited to 'maintenance')
-rw-r--r-- | maintenance/importImages.php | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/maintenance/importImages.php b/maintenance/importImages.php index ea0d7dc78960..86105b2752e3 100644 --- a/maintenance/importImages.php +++ b/maintenance/importImages.php @@ -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; } /** |