cronos-bundle icon indicating copy to clipboard operation
cronos-bundle copied to clipboard

Symfony 5.3 LazyCommands are not parsed

Open ericabouaf opened this issue 3 years ago • 2 comments

The @Cron annotations are not parsed on LazyCommands.

Cf. https://symfony.com/blog/new-in-symfony-5-3-lazy-command-description

ericabouaf avatar Jul 08 '21 10:07 ericabouaf

The fix above is working, but it is certainly not be the best way to fix this issue...

In https://github.com/mybuilder/cronos-bundle/blob/3.1.2/Command/CommandBase.php#L61, we use the Symfony application to fetch all commands : $commands = $this->getApplication()->all().

Since it may now return LazyCommand instead of our commands, shouldn't cronos-bundle discover itself the Commands class ?

ericabouaf avatar Jul 08 '21 10:07 ericabouaf

my workaround:

Exporter/AnnotationCronExporter.php

...
use Symfony\Component\Console\Command\LazyCommand;
...
public function export(array $commands, array $options): CronFormatter
{
	$cron = $this->createCronConfiguration();

	foreach ($commands as $command) {
		if ($command instanceof LazyCommand) {
			$command = $command->getCommand();
		}
		if ($command instanceof Command) {
			$cron = $this->parseAnnotations($cron, $command, $options);
		}
	}

	return $cron;
}
...

c33s avatar Jun 27 '22 21:06 c33s