Skip to content

Added new methods. Old methods and properties are marked as deprecated #187

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
7 changes: 0 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
cacheResult="false"
colors="true"
>
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/logs/coverage"/>
<text outputFile="build/logs/coverage.txt"/>
</report>
</coverage>
<php>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<env name="APP_ENV" value="testing"/>
Expand Down
81 changes: 80 additions & 1 deletion src/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,35 @@ abstract class 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 `withinEnvironment` 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 `exceptEnvironment` method instead.
*/
protected array|string|null $exceptEnvironment = null;

/** Defines a possible "pre-launch" of the operation. */
/**
* 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');
Expand All @@ -40,22 +53,47 @@ public function getConnection(): ?string
*
* 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
{
Expand All @@ -64,14 +102,25 @@ public function transactionAttempts(): int

/**
* Determines which environment to run on.
*
* @deprecated Will be removed in 7.x version. Use `withinEnvironment` method instead.
*/
public function onEnvironment(): array
{
return Arr::wrap($this->environment);
}

public function withinEnvironment(): bool
{
$env = $this->onEnvironment();

return empty($env) || in_array(app()->environment(), $env, true);
}

/**
* Determines in which environment it should not run.
*
* @deprecated Since with version 7.0 will return `bool`.
*/
public function exceptEnvironment(): array
{
Expand All @@ -80,28 +129,58 @@ public function exceptEnvironment(): array

/**
* 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
{
return $this->allow();
}

/**
* 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.
*/
Expand Down
27 changes: 10 additions & 17 deletions src/Services/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function runUp(string $filename, int $batch, Options $options): void
? $this->runOperation($operation, '__invoke')
: $this->runOperation($operation, 'up');

if ($this->allowLogging($operation)) {
if ($operation->shouldOnce()) {
$this->log($name, $batch);
}
});
Expand All @@ -96,7 +96,7 @@ protected function runOperation(Operation $operation, string $method): void
$this->runMethod(
$operation,
$method,
$operation->enabledTransactions(),
$operation->withinTransactions(),
$operation->transactionAttempts()
);

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

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

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

return $operation->allow()
&& $this->onEnvironment($env, $operation->onEnvironment())
return $operation->shouldRun()
&& $operation->withinEnvironment()
&& $this->exceptEnvironment($env, $operation->exceptEnvironment());
}

protected function onEnvironment(?string $env, array $on): bool
{
return empty($on) || in_array($env, $on);
}

/**
* @deprecated
*/
protected function exceptEnvironment(?string $env, array $except): bool
{
return empty($except) || ! in_array($env, $except);
return empty($except) || ! in_array($env, $except, true);
}

protected function disallowBefore(Operation $operation, Options $options): bool
{
return $options->before && ! $operation->hasBefore();
}

protected function allowLogging(Operation $operation): bool
{
return $operation->isOnce();
return $options->before && ! $operation->needBefore();
}

protected function resolvePath(string $filename, string $path): string
Expand Down