From 2af0552a8b60f815c28ab2efdc8d3154afd01c62 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Fri, 15 Oct 2021 01:20:02 +0300 Subject: [PATCH] Fix switch accounts during move domain. --- composer.json | 3 ++- src/App.php | 7 +++++-- src/actions/DomainAction.php | 12 ++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 695df57..40bff47 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ "scripts": { "post-install-cmd": [ "chmod +x do.sh", - "mkdir -m=777 -p tmp" + "mkdir -m=777 -p tmp", + "cp accounts.json.example accounts.json" ], "cs:check": "php-cs-fixer fix --verbose --ansi --show-progress=dots --diff --dry-run --config ./.php-cs.php", "cs:fix": "php-cs-fixer fix --verbose --ansi --show-progress=dots --config .php-cs.php" diff --git a/src/App.php b/src/App.php index 2175633..80a143f 100644 --- a/src/App.php +++ b/src/App.php @@ -78,9 +78,10 @@ public function __construct() /** * @param mixed $excludes * @param mixed $message + * @param mixed $forceAuth * @throws Exception */ - public function selectAccount($message = 'Select DigitalOcean account:', $excludes = []): string + public function selectAccount($message = 'Select DigitalOcean account:', $excludes = [], $forceAuth = true): string { if (!$this->accounts) { if (!file_exists('accounts.json') || !is_file('accounts.json') || !is_readable('accounts.json')) { @@ -110,7 +111,9 @@ public function selectAccount($message = 'Select DigitalOcean account:', $exclud $this->account = $this->radio($message, array_keys($accounts)); - $this->auth($this->accounts[$this->account]); + if ($forceAuth) { + $this->auth($this->accounts[$this->account]); + } return $this->account; } diff --git a/src/actions/DomainAction.php b/src/actions/DomainAction.php index 30665f2..194de87 100644 --- a/src/actions/DomainAction.php +++ b/src/actions/DomainAction.php @@ -94,7 +94,11 @@ public function run(): void try { // Save zone file - $file = sprintf('./tmp/%s-%s.conf', $this->domain, microtime(true)); + $dir = sprintf('./tmp/%s', date('Y-m-d')); + if (!file_exists($dir) || !is_dir($dir)) { + mkdir($dir, 0777, true); + } + $file = sprintf('%s/%s-%s.conf', $dir, $this->domain, microtime(true)); $domain = $this->app->client->domain()->getByName($this->domain); file_put_contents($file, $domain->zoneFile); $this->app->climate->info("Zone file backuped: {$file}"); @@ -110,7 +114,7 @@ public function run(): void } } - $this->accountTo = $this->app->selectAccount("Select account to move {$this->domain}", [$this->accountFrom]); + $this->accountTo = $this->app->selectAccount("Select account to move {$this->domain}", [$this->accountFrom], false); $ips = []; @@ -125,6 +129,10 @@ public function run(): void } } + if (!\count($ips)) { + $ips[] = '127.0.0.1'; + } + $ip = $this->app->radio('Select domain ip (A or AAAA):', $ips); try {