/** * {@inheritDoc} */ public function registerJob($jobName, array $config) { try { foreach (array("command", "schedule") as $field) { if (empty($config[$field])) { throw new \Exception("'{$field}' is required for '{$jobName}' job"); } } $jobByCommand = $this->em->getRepository('Newscoop\\Entity\\CronJob')->findOneByCommand($config['command']); if (!$jobByCommand) { $cronJob = new CronJob(); foreach ($config as $key => $value) { $setter = "set" . ucfirst($key); $cronJob->{$setter}($value); } $cronJob->setName($jobName); $this->em->persist($cronJob); $this->em->flush($cronJob); } } catch (\Exception $e) { throw new \Exception("Could not register job: '{$jobName}'", 0, $e); } }