Skip to content

Commit

Permalink
feat: reset the entity manager if the connection is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
gsdevme authored and kardi31 committed Jan 27, 2020
1 parent e097b4a commit dc988cb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Repository/JobLogRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use Markup\JobQueueBundle\Entity\JobLog;
Expand Down Expand Up @@ -195,7 +196,7 @@ public function save(JobLog $jobLog): void

private function getEntityRepository(): EntityRepository
{
$repository = $this->doctrine->getRepository(JobLog::class);
$repository = $this->getEntityManager()->getRepository(JobLog::class);

if ($repository instanceof EntityRepository) {
return $repository;
Expand All @@ -207,6 +208,11 @@ private function getEntityRepository(): EntityRepository
private function getEntityManager(): EntityManager
{
$manager = $this->doctrine->getManager();

if ($manager instanceof EntityManagerInterface && !$manager->isOpen()) {
$manager = $this->doctrine->resetManager();
}

if ($manager instanceof EntityManager) {
return $manager;
}
Expand Down

0 comments on commit dc988cb

Please sign in to comment.