-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathOperation.php
More file actions
193 lines (168 loc) · 5.05 KB
/
Operation.php
File metadata and controls
193 lines (168 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
namespace DragonCode\LaravelDeployOperations;
use DragonCode\LaravelDeployOperations\Concerns\Artisan;
use Illuminate\Support\Arr;
abstract class Operation
{
use Artisan;
/**
* Determines the type of launch of the deploy operation.
*
* If true, then it will be executed once.
* If false, then the operation will run every time the `operations` command is invoked.
*
* @deprecated Will be removed in 7.x version. Use `shouldOnce` method instead.
*/
protected bool $once = true;
/**
* Determines which environment to run on.
*
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
*/
protected array|string|null $environment = null;
/**
* Determines in which environment it should not run.
*
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
*/
protected array|string|null $exceptEnvironment = null;
/**
* Defines a possible "pre-launch" of the operation.
*
* @deprecated Will be removed in 7.x version. Use `hasBefore` method instead.
*/
protected bool $before = true;
/**
* @deprecated
*/
public function getConnection(): ?string
{
return config('deploy-operations.connection');
}
/**
* Determines the type of launch of the deploy operation.
*
* If true, then it will be executed once.
* If false, then the operation will run every time the `operations` command is invoked.
*
* @deprecated Will be removed in 7.x version. Use `shouldOnce` method instead.
*/
public function isOnce(): bool
{
return $this->once;
}
/**
* Determines the type of launch of the deploy operation.
*
* If true, then it will be executed once.
* If false, then the operation will run every time the `operations` command is invoked.
*/
public function shouldOnce(): bool
{
return $this->isOnce();
}
/**
* Determines a call to database transactions.
*
* @deprecated Will be removed in 7.x version. Use `withinTransactions` method instead.
*/
public function enabledTransactions(): bool
{
return (bool) config('deploy-operations.transactions.enabled');
}
/**
* Determines a call to database transactions.
*/
public function withinTransactions(): bool
{
return $this->enabledTransactions();
}
/**
* The number of attempts to execute a request within a transaction before throwing an error.
*
* @deprecated Will be removed in 7.x version. Set the value in the `config/deploy-operations.php` settings file.
*/
public function transactionAttempts(): int
{
return config('deploy-operations.transactions.attempts', 1);
}
/**
* Determines which environment to run on.
*
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
*/
public function onEnvironment(): array
{
return Arr::wrap($this->environment);
}
/**
* Determines in which environment it should not run.
*
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
*/
public function exceptEnvironment(): array
{
return Arr::wrap($this->exceptEnvironment);
}
/**
* Determines whether the given operation can be called conditionally.
*
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
*/
public function allow(): bool
{
return true;
}
/**
* Determines whether the given operation can be called conditionally.
*/
public function shouldRun(): bool
{
$env = app()->environment();
$on = $this->onEnvironment();
$except = $this->exceptEnvironment();
return $this->allow()
&& (empty($on) || in_array($env, $on, true))
&& (empty($except) || ! in_array($env, $except, true));
}
/**
* Defines a possible "pre-launch" of the operation.
*
* @deprecated Will be removed in 7.x version. Use `needBefore` method instead.
*/
public function hasBefore(): bool
{
return $this->before;
}
/**
* Defines a possible "pre-launch" of the operation.
*/
public function needBefore(): bool
{
return $this->hasBefore();
}
/**
* Defines whether the operation will run synchronously or asynchronously.
*
* @deprecated Will be removed in 7.x version. Use `shouldBeAsync` method instead.
*/
public function isAsync(): bool
{
return (bool) config('deploy-operations.async');
}
/**
* Defines whether the operation will run synchronously or asynchronously.
*/
public function shouldBeAsync(): bool
{
return $this->isAsync();
}
/**
* Method to be called when the job completes successfully.
*/
public function success(): void {}
/**
* The method will be called if an error occurs.
*/
public function failed(): void {}
}