support = array(); } /** * @return string */ public function __toString() { return (string)$this->name; } /** * Get id * * @return int */ public function getId() { return $this->id; } /** * Set name * * @param string $name * * @return Workflow */ public function setName($name) { $_name = strtolower($name); $name = str_replace(" ", "_", $_name); $this->name = $name; return $this; } /** * Get name * * @return string */ public function getName() { return $this->name; } /** * Set type * * @param string $type * * @return Workflow */ public function setType($type) { $this->type = $type; return $this; } /** * Get type * * @return string */ public function getType() { return $this->type; } /** * Set markingType * * @param string $markingType * * @return Workflow */ public function setMarkingType($markingType) { $this->markingType = $markingType; return $this; } /** * Get markingType * * @return string */ public function getMarkingType() { return $this->markingType; } /** * Set markingName * * @param string $markingName * * @return Workflow */ public function setMarkingName($markingName) { $this->markingName = $markingName; return $this; } /** * Get markingName * * @return string */ public function getMarkingName() { return $this->markingName; } /** * Set description * * @param string $description * * @return Workflow */ public function setDescription($description) { $this->description = $description; return $this; } /** * Get description * * @return string */ public function getDescription() { return $this->description; } /** * Set template * * @param text $template * * @return Workflow */ public function setTemplate($template) { //$array = Yaml::parse($template); //$text = Yaml::dump($array,100,2); $this->template = $template; return $this; } /** * Get template * * @return text */ public function getTemplate() { return $this->template; } /** * Get created * * @return \DateTime */ public function getCreated() { return $this->created; } /** * Get updated * * @return \DateTime */ public function getUpdated() { return $this->updated; } /** * Set tenancyId * * @param int $tenancyId * * @return Workflow */ public function setTenancyId($tenancyId) { $this->tenancyId = $tenancyId; return $this; } /** * Get tenancyId * * @return int */ public function getTenancyId() { return $this->tenancyId; } /** * Set enable * * @param boolean $enable * @return Workflow */ public function setEnable($enable) { $this->enable = $enable; return $this; } /** * Get enable * * @return boolean */ public function getEnable() { return $this->enable; } /** * @ORM\PostPersist */ public function postPersist(LifecycleEventArgs $event) { $this->updateWorkflows(); } /** * @ORM\PostUpdate */ public function postUpdate(LifecycleEventArgs $event) { $this->updateWorkflows(); } /** * @ORM\PreRemove */ public function preRemove(LifecycleEventArgs $event) { $this->updateWorkflows(); } // La idea era peticionar el comando y que actualice, pero desde aquĆ­, el comando no obtiene el enable actualizado. public function updateWorkflowsCommand() { $console = $this->getContainer()->getParameter('kernel.root_dir') . "/../bin/console"; exec("php {$console} workflow:generate:list"); exec("php {$console} cache:clear --env=prod"); } public function updateWorkflows() { $em = $this->getContainer()->get("doctrine.orm.entity_manager"); $workflows = $em->getRepository("WorkflowBundle:Workflow")->findBy(array('enable' => 1)); $rootDir = $this->getContainer()->getParameter('kernel.root_dir'); $workflow_template = array(); $workflow_template['framework'] = array(); $templates = array(); foreach ($workflows as $k => $workflow) { $body = array(); $body['type'] = $workflow->getType(); if (is_array($workflow->getMarkingName())) { $markingName = $workflow->getMarkingName(); } else { $markingName = array(0 => $workflow->getMarkingName()); } $body['marking_store'] = array('type' => $workflow->getMarkingType(), 'arguments' => $markingName); $body['supports'] = $workflow->getSupport(); $body += Yaml::parse($workflow->getTemplate()); $templates[$workflow->getName()] = $body; } $workflow_file = $rootDir . "/Resources/workflows/workflow_list.yml"; $handle = fopen($workflow_file, "w+"); if ($templates) { $workflow_template['framework'] = array('workflows' => $templates); $yaml = Yaml::dump($workflow_template, 100, 2); fwrite($handle, $yaml); } else { fwrite($handle, ""); } fclose($handle); chmod($workflow_file, 0777); $console = $rootDir . "/../bin/console"; exec("php {$console} cache:clear --env=prod"); /*$web_workflows = $rootDir."/../web/workflows_png/"; foreach($workflows as $k => $workflow) { $file_locate = "{$web_workflows}/{$workflow->getName()}"; exec("php {$console} workflow:dump {$workflow->getName()} > {$file_locate}.dot"); if(file_exists("{$file_locate}.dot")) { exec("dot -Tpng {$file_locate}.dot -o {$file_locate}.png"); } }*/ } public function getDefinition($subject) { try { $registry = $this->getContainer()->get("workflow.registry"); $definition = $registry->get($subject, $this->name)->getDefinition(); } catch (\Exception $e) { return null; } return $definition; } public function getInitialPlace($subject) { try { $registry = $this->getContainer()->get("workflow.registry"); $definition = $registry->get($subject, $this->name)->getDefinition(); } catch (\Exception $e) { return null; } return $definition->getInitialPlace(); } /** * Set support * * @param array $support * @return Workflow */ public function setSupport($support) { $this->support = $support; return $this; } /** * Get support * * @return array */ public function getSupport() { return $this->support; } /** * Get subject * * Para obtener un workflow desde el registry ya que localiza por object y workflowName */ public function getSubject() { if ($this->support) { $className = "\\" . $this->support[0]; return new $className(); } return null; } /** * @return mixed */ public function getContainer() { return $this->container; } /** * @param mixed $container */ public function setContainer($container) { $this->container = $container; } }