Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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();
    }
  • Loading branch information...
commit ac291fa9eabf2efbd038b49f037b82b908431a3f 1 parent 377b7e1
@fabpot fabpot authored
Showing with 10 additions and 1 deletion.
  1. +10 −1 Registry.php
View
11 Registry.php
@@ -103,7 +103,16 @@ public function getEntityManager($name = null)
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;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.