diff --git a/packages/cron-job/CronJobProcessor.php b/packages/cron-job/CronJobProcessor.php index 213bed82..f23ef489 100644 --- a/packages/cron-job/CronJobProcessor.php +++ b/packages/cron-job/CronJobProcessor.php @@ -4,6 +4,7 @@ namespace Draw\Component\CronJob; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\ManagerRegistry; use Draw\Component\CronJob\Entity\CronJob; use Draw\Component\CronJob\Entity\CronJobExecution; @@ -40,6 +41,8 @@ public function process(CronJobExecution $execution): void { $manager = $this->managerRegistry->getManagerForClass(CronJobExecution::class); + \assert($manager instanceof EntityManagerInterface); + if (!$execution->isExecutable(new \DateTimeImmutable())) { $execution->skip(); $manager->flush(); @@ -59,6 +62,10 @@ public function process(CronJobExecution $execution): void $execution->start(); $manager->flush(); + // This allows long process cron to release connection + // Also allow issue with server "gone away" to be resolved + $manager->getConnection()->close(); + $process = $this->processFactory->createFromShellCommandLine( $this->parameterBag->resolveValue( $event->getCommand() diff --git a/packages/cron-job/Tests/CronJobProcessorTest.php b/packages/cron-job/Tests/CronJobProcessorTest.php index fa0daa9f..c1aa8709 100644 --- a/packages/cron-job/Tests/CronJobProcessorTest.php +++ b/packages/cron-job/Tests/CronJobProcessorTest.php @@ -4,6 +4,7 @@ namespace Draw\Component\CronJob\Tests; +use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\ManagerRegistry; use Draw\Component\CronJob\CronJobProcessor; @@ -130,6 +131,17 @@ public function testProcess( ->expects(static::exactly(2)) ->method('flush'); + $this->entityManager + ->expects(static::once()) + ->method('getConnection') + ->willReturn( + $connection = $this->createMock(Connection::class) + ); + + $connection + ->expects(static::once()) + ->method('close'); + $this->processFactory ->expects(static::once()) ->method('createFromShellCommandLine') @@ -197,6 +209,17 @@ public function testProcessWithError(): void ->expects(static::exactly(2)) ->method('flush'); + $this->entityManager + ->expects(static::once()) + ->method('getConnection') + ->willReturn( + $connection = $this->createMock(Connection::class) + ); + + $connection + ->expects(static::once()) + ->method('close'); + $process = $this->createMock(Process::class); $process ->expects(static::any()) diff --git a/packages/sonata-extra-bundle/Resources/views/CRUD/show_grid.html.twig b/packages/sonata-extra-bundle/Resources/views/CRUD/show_grid.html.twig index 836ad474..11901b83 100644 --- a/packages/sonata-extra-bundle/Resources/views/CRUD/show_grid.html.twig +++ b/packages/sonata-extra-bundle/Resources/views/CRUD/show_grid.html.twig @@ -12,7 +12,17 @@ {% for field in field_description.options.fields %} {% if field.type != 'grid' %} {% set colCount = colCount +1 %} - {{ field.label }} + + {% apply spaceless %} + {% if field.label is not same as(false) %} + {% if field.translationDomain is same as(false) %} + {{ field.label }} + {% else %} + {{ field.label|trans({}, field.translationDomain) }} + {% endif %} + {% endif %} + {% endapply %} + {% endif %} {% endfor %}