Skip to content

Commit b4fdb83

Browse files
Merge pull request #190 from TheDragonCode/7.x
Removed deprecated methods and properties
2 parents 9de6ca4 + fc6799c commit b4fdb83

17 files changed

+80
-181
lines changed

src/Helpers/Config.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public function connection(): ?string
2828
return $this->config->get('deploy-operations.connection');
2929
}
3030

31+
public function transactionAttempts(): int
32+
{
33+
return $this->config->get('deploy-operations.transactions.attempts', 1);
34+
}
35+
3136
public function table(): string
3237
{
3338
return $this->config->get('deploy-operations.table');

src/Operation.php

Lines changed: 5 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,11 @@
33
namespace DragonCode\LaravelDeployOperations;
44

55
use DragonCode\LaravelDeployOperations\Concerns\Artisan;
6-
use Illuminate\Support\Arr;
76

87
abstract class Operation
98
{
109
use Artisan;
1110

12-
/**
13-
* Determines the type of launch of the deploy operation.
14-
*
15-
* If true, then it will be executed once.
16-
* 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.
19-
*/
20-
protected bool $once = true;
21-
22-
/**
23-
* Determines which environment to run on.
24-
*
25-
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
26-
*/
27-
protected array|string|null $environment = null;
28-
29-
/**
30-
* Determines in which environment it should not run.
31-
*
32-
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
33-
*/
34-
protected array|string|null $exceptEnvironment = null;
35-
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-
*/
41-
protected bool $before = true;
42-
43-
/**
44-
* @deprecated
45-
*/
46-
public function getConnection(): ?string
47-
{
48-
return config('deploy-operations.connection');
49-
}
50-
51-
/**
52-
* Determines the type of launch of the deploy operation.
53-
*
54-
* If true, then it will be executed once.
55-
* 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.
58-
*/
59-
public function isOnce(): bool
60-
{
61-
return $this->once;
62-
}
63-
6411
/**
6512
* Determines the type of launch of the deploy operation.
6613
*
@@ -69,116 +16,39 @@ public function isOnce(): bool
6916
*/
7017
public function shouldOnce(): bool
7118
{
72-
return $this->isOnce();
73-
}
74-
75-
/**
76-
* Determines a call to database transactions.
77-
*
78-
* @deprecated Will be removed in 7.x version. Use `withinTransactions` method instead.
79-
*/
80-
public function enabledTransactions(): bool
81-
{
82-
return (bool) config('deploy-operations.transactions.enabled');
19+
return true;
8320
}
8421

8522
/**
8623
* Determines a call to database transactions.
8724
*/
8825
public function withinTransactions(): bool
8926
{
90-
return $this->enabledTransactions();
91-
}
92-
93-
/**
94-
* 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.
97-
*/
98-
public function transactionAttempts(): int
99-
{
100-
return config('deploy-operations.transactions.attempts', 1);
101-
}
102-
103-
/**
104-
* Determines which environment to run on.
105-
*
106-
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
107-
*/
108-
public function onEnvironment(): array
109-
{
110-
return Arr::wrap($this->environment);
111-
}
112-
113-
/**
114-
* Determines in which environment it should not run.
115-
*
116-
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
117-
*/
118-
public function exceptEnvironment(): array
119-
{
120-
return Arr::wrap($this->exceptEnvironment);
121-
}
122-
123-
/**
124-
* Determines whether the given operation can be called conditionally.
125-
*
126-
* @deprecated Will be removed in 7.x version. Use `shouldRun` method instead.
127-
*/
128-
public function allow(): bool
129-
{
130-
return true;
27+
return (bool) config('deploy-operations.transactions.enabled');
13128
}
13229

13330
/**
13431
* Determines whether the given operation can be called conditionally.
13532
*/
13633
public function shouldRun(): bool
13734
{
138-
$env = app()->environment();
139-
140-
$on = $this->onEnvironment();
141-
$except = $this->exceptEnvironment();
142-
143-
return $this->allow()
144-
&& (empty($on) || in_array($env, $on, true))
145-
&& (empty($except) || ! in_array($env, $except, true));
146-
}
147-
148-
/**
149-
* Defines a possible "pre-launch" of the operation.
150-
*
151-
* @deprecated Will be removed in 7.x version. Use `needBefore` method instead.
152-
*/
153-
public function hasBefore(): bool
154-
{
155-
return $this->before;
35+
return true;
15636
}
15737

15838
/**
15939
* Defines a possible "pre-launch" of the operation.
16040
*/
16141
public function needBefore(): bool
16242
{
163-
return $this->hasBefore();
164-
}
165-
166-
/**
167-
* Defines whether the operation will run synchronously or asynchronously.
168-
*
169-
* @deprecated Will be removed in 7.x version. Use `shouldBeAsync` method instead.
170-
*/
171-
public function isAsync(): bool
172-
{
173-
return (bool) config('deploy-operations.async');
43+
return true;
17444
}
17545

17646
/**
17747
* Defines whether the operation will run synchronously or asynchronously.
17848
*/
17949
public function shouldBeAsync(): bool
18050
{
181-
return $this->isAsync();
51+
return (bool) config('deploy-operations.async');
18252
}
18353

18454
/**

src/Services/Migrator.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,7 @@ protected function runOperation(Operation $operation, string $method): void
9292
{
9393
if ($this->hasOperation($operation, $method)) {
9494
try {
95-
$this->runMethod(
96-
$operation,
97-
$method,
98-
$operation->withinTransactions(),
99-
$operation->transactionAttempts()
100-
);
95+
$this->runMethod($operation, $method, $operation->withinTransactions());
10196

10297
$operation->success();
10398
}
@@ -119,11 +114,11 @@ protected function hasAsync(Operation $operation, Options $options): bool
119114
return ! $options->sync && $operation->shouldBeAsync();
120115
}
121116

122-
protected function runMethod(Operation $operation, string $method, bool $transactions, int $attempts): void
117+
protected function runMethod(Operation $operation, string $method, bool $transactions): void
123118
{
124119
$callback = fn () => $this->container->call([$operation, $method]);
125120

126-
$transactions ? DB::transaction($callback, $attempts) : $callback();
121+
$transactions ? DB::transaction($callback, $this->config->transactionAttempts()) : $callback();
127122
}
128123

129124
protected function log(string $name, int $batch): void

tests/fixtures/app/async/2021_04_06_212742_every_time.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use Ramsey\Uuid\Uuid;
77

88
return new class extends Operation {
9-
protected bool $once = false;
10-
119
public function __invoke(): void
1210
{
1311
$this->table()->insert([
@@ -20,7 +18,12 @@ protected function table(): Builder
2018
return DB::table('every_time');
2119
}
2220

23-
public function isAsync(): bool
21+
public function shouldOnce(): bool
22+
{
23+
return false;
24+
}
25+
26+
public function shouldBeAsync(): bool
2427
{
2528
return true;
2629
}

tests/fixtures/app/async/2023_04_06_212637_foo_bar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function table(): Builder
1818
return DB::table('test');
1919
}
2020

21-
public function isAsync(): bool
21+
public function shouldBeAsync(): bool
2222
{
2323
return true;
2424
}

tests/fixtures/app/operations/2021_01_02_020947_every_time.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use Ramsey\Uuid\Uuid;
77

88
return new class extends Operation {
9-
protected bool $once = false;
10-
119
public function up(): void
1210
{
1311
$this->table()->insert([
@@ -19,4 +17,9 @@ protected function table(): Builder
1917
{
2018
return DB::table('every_time');
2119
}
20+
21+
public function shouldOnce(): bool
22+
{
23+
return false;
24+
}
2225
};

tests/fixtures/app/operations/2021_05_24_120003_run_on_many_environments.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use Ramsey\Uuid\Uuid;
77

88
return new class extends Operation {
9-
protected array|string|null $environment = ['testing', 'production'];
10-
119
public function up(): void
1210
{
1311
$this->table()->insert([
@@ -26,4 +24,9 @@ protected function table(): Builder
2624
{
2725
return DB::table('environment');
2826
}
27+
28+
public function shouldRun(): bool
29+
{
30+
return in_array(app()->environment(), ['testing', 'production'], true);
31+
}
2932
};

tests/fixtures/app/operations/2021_05_24_120003_run_on_production.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use Ramsey\Uuid\Uuid;
77

88
return new class extends Operation {
9-
protected array|string|null $environment = 'production';
10-
119
public function up(): void
1210
{
1311
$this->table()->insert([
@@ -26,4 +24,9 @@ protected function table(): Builder
2624
{
2725
return DB::table('environment');
2826
}
27+
28+
public function shouldRun(): bool
29+
{
30+
return app()->environment() === 'production';
31+
}
2932
};

tests/fixtures/app/operations/2021_05_24_120003_run_on_testing.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use Ramsey\Uuid\Uuid;
77

88
return new class extends Operation {
9-
protected array|string|null $environment = 'testing';
10-
119
public function up(): void
1210
{
1311
$this->table()->insert([
@@ -26,4 +24,9 @@ protected function table(): Builder
2624
{
2725
return DB::table('environment');
2826
}
27+
28+
public function shouldRun(): bool
29+
{
30+
return app()->environment() === 'testing';
31+
}
2932
};

tests/fixtures/app/operations/2021_06_07_132849_run_except_production.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use Ramsey\Uuid\Uuid;
77

88
return new class extends Operation {
9-
protected array|string|null $exceptEnvironment = 'production';
10-
119
public function up(): void
1210
{
1311
$this->table()->insert([
@@ -26,4 +24,9 @@ protected function table(): Builder
2624
{
2725
return DB::table('environment');
2826
}
27+
28+
public function shouldRun(): bool
29+
{
30+
return app()->environment() !== 'production';
31+
}
2932
};

tests/fixtures/app/operations/2021_06_07_132917_run_except_testing.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use Ramsey\Uuid\Uuid;
77

88
return new class extends Operation {
9-
protected array|string|null $exceptEnvironment = 'testing';
10-
119
public function up(): void
1210
{
1311
$this->table()->insert([
@@ -26,4 +24,9 @@ protected function table(): Builder
2624
{
2725
return DB::table('environment');
2826
}
27+
28+
public function shouldRun(): bool
29+
{
30+
return app()->environment() !== 'testing';
31+
}
2932
};

tests/fixtures/app/operations/2021_06_07_134045_run_except_many_environments.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
use Ramsey\Uuid\Uuid;
77

88
return new class extends Operation {
9-
protected array|string|null $environment = ['testing'];
10-
11-
protected array|string|null $exceptEnvironment = ['testing', 'production'];
12-
139
public function up(): void
1410
{
1511
$this->table()->insert([
@@ -28,4 +24,10 @@ protected function table(): Builder
2824
{
2925
return DB::table('environment');
3026
}
27+
28+
public function shouldRun(): bool
29+
{
30+
return app()->environment() === 'testing'
31+
&& ! in_array(app()->environment(), ['testing', 'production'], true);
32+
}
3133
};

0 commit comments

Comments
 (0)