Exemplo n.º 1
0
 public function load(ObjectManager $manager)
 {
     $entity = new CronTask();
     $entity->setName('Example router debug task')->setInterval(60)->setCommands(array('router:debug'));
     $manager->persist($entity);
     $manager->flush();
 }
Exemplo n.º 2
0
 /**
  * Send the current temperature to the specified email address in every hour
  * Method: POST
  * -----------
  * @Rest\View
  * @Route("/api/subscribe_temperature")
  */
 public function postSubscribeTemperatureAction()
 {
     //$to comes from POST
     $entity = new Email();
     $form = $this->createForm(new RestEmailType(), $entity);
     $form->handleRequest($this->getRequest());
     $data = array('code' => 400, 'status' => 'Bad request.');
     if ($form->isValid()) {
         try {
             $em = $this->getDoctrine()->getManager();
             if ($this->isEmailUnique($em, $entity->getTo())) {
                 $em->persist($entity);
                 $cronEntity = new CronTask();
                 $cronEntity->setName($entity->getTo())->setTaskInterval(3600)->setLastRun(new \DateTime());
                 $em->persist($cronEntity);
                 $em->flush();
                 $this->sendEmail($entity->getTo(), $this->emailMsgFactory($entity->getTo(), "subscribing to"));
                 $data["code"] = 200;
                 $data["status"] = "OK";
             } else {
                 $data["code"] = 422;
                 $data["status"] = "There's already a subscription with the given email address!";
             }
         } catch (Excpetion $e) {
             $data["code"] = 500;
             $data["status"] = "Server error! Subscription failed!.";
         }
     }
     return new Response(json_encode(array("status" => $data["status"])), $data["code"], array('Content-Type' => 'application/json'));
 }
Exemplo n.º 3
0
 public function load(ObjectManager $manager)
 {
     $cronTask = new CronTask();
     $cronTask->setName('Example')->setCommands(['cache:clear'])->setRunInterval(3600);
     $manager->persist($cronTask);
     $manager->flush();
 }