Skip to content

Commit

Permalink
#1259 Use Symfony Console Command constants
Browse files Browse the repository at this point in the history
  • Loading branch information
j3nsch committed Feb 6, 2025
1 parent 81ce7b9 commit 2decc4e
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 31 deletions.
10 changes: 5 additions & 5 deletions library/Application/Console/Collection/CopyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if ($sourceCol === null) {
$output->writeln('Source collection needs to be specified.');
return 0;
return self::FAILURE;
}

if ($destCol === null) {
$output->writeln('Destination collection needs to be specified.');
return 0;
return self::FAILURE;
}

$sourceId = $sourceCol->getId();
Expand All @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('');
$output->writeln(' "' . $sourceCol->getDisplayName() . '"');
$output->writeln('');
return 0;
return self::SUCCESS;
}

$destDocuments = $destCol->getDocumentIds();
Expand All @@ -88,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if ($moveCount === 0) {
$output->writeln("Destination collection already contains all the documents (${sourceCount}) of source collection.");
return 0;
return self::SUCCESS;
}

$output->writeln("Copy documents (${moveCount}) from source collection (ID = ${sourceId})");
Expand Down Expand Up @@ -116,6 +116,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('Copying cancelled');
}

return 0;
return self::SUCCESS;
}
}
8 changes: 4 additions & 4 deletions library/Application/Console/Collection/MoveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if ($sourceCol === null) {
$output->writeln('Source collection needs to be specified.');
return 0;
return self::FAILURE;
}

if ($destCol === null) {
$output->writeln('Destination collection needs to be specified.');
return 0;
return self::FAILURE;
}

$sourceId = $sourceCol->getId();
Expand All @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('');
$output->writeln(' "' . $sourceCol->getDisplayName() . '"');
$output->writeln('');
return 0;
return self::SUCCESS;
}

$output->writeln("Move documents (${sourceCount}) from source collection (ID = ${sourceId})");
Expand Down Expand Up @@ -107,6 +107,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('Moving cancelled');
}

return 0;
return self::SUCCESS;
}
}
12 changes: 6 additions & 6 deletions library/Application/Console/Collection/RemoveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if ($targetCol === null) {
$output->writeln('Collection must be specified');
return 0;
return self::FAILURE;
}

$targetId = $targetCol->getId();
Expand All @@ -214,7 +214,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('');
$output->writeln(' "' . $targetCol->getDisplayName() . '"');
$output->writeln('');
return 0;
return self::FAILURE;
}

$removeDocuments = null;
Expand All @@ -235,7 +235,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('');
$output->writeln(' "' . $filterCol->getDisplayName() . '"');
$output->writeln('');
return 0;
return self::FAILURE;
}

$removeDocuments = array_intersect($filterDocuments, $targetDocuments);
Expand All @@ -246,11 +246,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('');
$output->writeln(' "' . $filterCol->getDisplayName() . '"');
$output->writeln('');
$output->writeln("is present in the target collection (ID= ${targetId})");
$output->writeln("are present in the target collection (ID= ${targetId})");
$output->writeln('');
$output->writeln(' "' . $targetCol->getDisplayName() . '"');
$output->writeln('');
return 0;
return self::FAILURE;
}

$output->writeln("Remove documents (${filterCount}) in collection (ID = ${filterId})");
Expand Down Expand Up @@ -279,6 +279,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('Removing cancelled');
}

return 0;
return self::SUCCESS;
}
}
4 changes: 2 additions & 2 deletions library/Application/Console/Console/ConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('Caught exception ' . get_class($e) . ': ' . $e->getMessage());
$output->writeln($e->getTraceAsString());

return Command::FAILURE;
return self::FAILURE;
}
}

return Command::SUCCESS;
return self::SUCCESS;
}
}
4 changes: 2 additions & 2 deletions library/Application/Console/Console/ExecCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('Caught exception ' . get_class($e) . ': ' . $e->getMessage());
$output->writeln($e->getTraceAsString());

return Command::FAILURE;
return self::FAILURE;
}
}

return $successfulIncludes > 0 ? Command::SUCCESS : Command::FAILURE;
return $successfulIncludes > 0 ? self::SUCCESS : self::FAILURE;
}
}
2 changes: 1 addition & 1 deletion library/Application/Console/Debug/DocumentXmlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$output->write($xml->saveXml());

return 0;
return self::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion library/Application/Console/Document/DeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('Deletion cancelled');
}

return 0;
return self::SUCCESS;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion library/Application/Console/Document/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$diff->diff($docIds);
}

return 0;
return self::SUCCESS;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion library/Application/Console/Document/DuplicatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('No DOI values found');
}

return 0;
return self::SUCCESS;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions library/Application/Console/Task/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if (empty($taskConfigurations)) {
$output->writeln('<fg=red>There are no tasks configured</>');
return Command::FAILURE;
return self::FAILURE;
}

if (empty($taskName)) {
Expand All @@ -98,7 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$taskConfig = $taskManager->getTaskConfig($taskName);
if (! $taskConfig) {
$output->writeln('Task not found: <fg=red>' . $taskName . '</>');
return Command::FAILURE;
return self::FAILURE;
}

// show
Expand Down Expand Up @@ -132,6 +132,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
->setStyle('compact')
->render();

return Command::SUCCESS;
return self::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion library/Application/Console/Task/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$table->render();

return 0;
return self::SUCCESS;
}
}
8 changes: 4 additions & 4 deletions library/Application/Console/Task/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if (empty($taskConfigurations)) {
$output->writeln('<fg=red>There are no tasks to run</>');
return Command::FAILURE;
return self::FAILURE;
}

if (empty($taskName)) {
Expand All @@ -101,22 +101,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$taskConfig = $taskManager->getTaskConfig($taskName);
if (! $taskConfig) {
$output->writeln('Task not found: <fg=red>' . $taskName . '</>');
return Command::FAILURE;
return self::FAILURE;
}

if (! $taskManager->isValidTaskClass($taskConfig->getClass())) {
$output->writeln(
'Invalid task class <fg=red>' . $taskConfig->getClass()
. '</> for task <fg=red>' . $taskName . '</>'
);
return Command::FAILURE;
return self::FAILURE;
}

$taskRunner = new TaskRunner();
$taskRunnerLogger = $taskRunner->getTaskLogger();
$taskRunnerLogger->info('CLI triggered run: "' . $taskName . '"');
$taskRunner->runTask($taskName);

return Command::SUCCESS;
return self::SUCCESS;
}
}

0 comments on commit 2decc4e

Please sign in to comment.