From 6e6e33393d28a820b154a6dd1104c43739d045a9 Mon Sep 17 00:00:00 2001 From: balabis Date: Mon, 6 Apr 2020 11:05:17 +0300 Subject: [PATCH 1/9] Added: ability to pass entity manager name to use --- .../DependencyInjection/Configuration.php | 3 +++ .../DependencyInjection/EnqueueExtension.php | 5 +++++ pkg/enqueue-bundle/Resources/config/job.yml | 1 + pkg/job-queue/Doctrine/JobStorage.php | 17 +++++++++++++---- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pkg/enqueue-bundle/DependencyInjection/Configuration.php b/pkg/enqueue-bundle/DependencyInjection/Configuration.php index 3b6367fda..0bd6bb378 100644 --- a/pkg/enqueue-bundle/DependencyInjection/Configuration.php +++ b/pkg/enqueue-bundle/DependencyInjection/Configuration.php @@ -94,6 +94,9 @@ private function getJobConfiguration(): ArrayNodeDefinition } return (new ArrayNodeDefinition('job')) + ->children() + ->scalarNode('entity_manager_name')->defaultNull()->end() + ->end() ->addDefaultsIfNotSet() ->canBeEnabled() ; diff --git a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php index 10521b3a0..e45fac7bb 100644 --- a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php +++ b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php @@ -98,6 +98,11 @@ public function load(array $configs, ContainerBuilder $container): void throw new \LogicException('Job-queue supports only default configuration.'); } + $container->setParameter( + 'enqueue.job.entity_manager_name', + $modules['job']['entity_manager_name'] + ); + $loader->load('job.yml'); } diff --git a/pkg/enqueue-bundle/Resources/config/job.yml b/pkg/enqueue-bundle/Resources/config/job.yml index 0a368aebc..541fc13cf 100644 --- a/pkg/enqueue-bundle/Resources/config/job.yml +++ b/pkg/enqueue-bundle/Resources/config/job.yml @@ -9,6 +9,7 @@ services: - '@doctrine' - 'Enqueue\JobQueue\Doctrine\Entity\Job' - '%enqueue.job.unique_job_table_name%' + - '%enqueue.job.entity_manager_name%' # Deprecated. To be removed in 0.10. enqueue.job.storage: diff --git a/pkg/job-queue/Doctrine/JobStorage.php b/pkg/job-queue/Doctrine/JobStorage.php index 32e20fe8d..bf86a9ae1 100644 --- a/pkg/job-queue/Doctrine/JobStorage.php +++ b/pkg/job-queue/Doctrine/JobStorage.php @@ -38,16 +38,23 @@ class JobStorage */ private $uniqueTableName; + /** + * @var string + */ + private $entityManagerName; + /** * @param ManagerRegistry $doctrine - * @param string $entityClass - * @param string $uniqueTableName + * @param string $entityClass + * @param string $uniqueTableName + * @param $entityManagerName */ - public function __construct(ManagerRegistry $doctrine, $entityClass, $uniqueTableName) + public function __construct(ManagerRegistry $doctrine, $entityClass, $uniqueTableName, $entityManagerName) { $this->doctrine = $doctrine; $this->entityClass = $entityClass; $this->uniqueTableName = $uniqueTableName; + $this->entityManagerName = $entityManagerName; } /** @@ -210,7 +217,9 @@ private function getEntityRepository() private function getEntityManager() { if (!$this->em) { - $this->em = $this->doctrine->getManagerForClass($this->entityClass); + $this->em = empty($this->entityManagerName) + ? $this->doctrine->getManagerForClass($this->entityClass) + : $this->doctrine->getManager($this->entityManagerName); } if (!$this->em->isOpen()) { $this->em = $this->doctrine->resetManager(); From 426aea9b2042161e0ff2fec123b7bc4405bd7bcc Mon Sep 17 00:00:00 2001 From: balabis Date: Mon, 6 Apr 2020 11:21:21 +0300 Subject: [PATCH 2/9] Changed: documentation --- docs/bundle/config_reference.md | 1 + docs/bundle/job_queue.md | 16 ++++------------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/docs/bundle/config_reference.md b/docs/bundle/config_reference.md index d27877765..eaa3fafc9 100644 --- a/docs/bundle/config_reference.md +++ b/docs/bundle/config_reference.md @@ -67,6 +67,7 @@ enqueue: queue_name: ~ job: enabled: false + entity_manager_name: ~ async_events: enabled: false extensions: diff --git a/docs/bundle/job_queue.md b/docs/bundle/job_queue.md index eb1e25281..59b1b15d6 100644 --- a/docs/bundle/job_queue.md +++ b/docs/bundle/job_queue.md @@ -60,18 +60,10 @@ enqueue: # plus basic bundle configuration job: true - -doctrine: - # plus basic bundle configuration - - orm: - mappings: - EnqueueJobQueue: - is_bundle: false - type: xml - dir: '%kernel.project_dir%/vendor/enqueue/job-queue/Doctrine/mapping' - prefix: 'Enqueue\JobQueue\Doctrine\Entity' - + + # by default bundle will add a default orm mapping configuration + # if you define custom mappings, you can specify which entity manager to use here + entity_manager_name: ~ ``` * Run doctrine schema update command From d48103dc5f1a34c32483b79740368d0a0758366f Mon Sep 17 00:00:00 2001 From: balabis Date: Mon, 6 Apr 2020 11:27:39 +0300 Subject: [PATCH 3/9] Fixed: cs --- .../DoctrineClearIdentityMapExtension.php | 3 -- .../Tests/Functional/App/AppKernel.php | 3 -- .../CalculateRootJobStatusService.php | 11 +---- pkg/job-queue/DependentJobContext.php | 3 -- pkg/job-queue/DependentJobProcessor.php | 5 -- pkg/job-queue/DependentJobService.php | 10 +--- pkg/job-queue/Doctrine/JobStorage.php | 17 +------ pkg/job-queue/Job.php | 9 ---- pkg/job-queue/JobProcessor.php | 46 ++----------------- pkg/job-queue/JobRunner.php | 20 +++----- .../Test/DbalPersistedConnection.php | 3 -- .../Tests/Functional/app/AppKernel.php | 3 -- 12 files changed, 14 insertions(+), 119 deletions(-) diff --git a/pkg/enqueue-bundle/Consumption/Extension/DoctrineClearIdentityMapExtension.php b/pkg/enqueue-bundle/Consumption/Extension/DoctrineClearIdentityMapExtension.php index a8f258f21..e88076819 100644 --- a/pkg/enqueue-bundle/Consumption/Extension/DoctrineClearIdentityMapExtension.php +++ b/pkg/enqueue-bundle/Consumption/Extension/DoctrineClearIdentityMapExtension.php @@ -13,9 +13,6 @@ class DoctrineClearIdentityMapExtension implements MessageReceivedExtensionInter */ protected $registry; - /** - * @param ManagerRegistry $registry - */ public function __construct(ManagerRegistry $registry) { $this->registry = $registry; diff --git a/pkg/enqueue-bundle/Tests/Functional/App/AppKernel.php b/pkg/enqueue-bundle/Tests/Functional/App/AppKernel.php index e484f0bfd..49ae1c605 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/AppKernel.php +++ b/pkg/enqueue-bundle/Tests/Functional/App/AppKernel.php @@ -37,9 +37,6 @@ public function getLogDir() return sys_get_temp_dir().'/EnqueueBundle/cache/logs'; } - /** - * @param \Symfony\Component\Config\Loader\LoaderInterface $loader - */ public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load(__DIR__.'/config/config.yml'); diff --git a/pkg/job-queue/CalculateRootJobStatusService.php b/pkg/job-queue/CalculateRootJobStatusService.php index af4631e2a..4268158b1 100644 --- a/pkg/job-queue/CalculateRootJobStatusService.php +++ b/pkg/job-queue/CalculateRootJobStatusService.php @@ -12,17 +12,12 @@ class CalculateRootJobStatusService */ private $jobStorage; - /** - * @param JobStorage $jobStorage - */ public function __construct(JobStorage $jobStorage) { $this->jobStorage = $jobStorage; } /** - * @param Job $job - * * @return bool true if root job was stopped */ public function calculate(Job $job) @@ -91,11 +86,7 @@ protected function calculateRootJobStatus(array $jobs) $success++; break; default: - throw new \LogicException(sprintf( - 'Got unsupported job status: id: "%s" status: "%s"', - $job->getId(), - $job->getStatus() - )); + throw new \LogicException(sprintf('Got unsupported job status: id: "%s" status: "%s"', $job->getId(), $job->getStatus())); } } diff --git a/pkg/job-queue/DependentJobContext.php b/pkg/job-queue/DependentJobContext.php index 34deba656..04b898fd3 100644 --- a/pkg/job-queue/DependentJobContext.php +++ b/pkg/job-queue/DependentJobContext.php @@ -14,9 +14,6 @@ class DependentJobContext */ private $dependentJobs; - /** - * @param Job $job - */ public function __construct(Job $job) { $this->job = $job; diff --git a/pkg/job-queue/DependentJobProcessor.php b/pkg/job-queue/DependentJobProcessor.php index 6126be08f..4916c7031 100644 --- a/pkg/job-queue/DependentJobProcessor.php +++ b/pkg/job-queue/DependentJobProcessor.php @@ -30,11 +30,6 @@ class DependentJobProcessor implements Processor, TopicSubscriberInterface */ private $logger; - /** - * @param JobStorage $jobStorage - * @param ProducerInterface $producer - * @param LoggerInterface $logger - */ public function __construct(JobStorage $jobStorage, ProducerInterface $producer, LoggerInterface $logger) { $this->jobStorage = $jobStorage; diff --git a/pkg/job-queue/DependentJobService.php b/pkg/job-queue/DependentJobService.php index b6066d669..9ab500ba8 100644 --- a/pkg/job-queue/DependentJobService.php +++ b/pkg/job-queue/DependentJobService.php @@ -20,8 +20,6 @@ public function __construct(JobStorage $jobStorage) } /** - * @param Job $job - * * @return DependentJobContext */ public function createDependentJobContext(Job $job) @@ -29,16 +27,10 @@ public function createDependentJobContext(Job $job) return new DependentJobContext($job); } - /** - * @param DependentJobContext $context - */ public function saveDependentJob(DependentJobContext $context) { if (!$context->getJob()->isRoot()) { - throw new \LogicException(sprintf( - 'Only root jobs allowed but got child. jobId: "%s"', - $context->getJob()->getId() - )); + throw new \LogicException(sprintf('Only root jobs allowed but got child. jobId: "%s"', $context->getJob()->getId())); } $this->jobStorage->saveJob($context->getJob(), function (Job $job) use ($context) { diff --git a/pkg/job-queue/Doctrine/JobStorage.php b/pkg/job-queue/Doctrine/JobStorage.php index bf86a9ae1..5de408138 100644 --- a/pkg/job-queue/Doctrine/JobStorage.php +++ b/pkg/job-queue/Doctrine/JobStorage.php @@ -44,7 +44,6 @@ class JobStorage private $entityManagerName; /** - * @param ManagerRegistry $doctrine * @param string $entityClass * @param string $uniqueTableName * @param $entityManagerName @@ -97,7 +96,6 @@ public function findRootJobByOwnerIdAndJobName($ownerId, $jobName) /** * @param string $name - * @param Job $rootJob * * @return Job */ @@ -126,20 +124,13 @@ public function createJob() } /** - * @param Job $job - * @param \Closure|null $lockCallback - * * @throws DuplicateJobException */ public function saveJob(Job $job, \Closure $lockCallback = null) { $class = $this->getEntityRepository()->getClassName(); if (!$job instanceof $class) { - throw new \LogicException(sprintf( - 'Got unexpected job instance: expected: "%s", actual" "%s"', - $class, - get_class($job) - )); + throw new \LogicException(sprintf('Got unexpected job instance: expected: "%s", actual" "%s"', $class, get_class($job))); } if ($lockCallback) { @@ -182,11 +173,7 @@ public function saveJob(Job $job, \Closure $lockCallback = null) ]); } } catch (UniqueConstraintViolationException $e) { - throw new DuplicateJobException(sprintf( - 'Duplicate job. ownerId:"%s", name:"%s"', - $job->getOwnerId(), - $job->getName() - )); + throw new DuplicateJobException(sprintf('Duplicate job. ownerId:"%s", name:"%s"', $job->getOwnerId(), $job->getName())); } $this->getEntityManager()->persist($job); diff --git a/pkg/job-queue/Job.php b/pkg/job-queue/Job.php index 0468d7fdb..ef0c42c4e 100644 --- a/pkg/job-queue/Job.php +++ b/pkg/job-queue/Job.php @@ -237,8 +237,6 @@ public function getCreatedAt() * Do not call from the outside. * * @internal - * - * @param \DateTime $createdAt */ public function setCreatedAt(\DateTime $createdAt) { @@ -258,8 +256,6 @@ public function getStartedAt() * Do not call from the outside. * * @internal - * - * @param \DateTime $startedAt */ public function setStartedAt(\DateTime $startedAt) { @@ -279,8 +275,6 @@ public function getStoppedAt() * Do not call from the outside. * * @internal - * - * @param \DateTime $stoppedAt */ public function setStoppedAt(\DateTime $stoppedAt) { @@ -324,9 +318,6 @@ public function getData() return $this->data; } - /** - * @param array $data - */ public function setData(array $data) { $this->data = $data; diff --git a/pkg/job-queue/JobProcessor.php b/pkg/job-queue/JobProcessor.php index 8f197f742..06698f45c 100644 --- a/pkg/job-queue/JobProcessor.php +++ b/pkg/job-queue/JobProcessor.php @@ -17,10 +17,6 @@ class JobProcessor */ private $producer; - /** - * @param JobStorage $jobStorage - * @param ProducerInterface $producer - */ public function __construct(JobStorage $jobStorage, ProducerInterface $producer) { $this->jobStorage = $jobStorage; @@ -74,7 +70,6 @@ public function findOrCreateRootJob($ownerId, $jobName, $unique = false) /** * @param string $jobName - * @param Job $rootJob * * @return Job */ @@ -104,9 +99,6 @@ public function findOrCreateChildJob($jobName, Job $rootJob) return $job; } - /** - * @param Job $job - */ public function startChildJob(Job $job) { if ($job->isRoot()) { @@ -116,11 +108,7 @@ public function startChildJob(Job $job) $job = $this->jobStorage->findJobById($job->getId()); if (Job::STATUS_NEW !== $job->getStatus()) { - throw new \LogicException(sprintf( - 'Can start only new jobs: id: "%s", status: "%s"', - $job->getId(), - $job->getStatus() - )); + throw new \LogicException(sprintf('Can start only new jobs: id: "%s", status: "%s"', $job->getId(), $job->getStatus())); } $job->setStatus(Job::STATUS_RUNNING); @@ -131,9 +119,6 @@ public function startChildJob(Job $job) $this->sendCalculateRootJobStatusEvent($job); } - /** - * @param Job $job - */ public function successChildJob(Job $job) { if ($job->isRoot()) { @@ -143,11 +128,7 @@ public function successChildJob(Job $job) $job = $this->jobStorage->findJobById($job->getId()); if (Job::STATUS_RUNNING !== $job->getStatus()) { - throw new \LogicException(sprintf( - 'Can success only running jobs. id: "%s", status: "%s"', - $job->getId(), - $job->getStatus() - )); + throw new \LogicException(sprintf('Can success only running jobs. id: "%s", status: "%s"', $job->getId(), $job->getStatus())); } $job->setStatus(Job::STATUS_SUCCESS); @@ -158,9 +139,6 @@ public function successChildJob(Job $job) $this->sendCalculateRootJobStatusEvent($job); } - /** - * @param Job $job - */ public function failChildJob(Job $job) { if ($job->isRoot()) { @@ -170,11 +148,7 @@ public function failChildJob(Job $job) $job = $this->jobStorage->findJobById($job->getId()); if (Job::STATUS_RUNNING !== $job->getStatus()) { - throw new \LogicException(sprintf( - 'Can fail only running jobs. id: "%s", status: "%s"', - $job->getId(), - $job->getStatus() - )); + throw new \LogicException(sprintf('Can fail only running jobs. id: "%s", status: "%s"', $job->getId(), $job->getStatus())); } $job->setStatus(Job::STATUS_FAILED); @@ -185,9 +159,6 @@ public function failChildJob(Job $job) $this->sendCalculateRootJobStatusEvent($job); } - /** - * @param Job $job - */ public function cancelChildJob(Job $job) { if ($job->isRoot()) { @@ -197,11 +168,7 @@ public function cancelChildJob(Job $job) $job = $this->jobStorage->findJobById($job->getId()); if (!in_array($job->getStatus(), [Job::STATUS_NEW, Job::STATUS_RUNNING], true)) { - throw new \LogicException(sprintf( - 'Can cancel only new or running jobs. id: "%s", status: "%s"', - $job->getId(), - $job->getStatus() - )); + throw new \LogicException(sprintf('Can cancel only new or running jobs. id: "%s", status: "%s"', $job->getId(), $job->getStatus())); } $job->setStatus(Job::STATUS_CANCELLED); @@ -217,7 +184,6 @@ public function cancelChildJob(Job $job) } /** - * @param Job $job * @param bool $force */ public function interruptRootJob(Job $job, $force = false) @@ -245,8 +211,6 @@ public function interruptRootJob(Job $job, $force = false) /** * @see https://github.com/php-enqueue/enqueue-dev/pull/222#issuecomment-336102749 See for rationale - * - * @param Job $job */ protected function saveJob(Job $job) { @@ -255,8 +219,6 @@ protected function saveJob(Job $job) /** * @see https://github.com/php-enqueue/enqueue-dev/pull/222#issuecomment-336102749 See for rationale - * - * @param Job $job */ protected function sendCalculateRootJobStatusEvent(Job $job) { diff --git a/pkg/job-queue/JobRunner.php b/pkg/job-queue/JobRunner.php index afd445c67..e8d7eaa27 100644 --- a/pkg/job-queue/JobRunner.php +++ b/pkg/job-queue/JobRunner.php @@ -15,8 +15,7 @@ class JobRunner private $rootJob; /** - * @param JobProcessor $jobProcessor - * @param Job $rootJob + * @param Job $rootJob */ public function __construct(JobProcessor $jobProcessor, Job $rootJob = null) { @@ -25,9 +24,8 @@ public function __construct(JobProcessor $jobProcessor, Job $rootJob = null) } /** - * @param string $ownerId - * @param string $name - * @param callable $runCallback + * @param string $ownerId + * @param string $name * * @throws \Throwable|\Exception if $runCallback triggers an exception * @@ -54,11 +52,7 @@ public function runUnique($ownerId, $name, callable $runCallback) try { $this->jobProcessor->failChildJob($childJob); } catch (\Throwable $t) { - throw new OrphanJobException(sprintf( - 'Job cleanup failed. ID: "%s" Name: "%s"', - $childJob->getId(), - $childJob->getName() - ), 0, $e); + throw new OrphanJobException(sprintf('Job cleanup failed. ID: "%s" Name: "%s"', $childJob->getId(), $childJob->getName()), 0, $e); } throw $e; @@ -74,8 +68,7 @@ public function runUnique($ownerId, $name, callable $runCallback) } /** - * @param string $name - * @param callable $startCallback + * @param string $name * * @return mixed */ @@ -89,8 +82,7 @@ public function createDelayed($name, callable $startCallback) } /** - * @param string $jobId - * @param callable $runCallback + * @param string $jobId * * @return mixed */ diff --git a/pkg/job-queue/Test/DbalPersistedConnection.php b/pkg/job-queue/Test/DbalPersistedConnection.php index f1ec03035..51160c03b 100644 --- a/pkg/job-queue/Test/DbalPersistedConnection.php +++ b/pkg/job-queue/Test/DbalPersistedConnection.php @@ -102,9 +102,6 @@ protected function persistTransactionNestingLevel($level) static::$persistedTransactionNestingLevels[$this->getConnectionId()] = $level; } - /** - * @param DriverConnection $connection - */ protected function persistConnection(DriverConnection $connection) { static::$persistedConnections[$this->getConnectionId()] = $connection; diff --git a/pkg/job-queue/Tests/Functional/app/AppKernel.php b/pkg/job-queue/Tests/Functional/app/AppKernel.php index ce21df0b8..9e6a24812 100644 --- a/pkg/job-queue/Tests/Functional/app/AppKernel.php +++ b/pkg/job-queue/Tests/Functional/app/AppKernel.php @@ -36,9 +36,6 @@ public function getLogDir() return sys_get_temp_dir().'/EnqueueJobQueue/cache/logs'; } - /** - * @param \Symfony\Component\Config\Loader\LoaderInterface $loader - */ public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load(__DIR__.'/config/config.yml'); From 7087ddc57403b5f689a3c2c8b20a8a3afbb03373 Mon Sep 17 00:00:00 2001 From: balabis Date: Mon, 6 Apr 2020 15:50:46 +0300 Subject: [PATCH 4/9] Changed: default param to null --- pkg/job-queue/Doctrine/JobStorage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/job-queue/Doctrine/JobStorage.php b/pkg/job-queue/Doctrine/JobStorage.php index 5de408138..42b39b437 100644 --- a/pkg/job-queue/Doctrine/JobStorage.php +++ b/pkg/job-queue/Doctrine/JobStorage.php @@ -46,9 +46,9 @@ class JobStorage /** * @param string $entityClass * @param string $uniqueTableName - * @param $entityManagerName + * @param mixed $entityManagerName */ - public function __construct(ManagerRegistry $doctrine, $entityClass, $uniqueTableName, $entityManagerName) + public function __construct(ManagerRegistry $doctrine, $entityClass, $uniqueTableName, $entityManagerName = null) { $this->doctrine = $doctrine; $this->entityClass = $entityClass; From 10a0b124819fd0968a61f75c258eafabc94a9e39 Mon Sep 17 00:00:00 2001 From: balabis Date: Tue, 5 May 2020 10:54:48 +0300 Subject: [PATCH 5/9] Changed: use config setting to disable default mapping --- docs/bundle/config_reference.md | 2 +- docs/bundle/job_queue.md | 17 ++++++++++++++--- .../DependencyInjection/Configuration.php | 2 +- .../DependencyInjection/EnqueueExtension.php | 13 ++++++++----- pkg/enqueue-bundle/Resources/config/job.yml | 1 - pkg/job-queue/Doctrine/JobStorage.php | 8 ++------ 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/docs/bundle/config_reference.md b/docs/bundle/config_reference.md index eaa3fafc9..042b93cfa 100644 --- a/docs/bundle/config_reference.md +++ b/docs/bundle/config_reference.md @@ -67,7 +67,7 @@ enqueue: queue_name: ~ job: enabled: false - entity_manager_name: ~ + default_mapping: true async_events: enabled: false extensions: diff --git a/docs/bundle/job_queue.md b/docs/bundle/job_queue.md index 59b1b15d6..464ff0d0a 100644 --- a/docs/bundle/job_queue.md +++ b/docs/bundle/job_queue.md @@ -61,9 +61,20 @@ enqueue: job: true - # by default bundle will add a default orm mapping configuration - # if you define custom mappings, you can specify which entity manager to use here - entity_manager_name: ~ + # if you configure doctrine mapping yourself, disable default mapping + default_mapping: false + +doctrine: + # plus basic bundle configuration + + orm: + mappings: + EnqueueJobQueue: + is_bundle: false + type: xml + dir: '%kernel.project_dir%/vendor/enqueue/job-queue/Doctrine/mapping' + prefix: 'Enqueue\JobQueue\Doctrine\Entity' + ``` * Run doctrine schema update command diff --git a/pkg/enqueue-bundle/DependencyInjection/Configuration.php b/pkg/enqueue-bundle/DependencyInjection/Configuration.php index 0bd6bb378..070851e4e 100644 --- a/pkg/enqueue-bundle/DependencyInjection/Configuration.php +++ b/pkg/enqueue-bundle/DependencyInjection/Configuration.php @@ -95,7 +95,7 @@ private function getJobConfiguration(): ArrayNodeDefinition return (new ArrayNodeDefinition('job')) ->children() - ->scalarNode('entity_manager_name')->defaultNull()->end() + ->booleanNode('default_mapping')->defaultTrue()->end() ->end() ->addDefaultsIfNotSet() ->canBeEnabled() diff --git a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php index e45fac7bb..cc6c0500c 100644 --- a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php +++ b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php @@ -98,11 +98,6 @@ public function load(array $configs, ContainerBuilder $container): void throw new \LogicException('Job-queue supports only default configuration.'); } - $container->setParameter( - 'enqueue.job.entity_manager_name', - $modules['job']['entity_manager_name'] - ); - $loader->load('job.yml'); } @@ -176,6 +171,14 @@ private function registerJobQueueDoctrineEntityMapping(ContainerBuilder $contain return; } + foreach ($container->getExtensionConfig('enqueue') as $modules) { + foreach ($modules as $config) { + if (isset($config['job']) && false === $config['job']['default_mapping']) { + return; + } + } + } + foreach ($container->getExtensionConfig('doctrine') as $config) { // do not register mappings if dbal not configured. if (!empty($config['dbal'])) { diff --git a/pkg/enqueue-bundle/Resources/config/job.yml b/pkg/enqueue-bundle/Resources/config/job.yml index 541fc13cf..0a368aebc 100644 --- a/pkg/enqueue-bundle/Resources/config/job.yml +++ b/pkg/enqueue-bundle/Resources/config/job.yml @@ -9,7 +9,6 @@ services: - '@doctrine' - 'Enqueue\JobQueue\Doctrine\Entity\Job' - '%enqueue.job.unique_job_table_name%' - - '%enqueue.job.entity_manager_name%' # Deprecated. To be removed in 0.10. enqueue.job.storage: diff --git a/pkg/job-queue/Doctrine/JobStorage.php b/pkg/job-queue/Doctrine/JobStorage.php index 42b39b437..89a79ac44 100644 --- a/pkg/job-queue/Doctrine/JobStorage.php +++ b/pkg/job-queue/Doctrine/JobStorage.php @@ -46,14 +46,12 @@ class JobStorage /** * @param string $entityClass * @param string $uniqueTableName - * @param mixed $entityManagerName */ - public function __construct(ManagerRegistry $doctrine, $entityClass, $uniqueTableName, $entityManagerName = null) + public function __construct(ManagerRegistry $doctrine, $entityClass, $uniqueTableName) { $this->doctrine = $doctrine; $this->entityClass = $entityClass; $this->uniqueTableName = $uniqueTableName; - $this->entityManagerName = $entityManagerName; } /** @@ -204,9 +202,7 @@ private function getEntityRepository() private function getEntityManager() { if (!$this->em) { - $this->em = empty($this->entityManagerName) - ? $this->doctrine->getManagerForClass($this->entityClass) - : $this->doctrine->getManager($this->entityManagerName); + $this->em = $this->doctrine->getManagerForClass($this->entityClass); } if (!$this->em->isOpen()) { $this->em = $this->doctrine->resetManager(); From 7cbc437ed0f09eb067c785a4adf8d98076e30256 Mon Sep 17 00:00:00 2001 From: balabis Date: Thu, 20 Aug 2020 10:04:11 +0300 Subject: [PATCH 6/9] Removed: unused variable Changed: job queue documentation --- docs/bundle/job_queue.md | 5 +++-- pkg/job-queue/Doctrine/JobStorage.php | 5 ----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/docs/bundle/job_queue.md b/docs/bundle/job_queue.md index 464ff0d0a..cd13ca3cd 100644 --- a/docs/bundle/job_queue.md +++ b/docs/bundle/job_queue.md @@ -61,8 +61,9 @@ enqueue: job: true - # if you configure doctrine mapping yourself, disable default mapping - default_mapping: false + # adds bundle's default Job entity mapping to application's entity manager. + # set it to false when using your own mapped entities for jobs. + default_mapping: true doctrine: # plus basic bundle configuration diff --git a/pkg/job-queue/Doctrine/JobStorage.php b/pkg/job-queue/Doctrine/JobStorage.php index 89a79ac44..1ba6aab33 100644 --- a/pkg/job-queue/Doctrine/JobStorage.php +++ b/pkg/job-queue/Doctrine/JobStorage.php @@ -38,11 +38,6 @@ class JobStorage */ private $uniqueTableName; - /** - * @var string - */ - private $entityManagerName; - /** * @param string $entityClass * @param string $uniqueTableName From 200964cbc35b747eaf3a88cd312bac83ca47082e Mon Sep 17 00:00:00 2001 From: balabis Date: Thu, 20 Aug 2020 11:38:43 +0300 Subject: [PATCH 7/9] Added: additional information in bundle configuration --- pkg/enqueue-bundle/DependencyInjection/Configuration.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/enqueue-bundle/DependencyInjection/Configuration.php b/pkg/enqueue-bundle/DependencyInjection/Configuration.php index 070851e4e..733849d35 100644 --- a/pkg/enqueue-bundle/DependencyInjection/Configuration.php +++ b/pkg/enqueue-bundle/DependencyInjection/Configuration.php @@ -95,7 +95,10 @@ private function getJobConfiguration(): ArrayNodeDefinition return (new ArrayNodeDefinition('job')) ->children() - ->booleanNode('default_mapping')->defaultTrue()->end() + ->booleanNode('default_mapping') + ->defaultTrue() + ->info('Adds bundle\'s default Job entity mapping to application\'s entity manager') + ->end() ->end() ->addDefaultsIfNotSet() ->canBeEnabled() From 286834d442cc343a4c95a59c6db52ed1151f1274 Mon Sep 17 00:00:00 2001 From: balabis Date: Tue, 8 Sep 2020 10:00:34 +0300 Subject: [PATCH 8/9] Changed: use merged configuration --- .../DependencyInjection/EnqueueExtension.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php index cc6c0500c..64d59db71 100644 --- a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php +++ b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php @@ -171,11 +171,14 @@ private function registerJobQueueDoctrineEntityMapping(ContainerBuilder $contain return; } - foreach ($container->getExtensionConfig('enqueue') as $modules) { - foreach ($modules as $config) { - if (isset($config['job']) && false === $config['job']['default_mapping']) { - return; - } + $config = $this->processConfiguration( + new Configuration(false), + $container->getExtensionConfig('enqueue') + ); + + foreach ($config as $name => $modules) { + if (isset($modules['job']) && false === $modules['job']['default_mapping']) { + return; } } From 0fbfc4de1338f0fb7a622653940d4e59e904837b Mon Sep 17 00:00:00 2001 From: balabis Date: Tue, 8 Sep 2020 10:44:58 +0300 Subject: [PATCH 9/9] Fixed: failing test --- .../DependencyInjection/EnqueueExtension.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php index 64d59db71..c5dbbbc96 100644 --- a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php +++ b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php @@ -171,14 +171,15 @@ private function registerJobQueueDoctrineEntityMapping(ContainerBuilder $contain return; } - $config = $this->processConfiguration( - new Configuration(false), - $container->getExtensionConfig('enqueue') - ); + $config = $container->getExtensionConfig('enqueue'); - foreach ($config as $name => $modules) { - if (isset($modules['job']) && false === $modules['job']['default_mapping']) { - return; + if (!empty($config)) { + $processedConfig = $this->processConfiguration(new Configuration(false), $config); + + foreach ($processedConfig as $name => $modules) { + if (isset($modules['job']) && false === $modules['job']['default_mapping']) { + return; + } } }