Skip to content

Removed deprecated methods and properties #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Helpers/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public function connection(): ?string
return $this->config->get('deploy-operations.connection');
}

public function transactionAttempts(): int
{
return $this->config->get('deploy-operations.transactions.attempts', 1);
}

public function table(): string
{
return $this->config->get('deploy-operations.table');
Expand Down
140 changes: 5 additions & 135 deletions src/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,11 @@
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.
*
Expand All @@ -69,116 +16,39 @@ public function isOnce(): bool
*/
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');
return true;
}

/**
* 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;
return (bool) config('deploy-operations.transactions.enabled');
}

/**
* 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;
return true;
}

/**
* 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');
return true;
}

/**
* Defines whether the operation will run synchronously or asynchronously.
*/
public function shouldBeAsync(): bool
{
return $this->isAsync();
return (bool) config('deploy-operations.async');
}

/**
Expand Down
11 changes: 3 additions & 8 deletions src/Services/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ protected function runOperation(Operation $operation, string $method): void
{
if ($this->hasOperation($operation, $method)) {
try {
$this->runMethod(
$operation,
$method,
$operation->withinTransactions(),
$operation->transactionAttempts()
);
$this->runMethod($operation, $method, $operation->withinTransactions());

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

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

$transactions ? DB::transaction($callback, $attempts) : $callback();
$transactions ? DB::transaction($callback, $this->config->transactionAttempts()) : $callback();
}

protected function log(string $name, int $batch): void
Expand Down
9 changes: 6 additions & 3 deletions tests/fixtures/app/async/2021_04_06_212742_every_time.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Ramsey\Uuid\Uuid;

return new class extends Operation {
protected bool $once = false;

public function __invoke(): void
{
$this->table()->insert([
Expand All @@ -20,7 +18,12 @@ protected function table(): Builder
return DB::table('every_time');
}

public function isAsync(): bool
public function shouldOnce(): bool
{
return false;
}

public function shouldBeAsync(): bool
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/app/async/2023_04_06_212637_foo_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function table(): Builder
return DB::table('test');
}

public function isAsync(): bool
public function shouldBeAsync(): bool
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Ramsey\Uuid\Uuid;

return new class extends Operation {
protected bool $once = false;

public function up(): void
{
$this->table()->insert([
Expand All @@ -19,4 +17,9 @@ protected function table(): Builder
{
return DB::table('every_time');
}

public function shouldOnce(): bool
{
return false;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Ramsey\Uuid\Uuid;

return new class extends Operation {
protected array|string|null $environment = ['testing', 'production'];

public function up(): void
{
$this->table()->insert([
Expand All @@ -26,4 +24,9 @@ protected function table(): Builder
{
return DB::table('environment');
}

public function shouldRun(): bool
{
return in_array(app()->environment(), ['testing', 'production'], true);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Ramsey\Uuid\Uuid;

return new class extends Operation {
protected array|string|null $environment = 'production';

public function up(): void
{
$this->table()->insert([
Expand All @@ -26,4 +24,9 @@ protected function table(): Builder
{
return DB::table('environment');
}

public function shouldRun(): bool
{
return app()->environment() === 'production';
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Ramsey\Uuid\Uuid;

return new class extends Operation {
protected array|string|null $environment = 'testing';

public function up(): void
{
$this->table()->insert([
Expand All @@ -26,4 +24,9 @@ protected function table(): Builder
{
return DB::table('environment');
}

public function shouldRun(): bool
{
return app()->environment() === 'testing';
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Ramsey\Uuid\Uuid;

return new class extends Operation {
protected array|string|null $exceptEnvironment = 'production';

public function up(): void
{
$this->table()->insert([
Expand All @@ -26,4 +24,9 @@ protected function table(): Builder
{
return DB::table('environment');
}

public function shouldRun(): bool
{
return app()->environment() !== 'production';
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Ramsey\Uuid\Uuid;

return new class extends Operation {
protected array|string|null $exceptEnvironment = 'testing';

public function up(): void
{
$this->table()->insert([
Expand All @@ -26,4 +24,9 @@ protected function table(): Builder
{
return DB::table('environment');
}

public function shouldRun(): bool
{
return app()->environment() !== 'testing';
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
use Ramsey\Uuid\Uuid;

return new class extends Operation {
protected array|string|null $environment = ['testing'];

protected array|string|null $exceptEnvironment = ['testing', 'production'];

public function up(): void
{
$this->table()->insert([
Expand All @@ -28,4 +24,10 @@ protected function table(): Builder
{
return DB::table('environment');
}

public function shouldRun(): bool
{
return app()->environment() === 'testing'
&& ! in_array(app()->environment(), ['testing', 'production'], true);
}
};
Loading