From 37fd07cc1cfa11ae4aa3d63f0f8fe12a3633cce8 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos <ioigoume@gmail.com> Date: Thu, 6 Jun 2024 13:54:24 +0300 Subject: [PATCH] Move test seutp in TestCommand class --- app/src/Command/SetupCommand.php | 14 +++----------- app/src/Command/TestCommand.php | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/app/src/Command/SetupCommand.php b/app/src/Command/SetupCommand.php index 456c9f0bc..d3e3a8deb 100644 --- a/app/src/Command/SetupCommand.php +++ b/app/src/Command/SetupCommand.php @@ -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. diff --git a/app/src/Command/TestCommand.php b/app/src/Command/TestCommand.php index 038f94d54..85bf32b20 100644 --- a/app/src/Command/TestCommand.php +++ b/app/src/Command/TestCommand.php @@ -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' @@ -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; @@ -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; + } } \ No newline at end of file