This works on controllers, however, it doesn't work when injected to a command.
public function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getDoctrine()->getManager();
try {
$task = new Task();
$task->setSubject("Test subject");
$task->setCreatedAt(new \DateTime());
$em->persist($task);
$em->flush();
} catch (\Exception $e) {
throw $e; //no error
}
//prints successful here
}
/**
* @param string $entityName
* @return \Doctrine\Common\Persistence\ObjectRepository
*/
protected function getRepository($entityName)
{
return $this->getDoctrine()->getRepository($entityName);
}
protected function getDoctrine()
{
return $this->getContainer()->get('doctrine');
}
The cron is successfully picking it up until the end but it doesn't throw any error or save the entity.