Skip to content

Commit 2f30933

Browse files
Merge pull request #187 from TheDragonCode/6.x
Added new methods. Old methods and properties are marked as deprecated
2 parents 4966007 + 8273635 commit 2f30933

File tree

3 files changed

+90
-25
lines changed

3 files changed

+90
-25
lines changed

phpunit.xml

-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
cacheResult="false"
77
colors="true"
88
>
9-
<coverage>
10-
<report>
11-
<clover outputFile="build/logs/clover.xml"/>
12-
<html outputDirectory="build/logs/coverage"/>
13-
<text outputFile="build/logs/coverage.txt"/>
14-
</report>
15-
</coverage>
169
<php>
1710
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
1811
<env name="APP_ENV" value="testing"/>

src/Operation.php

+80-1
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,35 @@ abstract class Operation
1414
*
1515
* If true, then it will be executed once.
1616
* If false, then the operation will run every time the `operations` command is invoked.
17+
*
18+
* @deprecated Will be removed in 7.x version. Use `shouldOnce` method instead.
1719
*/
1820
protected bool $once = true;
1921

2022
/**
2123
* Determines which environment to run on.
24+
*
25+
* @deprecated Will be removed in 7.x version. Use `withinEnvironment` method instead.
2226
*/
2327
protected array|string|null $environment = null;
2428

2529
/**
2630
* Determines in which environment it should not run.
31+
*
32+
* @deprecated Will be removed in 7.x version. Use `exceptEnvironment` method instead.
2733
*/
2834
protected array|string|null $exceptEnvironment = null;
2935

30-
/** Defines a possible "pre-launch" of the operation. */
36+
/**
37+
* Defines a possible "pre-launch" of the operation.
38+
*
39+
* @deprecated Will be removed in 7.x version. Use `hasBefore` method instead.
40+
*/
3141
protected bool $before = true;
3242

43+
/**
44+
* @deprecated
45+
*/
3346
public function getConnection(): ?string
3447
{
3548
return config('deploy-operations.connection');
@@ -40,22 +53,47 @@ public function getConnection(): ?string
4053
*
4154
* If true, then it will be executed once.
4255
* If false, then the operation will run every time the `operations` command is invoked.
56+
*
57+
* @deprecated Will be removed in 7.x version. Use `shouldOnce` method instead.
4358
*/
4459
public function isOnce(): bool
4560
{
4661
return $this->once;
4762
}
4863

64+
/**
65+
* Determines the type of launch of the deploy operation.
66+
*
67+
* If true, then it will be executed once.
68+
* If false, then the operation will run every time the `operations` command is invoked.
69+
*/
70+
public function shouldOnce(): bool
71+
{
72+
return $this->isOnce();
73+
}
74+
4975
/**
5076
* Determines a call to database transactions.
77+
*
78+
* @deprecated Will be removed in 7.x version. Use `withinTransactions` method instead.
5179
*/
5280
public function enabledTransactions(): bool
5381
{
5482
return (bool) config('deploy-operations.transactions.enabled');
5583
}
5684

85+
/**
86+
* Determines a call to database transactions.
87+
*/
88+
public function withinTransactions(): bool
89+
{
90+
return $this->enabledTransactions();
91+
}
92+
5793
/**
5894
* The number of attempts to execute a request within a transaction before throwing an error.
95+
*
96+
* @deprecated Will be removed in 7.x version. Set the value in the `config/deploy-operations.php` settings file.
5997
*/
6098
public function transactionAttempts(): int
6199
{
@@ -64,14 +102,25 @@ public function transactionAttempts(): int
64102

65103
/**
66104
* Determines which environment to run on.
105+
*
106+
* @deprecated Will be removed in 7.x version. Use `withinEnvironment` method instead.
67107
*/
68108
public function onEnvironment(): array
69109
{
70110
return Arr::wrap($this->environment);
71111
}
72112

113+
public function withinEnvironment(): bool
114+
{
115+
$env = $this->onEnvironment();
116+
117+
return empty($env) || in_array(app()->environment(), $env, true);
118+
}
119+
73120
/**
74121
* Determines in which environment it should not run.
122+
*
123+
* @deprecated Since with version 7.0 will return `bool`.
75124
*/
76125
public function exceptEnvironment(): array
77126
{
@@ -80,28 +129,58 @@ public function exceptEnvironment(): array
80129

81130
/**
82131
* Determines whether the given operation can be called conditionally.
132+
*
133+
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
83134
*/
84135
public function allow(): bool
85136
{
86137
return true;
87138
}
88139

140+
/**
141+
* Determines whether the given operation can be called conditionally.
142+
*/
143+
public function shouldRun(): bool
144+
{
145+
return $this->allow();
146+
}
147+
89148
/**
90149
* Defines a possible "pre-launch" of the operation.
150+
*
151+
* @deprecated Will be removed in 7.x version. Use `needBefore` method instead.
91152
*/
92153
public function hasBefore(): bool
93154
{
94155
return $this->before;
95156
}
96157

158+
/**
159+
* Defines a possible "pre-launch" of the operation.
160+
*/
161+
public function needBefore(): bool
162+
{
163+
return $this->hasBefore();
164+
}
165+
97166
/**
98167
* Defines whether the operation will run synchronously or asynchronously.
168+
*
169+
* @deprecated Will be removed in 7.x version. Use `shouldBeAsync` method instead.
99170
*/
100171
public function isAsync(): bool
101172
{
102173
return (bool) config('deploy-operations.async');
103174
}
104175

176+
/**
177+
* Defines whether the operation will run synchronously or asynchronously.
178+
*/
179+
public function shouldBeAsync(): bool
180+
{
181+
return $this->isAsync();
182+
}
183+
105184
/**
106185
* Method to be called when the job completes successfully.
107186
*/

src/Services/Migrator.php

+10-17
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function runUp(string $filename, int $batch, Options $options): void
7171
? $this->runOperation($operation, '__invoke')
7272
: $this->runOperation($operation, 'up');
7373

74-
if ($this->allowLogging($operation)) {
74+
if ($operation->shouldOnce()) {
7575
$this->log($name, $batch);
7676
}
7777
});
@@ -96,7 +96,7 @@ protected function runOperation(Operation $operation, string $method): void
9696
$this->runMethod(
9797
$operation,
9898
$method,
99-
$operation->enabledTransactions(),
99+
$operation->withinTransactions(),
100100
$operation->transactionAttempts()
101101
);
102102

@@ -117,7 +117,7 @@ protected function hasOperation(Operation $operation, string $method): bool
117117

118118
protected function hasAsync(Operation $operation, Options $options): bool
119119
{
120-
return ! $options->sync && $operation->isAsync();
120+
return ! $options->sync && $operation->shouldBeAsync();
121121
}
122122

123123
protected function runMethod(Operation $operation, string $method, bool $transactions, int $attempts): void
@@ -150,29 +150,22 @@ protected function allowEnvironment(Operation $operation): bool
150150
{
151151
$env = $this->config->environment();
152152

153-
return $operation->allow()
154-
&& $this->onEnvironment($env, $operation->onEnvironment())
153+
return $operation->shouldRun()
154+
&& $operation->withinEnvironment()
155155
&& $this->exceptEnvironment($env, $operation->exceptEnvironment());
156156
}
157157

158-
protected function onEnvironment(?string $env, array $on): bool
159-
{
160-
return empty($on) || in_array($env, $on);
161-
}
162-
158+
/**
159+
* @deprecated
160+
*/
163161
protected function exceptEnvironment(?string $env, array $except): bool
164162
{
165-
return empty($except) || ! in_array($env, $except);
163+
return empty($except) || ! in_array($env, $except, true);
166164
}
167165

168166
protected function disallowBefore(Operation $operation, Options $options): bool
169167
{
170-
return $options->before && ! $operation->hasBefore();
171-
}
172-
173-
protected function allowLogging(Operation $operation): bool
174-
{
175-
return $operation->isOnce();
168+
return $options->before && ! $operation->needBefore();
176169
}
177170

178171
protected function resolvePath(string $filename, string $path): string

0 commit comments

Comments
 (0)