I have a console application with Symfony 2, the script run on cron (terminal). But, after \Doctrine\DBAL\DBALException the script throw N \Doctrine\ORM\ORMException with message "The EntityManager is closed.".
This is partial of script:
try {
    $this->getDoctrine()->getConnection()->beginTransaction();
    // ...
    $manager = $this->getDoctrine()->getManager();
    $entity = new Post();
    $entity
        ->setAuthor($author)
        ->setTitle($title)
        ->setContent($content)
    ;
    $manager->persist($entity);
    $manager->flush();
    $this->getDoctrine()->getConnection()->commit();
    return $entity->getId();
} catch (\Doctrine\DBAL\DBALException $e) {
    $this->getDoctrine()->resetManager();
    $output->writeln(sprintf(
        '<error>[!] %s (%s) the post could not be created "%s"</error>',
        get_class($e),
        date('Y-m-d H:i:s'),
        $e->getMessage()
    ));
    return false;
} catch (\Exception $e) {
    $this->getDoctrine()->getConnection()->rollback();
    $output->writeln(sprintf(
        '<error>[!] %s (%s) the post could not be created "%s"</error>',
        get_class($e),
        date('Y-m-d H:i:s'),
        $e->getMessage()
    ));
    return false;
}
How to fix it?
 
     
     
    