Kaynağa Gözat

[DoctrineBundle] changed the Registry to return a new instance if the current em is closed

    $em = $this->get('doctrine')->getEntityManager();

    $em->getConnection()->beginTransaction(); // suspend auto-commit
    try {
        //... do some work
    } catch (Exception $e) {
        $em->getConnection()->rollback();
        $em->close();

        // get a new EM
        $em = $this->get('doctrine')->getEntityManager();
    }
Fabien Potencier 14 yıl önce
ebeveyn
işleme
014b19040c
1 değiştirilmiş dosya ile 10 ekleme ve 1 silme
  1. 10 1
      src/Symfony/Bundle/DoctrineBundle/Registry.php

+ 10 - 1
src/Symfony/Bundle/DoctrineBundle/Registry.php

@@ -103,7 +103,16 @@ class Registry
             throw new \InvalidArgumentException(sprintf('Doctrine EntityManager named "%s" does not exist.', $name));
         }
 
-        return $this->container->get($this->entityManagers[$name]);
+        $em = $this->container->get($this->entityManagers[$name]);
+
+        if (!$em->isOpen()) {
+            // force the creation of a new entity manager
+            // if the current one is closed
+            $this->container->set($this->entityManagers[$name], null);
+            $em = $this->container->get($this->entityManagers[$name]);
+        }
+
+        return $em;
     }
 
     /**