Skip to content

CFM-28_Setup_Command_test_setup #203

Merged
merged 1 commit into from
Jun 6, 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
14 changes: 3 additions & 11 deletions app/src/Command/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,9 @@ public function execute(Arguments $args, ConsoleIo $io)
$force = $args->getOption('force');

// Check if the COmanage CO already exists, and if so abort.

$coTable = $this->getTableLocator()->get('Cos');
$query = $coTable->find();
$comanageCO = $coTable->findCOmanageCO($query)->first();

if(!is_null($comanageCO)) {
$io->out(__d('command', 'se.already'));

if(!$force) {
exit;
}
if($this->executeCommand(TestCommand::class, ['-t', 'setup']) === static::CODE_ERROR
&& !$force) {
$this->abort(static::CODE_ERROR);
}

// Collect the admin info before we try to do anything.
Expand Down
28 changes: 27 additions & 1 deletion app/src/Command/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
$parser->addOption('test', [
'help' => __d('command', 'opt.test.test'),
'short' => 't',
'choices' => ['database', 'mail']
'choices' => ['database', 'mail', 'setup']
])->addOption('datasource', [
'help' => __d('command', 'opt.test.database.source'),
'default' => 'default'
Expand Down Expand Up @@ -88,6 +88,9 @@ public function execute(Arguments $args, ConsoleIo $io)
case 'mail':
$this->testMail((int)$args->getOption('recipient'));
break;
case 'setup':
$this->testSetup();
break;
default:
$io->out("Command $test unknown");
break;
Expand Down Expand Up @@ -139,4 +142,27 @@ protected function testMail(int $recipient): int {

return static::CODE_SUCCESS;
}

/**
* Test COmanage setup
*
* @since COmanage Registry v5.0.0
* @return int Return Code (CODE_SUCCESS or CODE_ERROR)
*/

protected function testSetup(): int {

// Check if the COmanage CO already exists, and if so abort.

$coTable = $this->getTableLocator()->get('Cos');
$query = $coTable->find();
$comanageCO = $coTable->findCOmanageCO($query)->first();

if($comanageCO !== null) {
$this->io->out(__d('command', 'se.already'));
$this->abort(static::CODE_ERROR);
}

return static::CODE_SUCCESS;
}
}