From ac0d8c776e5b50f455c2c52f7ddc321b81e063b3 Mon Sep 17 00:00:00 2001 From: tracer Date: Fri, 3 May 2024 20:06:06 +0200 Subject: [PATCH] moved check:version to dev enviroment, for regular check use -v --- TODO | 5 ----- composer.json | 4 ++-- src/Controller/CLIController.php | 38 ++++++++++++++------------------ 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/TODO b/TODO index 4fb4047..5fa864f 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,3 @@ -check:bootstrap -check:version remove option update, we have -v as option -move stuff to dev:xxx which is not needed for endusers -make use of environment, somehow, dev, prod, test -check log file location check:config *validate if all required fields are set, sanity checks. API Endpoint cleanup check keytype of panel/bindApi diff --git a/composer.json b/composer.json index 36fecee..ba5b8a5 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "name": "tracer/bindapi", "description": "manage Bind9 client zones for KeyHelp", - "version": "1.0.9", - "build_number": "377", + "version": "1.1.0", + "build_number": "378", "authors": [ { "name": "Micha Espey", diff --git a/src/Controller/CLIController.php b/src/Controller/CLIController.php index af04eaa..185a4c4 100644 --- a/src/Controller/CLIController.php +++ b/src/Controller/CLIController.php @@ -61,6 +61,9 @@ class CLIController private readonly bool $quiet ) { + $env = $this->configController->getConfig(configKey: 'env'); + $devEnvs = ['dev', 'test']; + $this->baseDir = dirname(path: __DIR__, levels: 2) . '/'; $apikeyGroup = (new CommandGroup(name: 'apikeys', description: 'API keys to access this bindAPI')) @@ -273,14 +276,18 @@ class CLIController $this->checkSetup(); }, mandatoryParameters: ['username'], - description: 'Adapt filesystem permissions (requires elaborated permissions)')) - ->addCommand(command: new Command( + description: 'Adapt filesystem permissions (requires elaborated permissions)')); + + if (in_array(needle: $env, haystack: $devEnvs)) { + $checkVersionCommand = new Command( name: 'version', callback: function () { $this->checkVersion(); }, - optionalParameters: ['update'], - description: 'Read or set the bindApi version in the database')); + description: 'Sync the versions from composer to the database'); + $checkGroup->addCommand(command: $checkVersionCommand); + } + $migrationsGroup = (new CommandGroup(name: 'migrations', description: 'maintain database migrations')) ->addCommand(command: new Command( name: 'status', @@ -297,10 +304,8 @@ class CLIController description: 'Apply a new migration file' )); - $env = $this->configController->getConfig(configKey: 'env'); - $makeEnvs = ['dev', 'test']; - if (in_array(needle: $env, haystack: $makeEnvs)) { + if (in_array(needle: $env, haystack: $devEnvs)) { $makeMigrationsCommand = new Command( name: 'make', callback: function () { @@ -2236,16 +2241,6 @@ const VERSION = '{$versionSting}'; private function checkVersion(): void { $update = false; - if (isset($this->arguments[1])) { - $action = $this->arguments[1]; - if ($action !== 'update') { - if (!$this->quiet) { - echo 'The only allowed argument is "' . Colors::YELLOW . 'update' . Colors::DEFAULT . '.' . PHP_EOL; - } - exit(1); - } - $update = true; - } $composerFile = $this->baseDir . DIRECTORY_SEPARATOR . 'composer.json'; $composerJson = json_decode(json: file_get_contents(filename: $composerFile), associative: false); @@ -2263,14 +2258,13 @@ const VERSION = '{$versionSting}'; echo "File version:\t\t$fileVersion" . PHP_EOL; echo "File build number:\t$fileBuildNumber" . PHP_EOL; - if ($update) { - $this->settingsRepository->set(name: 'version', value: $json); - $this->settingsRepository->set(name: 'buildnumber', value: $fileBuildNumber); - } + $this->settingsRepository->set(name: 'version', value: $json); + $this->settingsRepository->set(name: 'buildnumber', value: $fileBuildNumber); + $currentDBVersion = $this->settingsRepository->findByName(name: 'version'); $dbVersion = json_decode(json: $currentDBVersion); - $currentDBBuildnumber = $this->settingsRepository->findByName(name: 'buildnumber'); + echo "DB version:\t\t"; echo $dbVersion->version->major . '.'; echo $dbVersion->version->minor . '.';