private function getArticle($articleNumber) { try { $article = $this->orm->getRepository('Newscoop\\Package\\Article')->findOneBy(array('id' => $articleNumber)); } catch (\Exception $e) { if ($e->getCode() === '42S02') { $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->orm); try { $schemaTool->createSchema(array($this->orm->getClassMetadata('Newscoop\\Package\\Article'))); } catch (\Exception $e) { } $article = null; } else { throw $e; } } if ($article === null) { $article = new Article($articleNumber); $this->orm->persist($article); $this->orm->flush($article); } return $article; }