Skip to content
This repository has been archived by the owner on Jan 28, 2025. It is now read-only.

Improvements to upload commands #244

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<files>...' 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",
Expand Down
11 changes: 10 additions & 1 deletion src/Command/UploadFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/Command/UploadPagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) {
Expand Down Expand Up @@ -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'] );
Expand Down