diff --git a/i18n/en.json b/i18n/en.json index f77450b..bef6c73 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -29,6 +29,7 @@ "arg-files-desc": "Filenames of files to upload.", "ask-login-username": "Enter your bot username (e.g. YourName@mwcli):", "ask-login-password": "Enter your bot password:", + "files-missing": "Please provide the '...' argument (a list of files to upload).", "not-a-file": "Unable to upload non-file: $1", "option-comment-desc": "Revision comment.", "file-exists": "File already exists: $1", diff --git a/src/Command/UploadFilesCommand.php b/src/Command/UploadFilesCommand.php index bc26ccb..b1199b2 100644 --- a/src/Command/UploadFilesCommand.php +++ b/src/Command/UploadFilesCommand.php @@ -2,6 +2,7 @@ namespace Samwilson\MediaWikiCLI\Command; +use Addwiki\Mediawiki\Api\Client\Action\Exception\UsageException; use Addwiki\Mediawiki\Api\Client\Action\Request\ActionRequest; use Addwiki\Mediawiki\Api\Service\FileUploader; use Symfony\Component\Console\Command\Command; @@ -74,9 +75,17 @@ public function execute( InputInterface $input, OutputInterface $output ) { // Upload. $pageText = ''; $comment = $input->getOption( 'comment' ); - $uploaded = $uploader->upload( $fileTitle, $file, $pageText, $comment ); + try { + $uploaded = $uploader->upload( $fileTitle, $file, $pageText, $comment ); + } catch ( UsageException $e ) { + $this->io->error( 'Unable to upload ' . $filePath ); + throw $e; + } if ( $uploaded ) { $this->io->success( $this->msg( 'file-uploaded-successfully', [ $filenameExistsInfo['canonicalurl'] ] ) ); + } else { + // @todo After https://github.com/addwiki/addwiki/issues/86 is fixed, report actual issue. + $this->io->error( 'Unable to upload ' . $filePath ); } } return Command::SUCCESS; diff --git a/src/Command/UploadPagesCommand.php b/src/Command/UploadPagesCommand.php index 8d10640..2dbca1e 100644 --- a/src/Command/UploadPagesCommand.php +++ b/src/Command/UploadPagesCommand.php @@ -105,7 +105,8 @@ public function execute( InputInterface $input, OutputInterface $output ) { public function import( $dir ) { $topLevel = new DirectoryIterator( $dir ); foreach ( $topLevel as $file ) { - if ( $file->isDot() ) { + if ( $file->isDot() || str_starts_with( $file->getFilename(), '.' ) ) { + $this->io->writeln( 'Ignoring ' . $file->getPathname() ); continue; } if ( $file->isDir() ) { @@ -155,9 +156,8 @@ protected function importPage( $filename ) { try { $result = $this->api->request( ActionRequest::simplePost( 'edit', $editParams ) ); } catch ( Exception $exception ) { - // Show the error, but carry on with other pages. - $this->io->error( $pageTitle . ' ' . $exception->getMessage() ); - return; + $this->io->error( "Failed to upload $filename to $pageTitle" ); + throw $exception; } if ( $result['edit']['result'] !== 'Success' ) { $this->io->warning( $result['edit']['result'] );