Skip to content
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
2 changes: 0 additions & 2 deletions src/Commands/Lister.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class Lister extends TaskCommand
*/
public function execute(array $params)
{
helper('preference');

if (parametre('tasks.enabled') === false) {
$this->writer->error('WARNING: L\'exécution de la tâche est actuellement désactivée.', true);
$this->writer->write("Pour réactiver les tâches, exécutez\u{a0}: `tasks:enable`", true);
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function execute(array $params)
$this->writer->error('WARNING: L\'exécution de la tâche est actuellement désactivée.', true);
$this->writer->write("Pour réactiver les tâches, exécutez\u{a0}: `tasks:enable`", true);
$this->newLine();

return EXIT_ERROR;
}

$this->task('Exécution de tâches...')->eol();
Expand Down
4 changes: 2 additions & 2 deletions src/HooksTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ protected function process(ContainerInterface $container, string $method): mixed
{
ob_start();

$result = $this->start($this->container, $method);
$result = $this->start($container, $method);

$result = $this->finish($this->container, $result);
$result = $this->finish($container, $result);

ob_end_flush();

Expand Down
29 changes: 8 additions & 21 deletions src/RunResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,13 @@ public function nextRun(string $expression, Date $next): Date
*/
protected function increment(Date $next, string $position): Date
{
switch ($position) {
case 'minute':
$next = $next->addMinutes(1);
break;

case 'hour':
$next = $next->addHours(1);
break;

case 'monthDay':
case 'weekDay':
$next = $next->addDays(1);
break;

case 'month':
$next = $next->addMonths(1);
break;
}

return $next;
return match ($position) {
'minute' => $next->addMinutes(1),
'hour' => $next->addHours(1),
'monthDay', 'weekDay' => $next->addDays(1),
'month' => $next->addMonths(1),
default => $next,
};
}

/**
Expand All @@ -161,7 +148,7 @@ protected function isInList($value, string $list): bool
{
$list = explode(',', $list);

return in_array(trim($value), $list, true);
return in_array(trim((string) $value), $list, true);
}

/**
Expand Down
17 changes: 13 additions & 4 deletions src/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class Task
*/
protected array $environments = [];

/**
* L'alias sous lesquel cette tâche peut être exécutée
*/
protected string $name;

/**
* Faut-il empêcher les exécutions simultanées de cette tâche ?
*/
Expand Down Expand Up @@ -102,7 +107,7 @@ public function __construct(protected string $type, protected mixed $action, pro
*/
public function named(string $name): self
{
$this->attributes['name'] = $name;
$this->name = $name;

return $this;
}
Expand Down Expand Up @@ -343,7 +348,7 @@ protected function buildName(): string
*/
public function __get(string $key)
{
if ($key === 'name' && empty($this->attributes['name'])) {
if ($key === 'name' && (! isset($this->name) || ($this->name === ''))) {
return $this->buildName();
}

Expand All @@ -359,7 +364,11 @@ public function __get(string $key)
*/
public function __set(string $name, mixed $value): void
{
$this->attributes[$name] = $value;
if ($name === 'name' && (! isset($this->name) || ($this->name === ''))) {
$this->name = $value;
} else {
$this->attributes[$name] = $value;
}
}

/**
Expand All @@ -369,7 +378,7 @@ public function __set(string $name, mixed $value): void
*/
private function getLockKey(): string
{
$name = $this->attributes['name'] ?? $this->buildName();
$name = $this->name ?? $this->buildName();

return 'task_lock_' . $name;
}
Expand Down
4 changes: 2 additions & 2 deletions src/TaskRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public function run(): void

foreach ($tasks as $task) {
// Si des tâches spécifiques ont été choisies, sauter l'exécution des tâches restantes.
if (! empty($this->only) && ! in_array($task->name, $this->only, true)) {
if ($this->only !== [] && ! in_array($task->name, $this->only, true)) {
continue;
}

if (! $task->shouldRun($this->testTime) && empty($this->only)) {
if (! $task->shouldRun($this->testTime) && $this->only === []) {
continue;
}

Expand Down