diff --git a/CHANGELOG.md b/CHANGELOG.md index 6837637..6748fe6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ vNext ===== * (impprovement) Display class name of wrapped Task when running `sf debug:scheduler` +* (bug) Add proper support for fetching and validating Tasks that are configured via `#[AsMessage(…)]` attribute. +* (internal) Remove previously used Tag `task-manager.task`. +* (improvement) Fix deprecation in `TaskLog`'s `OrderBy` configuration. 3.4.1 diff --git a/src/DependencyInjection/FindTaskClassesCompilerPass.php b/src/DependencyInjection/FindTaskClassesCompilerPass.php index 970d2c0..1278ae3 100644 --- a/src/DependencyInjection/FindTaskClassesCompilerPass.php +++ b/src/DependencyInjection/FindTaskClassesCompilerPass.php @@ -5,6 +5,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Torr\TaskManager\Config\BundleConfig; +use Torr\TaskManager\Task\Task; /** * Compiler pass, that collects all tasks from the container that are from the app @@ -22,20 +23,29 @@ public function process (ContainerBuilder $container) : void { $taskClasses = []; - foreach ($container->findTaggedServiceIds("task-manager.task") as $taskServiceId => $config) + foreach ($container->getDefinitions() as $taskServiceId => $definition) { - $definition = $container->getDefinition($taskServiceId); $taskFQCN = $definition->getClass(); - if (null !== $taskFQCN && str_starts_with($taskFQCN, "App\\")) + if (null === $taskFQCN || !str_starts_with($taskFQCN, "App\\")) { - $taskClasses[] = $taskFQCN; + continue; } - // Remove task service definition, as these must never be a service - // in the actual runtime. We just use the mechanism to collect all - // tasks in the app. - $container->removeDefinition($taskServiceId); + $reflection = $container->getReflectionClass($taskFQCN, false); + + if (null === $reflection || !$reflection->isSubclassOf(Task::class)) + { + continue; + } + + $taskClasses[] = $taskFQCN; + + // Ensure that our Task classes are removed from the container definitions. Depending on the way + // the Tasks are registered (either via `AsMessage` attribute or via `messenger.yaml` config), + // they'll be excluded automatically. This happens automatically when the `AsMessage` attribute is being used. + // Here we're making sure that this also happens when using the YAML config file. + $definition->addTag("container.excluded"); } $container->getDefinition(BundleConfig::class) diff --git a/src/Entity/TaskLog.php b/src/Entity/TaskLog.php index e446d43..1b7a31a 100644 --- a/src/Entity/TaskLog.php +++ b/src/Entity/TaskLog.php @@ -63,7 +63,7 @@ class TaskLog /** @var Collection */ #[ORM\OneToMany(mappedBy: "taskLog", targetEntity: TaskRun::class, cascade: ["remove"], orphanRemoval: true)] - #[ORM\OrderBy(["timeStarted" => "asc"])] + #[ORM\OrderBy(["timeStarted" => "ASC"])] public private(set) Collection $runs; /** diff --git a/src/TaskManagerBundle.php b/src/TaskManagerBundle.php index 190d4d9..b8f8910 100644 --- a/src/TaskManagerBundle.php +++ b/src/TaskManagerBundle.php @@ -8,7 +8,6 @@ use Torr\TaskManager\DependencyInjection\AutoDetectFailureTransportsCompilerPass; use Torr\TaskManager\DependencyInjection\FindTaskClassesCompilerPass; use Torr\TaskManager\DependencyInjection\TaskManagerBundleExtension; -use Torr\TaskManager\Task\Task; final class TaskManagerBundle extends Bundle { @@ -28,9 +27,6 @@ public function build (ContainerBuilder $container) : void $container ->addCompilerPass(new AutoDetectFailureTransportsCompilerPass()) ->addCompilerPass(new FindTaskClassesCompilerPass()); - - $container->registerForAutoconfiguration(Task::class) - ->addTag("task-manager.task"); } /**