From bac772ae7ebdf0887365600145c24deea54a189d Mon Sep 17 00:00:00 2001 From: Rob Church Date: Tue, 5 Jun 2007 18:39:02 +0000 Subject: [PATCH] Don't bug out if no files were found --- maintenance/importImages.php | 66 +++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/maintenance/importImages.php b/maintenance/importImages.php index a3a8f83b28..5ec580a86a 100644 --- a/maintenance/importImages.php +++ b/maintenance/importImages.php @@ -43,38 +43,40 @@ if( count( $args ) > 1 ) { # Batch "upload" operation global $wgUploadDirectory; - foreach( $files as $file ) { - $base = wfBaseName( $file ); - - # Validate a title - $title = Title::makeTitleSafe( NS_IMAGE, $base ); - if( !is_object( $title ) ) { - echo( "{$base} could not be imported; a valid title cannot be produced\n" ); - continue; - } - - # Check existence - $image = wfLocalFile( $title ); - if( $image->exists() ) { - echo( "{$base} could not be imported; a file with this name exists in the wiki\n" ); - continue; - } - - # Stash the file - echo( "Saving {$base}..." ); - - $archive = $image->publish( $file ); - if ( WikiError::isError( $archive ) ) { - echo( "failed.\n" ); - continue; - } - echo( "importing..." ); - - if ( $image->recordUpload( $archive, $comment, $license ) ) { - # We're done! - echo( "done.\n" ); - } else { - echo( "failed.\n" ); + if( count( $files ) > 0 ) { + foreach( $files as $file ) { + $base = wfBaseName( $file ); + + # Validate a title + $title = Title::makeTitleSafe( NS_IMAGE, $base ); + if( !is_object( $title ) ) { + echo( "{$base} could not be imported; a valid title cannot be produced\n" ); + continue; + } + + # Check existence + $image = wfLocalFile( $title ); + if( $image->exists() ) { + echo( "{$base} could not be imported; a file with this name exists in the wiki\n" ); + continue; + } + + # Stash the file + echo( "Saving {$base}..." ); + + $archive = $image->publish( $file ); + if ( WikiError::isError( $archive ) ) { + echo( "failed.\n" ); + continue; + } + echo( "importing..." ); + + if ( $image->recordUpload( $archive, $comment, $license ) ) { + # We're done! + echo( "done.\n" ); + } else { + echo( "failed.\n" ); + } } } -- 2.20.1