diff --git a/app/src/Command/TestCommand.php b/app/src/Command/TestCommand.php new file mode 100644 index 000000000..6109ae41d --- /dev/null +++ b/app/src/Command/TestCommand.php @@ -0,0 +1,104 @@ +addOption('test', [ + 'help' => __d('command', 'opt.test.test'), + 'short' => 't', + 'choices' => ['database'] + ])->addOption('datasource', [ + 'help' => __d('command', 'opt.test.database.source'), + 'default' => 'default' + ]); + + return $parser; + } + + /** + * Execute the Setup Command. + * + * @since COmanage Registry v5.0.0 + * @param Arguments $args Command Arguments + * @param ConsoleIo $io Console IO + */ + + public function execute(Arguments $args, ConsoleIo $io) + { + global $argv; + + $this->io = $io; + + // The test we want to run + $test = $args->getOption('test'); + + switch($test) { + case 'database': + $this->testDatabase($args->getOption('datasource')); + break; + } + } + + /** + * Test database connectivity for the default + */ + + protected function testDatabase(string $source): int { + try { + $cxn = ConnectionManager::get($source); + $this->io->out(__d('command', 'opt.test.database.ok')); + } + catch(\Exception $e) { + $this->io->error($e->getMessage()); + $this->abort(static::CODE_ERROR); + } + + return static::CODE_SUCCESS; + } +} \ No newline at end of file