|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Acacha\ForgePublish\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Acacha\ForgePublish\Commands\Traits\ChecksEnv; |
|
6
|
|
|
use Acacha\ForgePublish\Commands\Traits\ChecksSSHConnection; |
|
7
|
|
|
use Acacha\ForgePublish\Commands\Traits\RunsSSHCommands; |
|
8
|
|
|
use GuzzleHttp\Client; |
|
9
|
|
|
use Illuminate\Console\Command; |
|
10
|
|
|
use Illuminate\Support\Facades\File; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class PublishEnvProduction. |
|
14
|
|
|
* |
|
15
|
|
|
* @package Acacha\ForgePublish\Commands |
|
16
|
|
|
*/ |
|
17
|
|
|
class PublishEnvProduction extends Command |
|
18
|
|
|
{ |
|
19
|
|
|
use ChecksEnv, RunsSSHCommands; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Server name |
|
23
|
|
|
* |
|
24
|
|
|
* @var String |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $server; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Domain |
|
30
|
|
|
* |
|
31
|
|
|
* @var String |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $domain; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Local path. |
|
37
|
|
|
* |
|
38
|
|
|
* @var String |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $localPath; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Remote path. |
|
44
|
|
|
* |
|
45
|
|
|
* @var String |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $remotePath; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* The name and signature of the console command. |
|
51
|
|
|
* |
|
52
|
|
|
* @var string |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $signature = 'publish:env-production {--server=} {--domain=}'; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* The console command description. |
|
58
|
|
|
* |
|
59
|
|
|
* @var string |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $description = 'Install local .env.production to .env in production'; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Guzzle http client. |
|
65
|
|
|
* |
|
66
|
|
|
* @var Client |
|
67
|
|
|
*/ |
|
68
|
|
|
protected $http; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Create a new command instance. |
|
72
|
|
|
* |
|
73
|
|
|
*/ |
|
74
|
|
|
public function __construct(Client $http) |
|
75
|
|
|
{ |
|
76
|
|
|
parent::__construct(); |
|
77
|
|
|
$this->http = $http; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Execute the console command. |
|
82
|
|
|
* |
|
83
|
|
|
*/ |
|
84
|
|
|
public function handle() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->abortCommandExecution(); |
|
87
|
|
|
$this->remotePath = $this->domain . '/.env'; |
|
88
|
|
|
$this->runScp($this->localPath, $this->remotePath, null, true); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Abort command execution? |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function abortCommandExecution() |
|
95
|
|
|
{ |
|
96
|
|
|
$this->server = $this->checkEnv('server', 'ACACHA_FORGE_SERVER'); |
|
97
|
|
|
$this->domain = $this->checkEnv('domain', 'ACACHA_FORGE_DOMAIN'); |
|
98
|
|
|
|
|
99
|
|
|
if (! File::exists($this->localPath = base_path('.env.production'))) { |
|
100
|
|
|
$this->error('File ' . $this->localPath . ' not found!'); |
|
101
|
|
|
die(); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$this->abortIfNoSSHConnection(); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exitexpression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.