This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: replace composer deps to begin refactor # This is the commit message #2: chore: replace composer deps to begin refactor # This is the commit message #3: refactor: replace laminas-console with laminas-cli # This is the commit message #4: refactor: replace laminas-console with laminas-cli # This is the commit message #5: refactor: replace laminas-console with laminas-cli # This is the commit message #6: refactor: replace laminas-console with laminas-cli # This is the commit message #7: refactor: near-identical factory boilerplate was bloating, moved to ConfigAbstractFactory for these commands. # This is the commit message #8: refactor: near-identical factory boilerplate was bloating, moved to ConfigAbstractFactory for these commands. # This is the commit message #9: refactor: near-identical factory boilerplate was bloating, moved to ConfigAbstractFactory for these commands. # This is the commit message #10: refactor: Tweaked result handling # This is the commit message #11: refactor: migrated more commands from BatchController # This is the commit message #12: refactor: migrated more commands from BatchController # This is the commit message #13: refactor: more cmds migrated # This is the commit message #14: refactor: some config organised, queue controllers spun out into commands. # This is the commit message #15: refactor: some fixes to config and constructor # This is the commit message #16: refactor: reorganised a bit to correct some incorrect behaviour noticed in local testing # This is the commit message #17: refactor: sorted auth/privelege escallation now running as laminas-cli not as MvcConsole request # This is the commit message #18: refactor: Intial unit test work. # This is the commit message #19: refactor: more unit test work # This is the commit message #20: refactor: further tests implemented refactor: further test implemented refactor: unit test work refactor: more unit tests created refactor: Tests, static analysis fixes. Refactored controllers removed. refactor: Tests, static analysis fixes. Refactored controllers removed. refactor: Imports optimised
- Loading branch information
Showing
86 changed files
with
2,837 additions
and
2,553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
{ | ||
"repositories": [ | ||
{ | ||
"type": "vcs", | ||
"url": "[email protected]:dvsa/olcs-logging.git" | ||
} | ||
], | ||
"name": "olcs/backend", | ||
"description": "Back End Application for OLCS Project", | ||
"require": { | ||
|
@@ -20,7 +26,7 @@ | |
"league/flysystem": "^1.0", | ||
"league/flysystem-webdav": "1.0.10", | ||
"monolog/monolog": "^2.9", | ||
"olcs/olcs-logging": "^6.0.0", | ||
"olcs/olcs-logging": "dev-migrate-to-laminas-cli-vol-3615", | ||
"olcs/olcs-transfer": "^6.0.0", | ||
"olcs/olcs-utils": "^6.0.0", | ||
"olcs/olcs-xmltools": "^6.0.0", | ||
|
@@ -39,15 +45,15 @@ | |
"lm-commons/lmc-rbac-mvc": "^3.3", | ||
"laminas/laminas-mail": "^2.16", | ||
"laminas/laminas-mvc": "^3.3", | ||
"laminas/laminas-mvc-console": "^1.3", | ||
"laminas/laminas-mvc-i18n": "^1.4", | ||
"laminas/laminas-servicemanager": "^3.17", | ||
"laminas/laminas-http": "^2.16", | ||
"laminas/laminas-view": "^2.23", | ||
"laminas/laminas-i18n": "^2.17", | ||
"laminas/laminas-serializer": "^2.13", | ||
"laminas/laminas-eventmanager": "^3.5", | ||
"psr/container": "^1.1|^2" | ||
"psr/container": "^1.1|^2", | ||
"laminas/laminas-cli": "^1.5" | ||
}, | ||
"autoload": { | ||
"classmap": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
namespace Dvsa\Olcs\Cli\Command; | ||
|
||
use Dvsa\Olcs\Api\Domain\CommandHandlerManager; | ||
use Dvsa\Olcs\Api\Domain\Exception\NotFoundException; | ||
use Olcs\Logging\Log\Logger; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
abstract class AbstractOlcsCommand extends Command | ||
{ | ||
protected OutputInterface $output; | ||
protected CommandHandlerManager $commandHandlerManager; | ||
|
||
public function __construct( | ||
CommandHandlerManager $commandHandlerManager | ||
) { | ||
$this->commandHandlerManager = $commandHandlerManager; | ||
parent::__construct(); | ||
} | ||
|
||
protected function initializeOutputInterface(OutputInterface $output) | ||
{ | ||
$this->output = $output; | ||
} | ||
|
||
/** | ||
* Handle an array of command DTOs | ||
* | ||
* @param array $dto | ||
* @return int | ||
*/ | ||
protected function handleCommand(array $dto): int | ||
{ | ||
try { | ||
foreach ($dto as $count => $dtoCommand) { | ||
$logMessage = "Handling command " . ($count + 1) . ': ' . get_class($dtoCommand); | ||
$this->logAndWriteVerboseMessage($logMessage); | ||
|
||
if ($this->isVerbose()) { | ||
$this->output->writeln($logMessage); | ||
} | ||
|
||
$result = $this->commandHandlerManager->handleCommand($dtoCommand); | ||
foreach ($result->getMessages() as $message) { | ||
$this->logAndWriteVerboseMessage($message); | ||
} | ||
} | ||
} catch (NotFoundException $e) { | ||
$this->logAndWriteVerboseMessage('NotFoundException: ' . $e->getMessage(), \Laminas\Log\Logger::WARN, true); | ||
return Command::FAILURE; | ||
} catch (\Exception $e) { | ||
$this->logAndWriteVerboseMessage('Error: ' . $e->getMessage(), \Laminas\Log\Logger::ERR, true); | ||
return Command::FAILURE; | ||
} | ||
return Command::SUCCESS; | ||
} | ||
|
||
/** | ||
* Log messages, output to console if verbose mode is enabled. | ||
* | ||
* @param string $message | ||
* @param int $logPriority | ||
* @param bool $isError | ||
* @return void | ||
*/ | ||
protected function logAndWriteVerboseMessage(string $message, int $logPriority = \Laminas\Log\Logger::DEBUG, bool $isError = false) | ||
{ | ||
Logger::log($logPriority, $message); | ||
$formattedMessage = $isError ? "<error>$message</error>" : "<info>$message</info>"; | ||
|
||
if ($this->output->isVerbose()) { | ||
$this->output->writeln($formattedMessage); | ||
} | ||
} | ||
|
||
/** | ||
* Has user requested verbose output | ||
* | ||
* @return bool | ||
*/ | ||
protected function isVerbose(): bool | ||
{ | ||
return $this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE; | ||
} | ||
|
||
|
||
/** | ||
* Has user requested dry run | ||
* | ||
* @param InputInterface $input | ||
* @return bool | ||
*/ | ||
protected function isDryRun(InputInterface $input): bool | ||
{ | ||
return $input->getOption('dry-run'); | ||
} | ||
|
||
/** | ||
* Output the result of an operation with the appropriate message. | ||
* | ||
* @param int $result | ||
* @param string $successMessage | ||
* @param string $failureMessage | ||
* @return int The status code | ||
*/ | ||
protected function outputResult(int $result, string $successMessage, string $failureMessage): int | ||
{ | ||
if ($result === 0) { | ||
$this->logAndWriteVerboseMessage($successMessage); | ||
return Command::SUCCESS; | ||
} else { | ||
$this->logAndWriteVerboseMessage($failureMessage, \Laminas\Log\Logger::ERR, true); | ||
return Command::FAILURE; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Dvsa\Olcs\Cli\Command\Batch; | ||
|
||
use Dvsa\Olcs\Api\Domain\CommandHandlerManager; | ||
use Dvsa\Olcs\Api\Domain\Exception\NotFoundException; | ||
use Dvsa\Olcs\Api\Domain\QueryHandler\BundleSerializableInterface; | ||
use Dvsa\Olcs\Api\Domain\QueryHandlerManager; | ||
use Dvsa\Olcs\Cli\Command\AbstractOlcsCommand; | ||
use Dvsa\Olcs\Transfer\Query\QueryInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
abstract class AbstractBatchCommand extends AbstractOlcsCommand | ||
{ | ||
protected QueryHandlerManager $queryHandlerManager; | ||
|
||
public function __construct( | ||
CommandHandlerManager $commandHandlerManager, | ||
QueryHandlerManager $queryHandlerManager | ||
) { | ||
parent::__construct( | ||
$commandHandlerManager | ||
); | ||
$this->queryHandlerManager = $queryHandlerManager; | ||
} | ||
|
||
/** | ||
* Add common options to the command | ||
* | ||
* @return void | ||
*/ | ||
protected function addCommonOptions(): void | ||
{ | ||
$this->addOption( | ||
'dry-run', | ||
'd', | ||
InputOption::VALUE_NONE, | ||
'Perform a dry run without making any changes.' | ||
); | ||
} | ||
|
||
/** | ||
* Process a query DTO | ||
* | ||
* @param QueryInterface $dto | ||
* @return BundleSerializableInterface|mixed|null | ||
*/ | ||
protected function handleQuery(QueryInterface $dto) | ||
{ | ||
try { | ||
$this->logAndWriteVerboseMessage("Handling query: " . get_class($dto)); | ||
$result = $this->queryHandlerManager->handleQuery($dto); | ||
return $result; | ||
} catch (NotFoundException $e) { | ||
$this->logAndWriteVerboseMessage("NotFoundException: {$e->getMessage()}", \Laminas\Log\Logger::WARN, true); | ||
} catch (\Exception $e) { | ||
$this->logAndWriteVerboseMessage("Exception: {$e->getMessage()}", \Laminas\Log\Logger::ERR, true); | ||
} catch (\Throwable $e) { | ||
$this->logAndWriteVerboseMessage("Unhandled Error: {$e->getMessage()}", \Laminas\Log\Logger::CRIT, true); | ||
} | ||
return null; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
module/Cli/src/Command/Batch/CleanUpAbandonedVariationsCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Dvsa\Olcs\Cli\Command\Batch; | ||
|
||
use Dvsa\Olcs\Cli\Domain\Command\CleanUpAbandonedVariations; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class CleanUpAbandonedVariationsCommand extends AbstractBatchCommand | ||
{ | ||
protected static $defaultName = 'batch:clean-up-variations'; | ||
|
||
protected function configure() | ||
{ | ||
$this->setDescription('Clean up abandoned variations.'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$this->initializeOutputInterface($output); | ||
|
||
$result = $this->handleCommand([CleanUpAbandonedVariations::create([])]); | ||
|
||
if ($result) { | ||
$this->logAndWriteVerboseMessage('<error>Failed to clean up abandoned variations.</error>'); | ||
return Command::FAILURE; | ||
} | ||
|
||
$this->logAndWriteVerboseMessage('<info>Successfully cleaned up abandoned variations.</info>'); | ||
return Command::SUCCESS; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
module/Cli/src/Command/Batch/CompaniesHouseVsOlcsDiffsExportCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Dvsa\Olcs\Cli\Command\Batch; | ||
|
||
use Dvsa\Olcs\Cli\Domain\Command\CompaniesHouseVsOlcsDiffsExport; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class CompaniesHouseVsOlcsDiffsExportCommand extends AbstractBatchCommand | ||
{ | ||
protected static $defaultName = 'batch:companies-house-vs-olcs-diffs-export'; | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setDescription('Find differences between Companies House and OLCS data and export them.') | ||
->addOption( | ||
'path', | ||
null, | ||
InputOption::VALUE_REQUIRED, | ||
'Path to save the export file.' | ||
); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$this->initializeOutputInterface($output); | ||
|
||
$path = $input->getOption('path'); | ||
if (empty($path)) { | ||
$this->logAndWriteVerboseMessage('<error>No path specified for the export file.</error>'); | ||
return Command::FAILURE; | ||
} | ||
|
||
$result = $this->handleCommand([CompaniesHouseVsOlcsDiffsExport::create(['path' => $path])]); | ||
|
||
return $this->outputResult( | ||
$result, | ||
"Successfully exported differences to {$path}", | ||
'Failed to export differences between Companies House and OLCS data.' | ||
); | ||
} | ||
} |
Oops, something went wrong.