Skip to content

Commit

Permalink
Merge pull request #6 from grayfolk/dev
Browse files Browse the repository at this point in the history
Fix switch accounts during move domain.
  • Loading branch information
grayfolk authored Oct 14, 2021
2 parents dddf727 + 2af0552 commit 94e694d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 5 additions & 2 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 10 additions & 2 deletions src/actions/DomainAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand All @@ -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 = [];

Expand All @@ -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 {
Expand Down

0 comments on commit 94e694d

Please sign in to comment.