Skip to content

Commit 94e694d

Browse files
authored
Merge pull request #6 from grayfolk/dev
Fix switch accounts during move domain.
2 parents dddf727 + 2af0552 commit 94e694d

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"scripts": {
3737
"post-install-cmd": [
3838
"chmod +x do.sh",
39-
"mkdir -m=777 -p tmp"
39+
"mkdir -m=777 -p tmp",
40+
"cp accounts.json.example accounts.json"
4041
],
4142
"cs:check": "php-cs-fixer fix --verbose --ansi --show-progress=dots --diff --dry-run --config ./.php-cs.php",
4243
"cs:fix": "php-cs-fixer fix --verbose --ansi --show-progress=dots --config .php-cs.php"

src/App.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ public function __construct()
7878
/**
7979
* @param mixed $excludes
8080
* @param mixed $message
81+
* @param mixed $forceAuth
8182
* @throws Exception
8283
*/
83-
public function selectAccount($message = 'Select DigitalOcean account:', $excludes = []): string
84+
public function selectAccount($message = 'Select DigitalOcean account:', $excludes = [], $forceAuth = true): string
8485
{
8586
if (!$this->accounts) {
8687
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
110111

111112
$this->account = $this->radio($message, array_keys($accounts));
112113

113-
$this->auth($this->accounts[$this->account]);
114+
if ($forceAuth) {
115+
$this->auth($this->accounts[$this->account]);
116+
}
114117

115118
return $this->account;
116119
}

src/actions/DomainAction.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ public function run(): void
9494

9595
try {
9696
// Save zone file
97-
$file = sprintf('./tmp/%s-%s.conf', $this->domain, microtime(true));
97+
$dir = sprintf('./tmp/%s', date('Y-m-d'));
98+
if (!file_exists($dir) || !is_dir($dir)) {
99+
mkdir($dir, 0777, true);
100+
}
101+
$file = sprintf('%s/%s-%s.conf', $dir, $this->domain, microtime(true));
98102
$domain = $this->app->client->domain()->getByName($this->domain);
99103
file_put_contents($file, $domain->zoneFile);
100104
$this->app->climate->info("Zone file backuped: {$file}");
@@ -110,7 +114,7 @@ public function run(): void
110114
}
111115
}
112116

113-
$this->accountTo = $this->app->selectAccount("Select account to move {$this->domain}", [$this->accountFrom]);
117+
$this->accountTo = $this->app->selectAccount("Select account to move {$this->domain}", [$this->accountFrom], false);
114118

115119
$ips = [];
116120

@@ -125,6 +129,10 @@ public function run(): void
125129
}
126130
}
127131

132+
if (!\count($ips)) {
133+
$ips[] = '127.0.0.1';
134+
}
135+
128136
$ip = $this->app->radio('Select domain ip (A or AAAA):', $ips);
129137

130138
try {

0 commit comments

Comments
 (0)