public function newOperationByActivity(Activity $activity, $bundleName, $moduleIdentifier) { $operationModule = $this->getOperationModule($bundleName, $moduleIdentifier); $operation = new Operation(); $operation->setName($activity->getName()); $operation->setStartDate($activity->getStartDate()); $operation->setEndDate($activity->getEndDate()); $operation->setTriggerHook($activity->getTriggerHook()); $operation->setActivity($activity); $activity->addOperation($operation); $operationModule->addOperation($operation); $operation->setOperationModule($operationModule); return $operation; }
public function editActivity(Activity $activity, Form $form, $content) { /** @var ActivityService $activityService */ $activityService = $this->get('campaignchain.core.activity'); /** @var Operation $operation */ $operation = $activityService->getOperation($activity->getId()); $em = $this->getDoctrine()->getManager(); // Make sure that data stays intact by using transactions. try { $em->getConnection()->beginTransaction(); if ($this->handler->hasContent('edit')) { // Get the content data from request. $content = $this->handler->processContent($operation, $form->get($this->contentModuleFormName)->getData()); if ($this->parameters['equals_operation']) { // The activity equals the operation. Thus, we update the operation with the same data. $operation->setName($activity->getName()); $em->persist($operation); } else { throw new \Exception('Multiple Operations for one Activity not implemented yet.'); } $em->persist($content); } $hookService = $this->get('campaignchain.core.hook'); /** @var Activity $activity */ $activity = $hookService->processHooks($this->activityBundleName, $this->activityModuleIdentifier, $activity, $form); // Check if the content can be executed. if (isset($this->validators['operations'])) { $isExecutable = $this->validators['operations'][0]->isExecutableByLocation($content, $activity->getStartDate()); if (!$isExecutable['status']) { throw new \Exception($isExecutable['message']); } $activity->setMustValidate($this->validators['operations'][0]->mustValidate($content, $activity->getStartDate())); } $em->persist($activity); $em->flush(); // The module tries to execute the job immediately. $this->handler->postPersistEditEvent($this->operations[0], $form, $content); $em->getConnection()->commit(); return $activity; } catch (\Exception $e) { $em->getConnection()->rollback(); throw $e; } }
/** * Compares the status message of an already scheduled Activity with the * content of a new/edited Activity. * * @param Activity $existingActivity * @param StatusBase $content * @return array */ protected function isUniqueContent(Activity $existingActivity, StatusBase $content) { /** @var StatusBase $existingStatus */ $existingStatus = $this->em->getRepository('CampaignChainOperationFacebookBundle:StatusBase')->findOneByOperation($existingActivity->getOperations()[0]); if ($existingStatus->getMessage() == $content->getMessage()) { return array('status' => false, 'message' => 'Same status message has already been scheduled: ' . '<a href="' . $this->router->generate('campaignchain_activity_facebook_publish_status_edit', array('id' => $existingActivity->getId())) . '">' . $existingActivity->getName() . '</a>. ' . 'Either change the message or leave at least ' . $this->maxDuplicateInterval . ' between yours and the other post.'); } else { return array('status' => true); } }