Skip to content

Commit

Permalink
Merge pull request #80 from TheDragonCode/3.x
Browse files Browse the repository at this point in the history
Added logging when skipping action launches
  • Loading branch information
andrey-helldar authored Oct 12, 2022
2 parents badbc29 + c89fc05 commit d33232d
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/Services/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ public function runUp(string $filename, int $batch, Options $options): void
$name = $this->resolveActionName($path);

if ($this->allowAction($action, $name, $options)) {
$this->hasAction($action, '__invoke')
? $this->runAction($action, $name, '__invoke')
: $this->runAction($action, $name, 'up');
$this->notification->task($name, function () use ($action, $name, $batch) {
$this->hasAction($action, '__invoke')
? $this->runAction($action, '__invoke')
: $this->runAction($action, 'up');

if ($this->allowLogging($action)) {
$this->log($name, $batch);
}
if ($this->allowLogging($action)) {
$this->log($name, $batch);
}
});

return;
}

$this->notification->twoColumn($name, 'SKIP');
}

public function runDown(string $filename, Options $options): void
Expand All @@ -65,34 +71,34 @@ public function runDown(string $filename, Options $options): void
$action = $this->resolveAction($path);
$name = $this->resolveActionName($path);

if (! $this->hasAction($action, '__invoke') && $this->hasAction($action, 'down')) {
$this->runAction($action, $name, 'down');
}
$this->notification->task($name, function () use ($action, $name) {
if (! $this->hasAction($action, '__invoke') && $this->hasAction($action, 'down')) {
$this->runAction($action, 'down');
}

$this->deleteLog($name);
$this->deleteLog($name);
});
}

protected function hasAction(Action $action, string $method): bool
{
return method_exists($action, $method);
}

protected function runAction(Action $action, string $name, string $method): void
protected function runAction(Action $action, string $method): void
{
$this->notification->task($name, function () use ($action, $method) {
if ($this->hasAction($action, $method)) {
try {
$this->runMethod($action, $method, $action->enabledTransactions(), $action->transactionAttempts());
if ($this->hasAction($action, $method)) {
try {
$this->runMethod($action, $method, $action->enabledTransactions(), $action->transactionAttempts());

$action->success();
}
catch (Throwable $e) {
$action->failed();
$action->success();
}
catch (Throwable $e) {
$action->failed();

throw $e;
}
throw $e;
}
});
}
}

protected function runMethod(Action $action, string $method, bool $transactions, int $attempts): void
Expand Down

0 comments on commit d33232d

Please sign in to comment.