|
@@ -13,7 +13,8 @@ use Symfony\Component\Console\Input\ArrayInput;
|
|
|
use Symfony\Component\Console\Output\BufferedOutput;
|
|
|
use WorkflowBundle\Validator\Constraints as WorkflowAssert;
|
|
|
use Symfony\Component\Workflow\Registry;
|
|
|
-// TODO : Remplazar las referencias de "global $kenerl por algo mÃs testeable"
|
|
|
+
|
|
|
+// TODO : Remplazar las referencias de "global $kenerl por algo m�s testeable"
|
|
|
|
|
|
/**
|
|
|
* Workflow
|
|
@@ -33,42 +34,42 @@ class Workflow
|
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
|
|
*/
|
|
|
private $id;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @var string
|
|
|
*
|
|
|
* @ORM\Column(type="string", length=100, nullable=false)
|
|
|
*/
|
|
|
protected $name;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @var string
|
|
|
*
|
|
|
* @ORM\Column(type="string", length=100, nullable=false, options={"default":"state_machine"})
|
|
|
*/
|
|
|
- protected $type = "state_machine";
|
|
|
-
|
|
|
+ protected $type = "state_machine";
|
|
|
+
|
|
|
/**
|
|
|
* @var string
|
|
|
*
|
|
|
* @ORM\Column(type="string", length=100, nullable=false, options={"default":"single_state"})
|
|
|
*/
|
|
|
- protected $markingType = "single_state";
|
|
|
-
|
|
|
+ protected $markingType = "single_state";
|
|
|
+
|
|
|
/**
|
|
|
* @var string
|
|
|
*
|
|
|
* @ORM\Column(type="string", length=100, nullable=false, options={"default":"currentState"})
|
|
|
*/
|
|
|
- protected $markingName = "currentState";
|
|
|
-
|
|
|
+ protected $markingName = "currentState";
|
|
|
+
|
|
|
/**
|
|
|
* @var string
|
|
|
*
|
|
|
* @ORM\Column(type="string", length=350, nullable=true)
|
|
|
*/
|
|
|
protected $description;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @var text
|
|
|
*
|
|
@@ -76,7 +77,7 @@ class Workflow
|
|
|
* @WorkflowAssert\ContainsYaml
|
|
|
*/
|
|
|
protected $template;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @Gedmo\Timestampable(on="create")
|
|
|
* @ORM\Column(type="datetime")
|
|
@@ -88,7 +89,7 @@ class Workflow
|
|
|
* @ORM\Column(type="datetime")
|
|
|
*/
|
|
|
protected $updated;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @var int
|
|
|
*
|
|
@@ -101,14 +102,20 @@ class Workflow
|
|
|
*
|
|
|
*/
|
|
|
protected $enable = true;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @ORM\Column(type="array", nullable=true)
|
|
|
*
|
|
|
*/
|
|
|
protected $support = array();
|
|
|
-
|
|
|
-
|
|
|
+ /**
|
|
|
+ * var mixed Contiene el contenedor.
|
|
|
+ */
|
|
|
+ private $container;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Workflow constructor.
|
|
|
+ */
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->support = array();
|
|
@@ -119,9 +126,9 @@ class Workflow
|
|
|
*/
|
|
|
public function __toString()
|
|
|
{
|
|
|
- return (string) $this->name;
|
|
|
+ return (string)$this->name;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Get id
|
|
|
*
|
|
@@ -142,7 +149,7 @@ class Workflow
|
|
|
public function setName($name)
|
|
|
{
|
|
|
$_name = strtolower($name);
|
|
|
- $name = str_replace(" ","_",$_name);
|
|
|
+ $name = str_replace(" ", "_", $_name);
|
|
|
$this->name = $name;
|
|
|
|
|
|
return $this;
|
|
@@ -158,7 +165,7 @@ class Workflow
|
|
|
return $this->name;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* Set type
|
|
|
*
|
|
|
* @param string $type
|
|
@@ -182,7 +189,7 @@ class Workflow
|
|
|
return $this->type;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* Set markingType
|
|
|
*
|
|
|
* @param string $markingType
|
|
@@ -299,7 +306,7 @@ class Workflow
|
|
|
{
|
|
|
return $this->updated;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Set tenancyId
|
|
|
*
|
|
@@ -339,71 +346,67 @@ class Workflow
|
|
|
/**
|
|
|
* Get enable
|
|
|
*
|
|
|
- * @return boolean
|
|
|
+ * @return boolean
|
|
|
*/
|
|
|
public function getEnable()
|
|
|
{
|
|
|
return $this->enable;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ORM\PostPersist
|
|
|
+ /**
|
|
|
+ * @ORM\PostPersist
|
|
|
*/
|
|
|
- public function postPersist(LifecycleEventArgs $event)
|
|
|
+ public function postPersist(LifecycleEventArgs $event)
|
|
|
{
|
|
|
$this->updateWorkflows();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @ORM\PostUpdate
|
|
|
+ /**
|
|
|
+ * @ORM\PostUpdate
|
|
|
*/
|
|
|
- public function postUpdate(LifecycleEventArgs $event)
|
|
|
+ public function postUpdate(LifecycleEventArgs $event)
|
|
|
{
|
|
|
$this->updateWorkflows();
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * @ORM\PreRemove
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @ORM\PreRemove
|
|
|
*/
|
|
|
- public function preRemove(LifecycleEventArgs $event)
|
|
|
+ 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()
|
|
|
+ public function updateWorkflowsCommand()
|
|
|
{
|
|
|
- global $kernel;
|
|
|
-
|
|
|
- $console = $kernel->getRootDir()."/../bin/console";
|
|
|
+ $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()
|
|
|
+ public function updateWorkflows()
|
|
|
{
|
|
|
- global $kernel;
|
|
|
-
|
|
|
- $em = $kernel->getContainer()->get("doctrine.orm.entity_manager");
|
|
|
- $workflows = $em->getRepository("WorkflowBundle:Workflow")->findBy(array('enable'=>1));
|
|
|
+ $em = $this->getContainer()->get("doctrine.orm.entity_manager");
|
|
|
+ $workflows = $em->getRepository("WorkflowBundle:Workflow")->findBy(array('enable' => 1));
|
|
|
|
|
|
- $rootDir = $kernel->getRootDir();
|
|
|
+ $rootDir = $this->getContainer()->getParameter('kernel.root_dir');
|
|
|
|
|
|
$workflow_template = array();
|
|
|
$workflow_template['framework'] = array();
|
|
|
|
|
|
$templates = array();
|
|
|
- foreach($workflows as $k => $workflow) {
|
|
|
+ foreach ($workflows as $k => $workflow) {
|
|
|
|
|
|
$body = array();
|
|
|
|
|
|
$body['type'] = $workflow->getType();
|
|
|
-
|
|
|
- if(is_array($workflow->getMarkingName())) {
|
|
|
- $markingName = $workflow->getMarkingName();
|
|
|
+
|
|
|
+ if (is_array($workflow->getMarkingName())) {
|
|
|
+ $markingName = $workflow->getMarkingName();
|
|
|
} else {
|
|
|
- $markingName = array(0 => $workflow->getMarkingName());
|
|
|
+ $markingName = array(0 => $workflow->getMarkingName());
|
|
|
}
|
|
|
$body['marking_store'] = array('type' => $workflow->getMarkingType(), 'arguments' => $markingName);
|
|
|
$body['supports'] = $workflow->getSupport();
|
|
@@ -414,22 +417,22 @@ class Workflow
|
|
|
|
|
|
}
|
|
|
|
|
|
- $workflow_file = $rootDir."/Resources/workflows/workflow_list.yml";
|
|
|
-
|
|
|
- $handle = fopen($workflow_file,"w+");
|
|
|
+ $workflow_file = $rootDir . "/Resources/workflows/workflow_list.yml";
|
|
|
+
|
|
|
+ $handle = fopen($workflow_file, "w+");
|
|
|
|
|
|
- if($templates) {
|
|
|
+ if ($templates) {
|
|
|
$workflow_template['framework'] = array('workflows' => $templates);
|
|
|
- $yaml = Yaml::dump($workflow_template,100,2);
|
|
|
- fwrite($handle,$yaml);
|
|
|
+ $yaml = Yaml::dump($workflow_template, 100, 2);
|
|
|
+ fwrite($handle, $yaml);
|
|
|
} else {
|
|
|
- fwrite($handle,"");
|
|
|
+ fwrite($handle, "");
|
|
|
}
|
|
|
|
|
|
fclose($handle);
|
|
|
chmod($workflow_file, 0777);
|
|
|
|
|
|
- $console = $rootDir."/../bin/console";
|
|
|
+ $console = $rootDir . "/../bin/console";
|
|
|
exec("php {$console} cache:clear --env=prod");
|
|
|
|
|
|
/*$web_workflows = $rootDir."/../web/workflows_png/";
|
|
@@ -442,34 +445,28 @@ class Workflow
|
|
|
}*/
|
|
|
}
|
|
|
|
|
|
- public function getDefinition($subject) {
|
|
|
- global $kernel;
|
|
|
-
|
|
|
- if($kernel){
|
|
|
- try {
|
|
|
- $registry = $kernel->getContainer()->get("workflow.registry");
|
|
|
- $definition = $registry->get($subject, $this->name)->getDefinition();
|
|
|
- } catch (\Exception $e) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- return $definition;
|
|
|
- }
|
|
|
+ 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) {
|
|
|
- global $kernel;
|
|
|
- if($kernel){
|
|
|
- try {
|
|
|
- $registry = $kernel->getContainer()->get("workflow.registry");
|
|
|
- $definition = $registry->get($subject, $this->name)->getDefinition();
|
|
|
- } catch (\Exception $e) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- return $definition->getInitialPlace();
|
|
|
- }
|
|
|
+ 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();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -499,14 +496,29 @@ class Workflow
|
|
|
*
|
|
|
* 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();
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|