Bläddra i källkod

Se agrega comando para generar lista de workflows.

Maximiliano Schvindt 8 år sedan
förälder
incheckning
3e06f93b5d

+ 1 - 1
src/FTTHBundle/Entity/ONU.php

@@ -417,7 +417,7 @@ class ONU
     {
         if($this->model) {
             $model = $this->model;
-            if($model->getWorkflow()) {
+            if($model->getWorkflow() && $model->getWorkflow()->getEnable()) {
                 return $model->getWorkflow()->getName();
             }
         }

+ 9 - 4
src/WorkflowBundle/Admin/WorkflowAdmin.php

@@ -62,17 +62,22 @@ class WorkflowAdmin extends BaseAdmin
      */
     protected function configureFormFields(FormMapper $formMapper)
     {
+
         $formMapper
             ->add('name')
             ->add('description')
             ->add('enable')
-            ->add('type')
-            ->add('markingType')
-            ->add('markingName')
+            ->add('type', 'choice', array('choices' => array('state_machine' => 'state_machine', 'workflow' => 'workflow')))
+            ->add('markingType', 'choice', array('choices' => array('single_state' => 'single_state', 'multiple_state' => 'multiple_state')))
+            ->add('markingName', 'choice', array('choices' => array('currentState' => 'currentState')))
             ->add('template', null, array('attr' => array('style' => 'height:500px;')))
 
             ->setHelps(array(
-               'name' => $this->trans("helps.workflow_label_name")
+               'name' => $this->trans("helps.workflow_label_name"),
+               'type' => $this->trans("helps.workflow_label_type"),
+               'markingType' => $this->trans("helps.workflow_label_marking_type"),
+               'markingName' => $this->trans("helps.workflow_label_marking_name"),
+
             ))
             ;
     }

+ 73 - 0
src/WorkflowBundle/Command/WorkflowGenerateListCommand.php

@@ -0,0 +1,73 @@
+<?php
+namespace WorkflowBundle\Command;
+
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Yaml\Yaml;
+
+class WorkflowGenerateListCommand extends ContainerAwareCommand
+{
+    protected function configure()
+    {
+        $this
+            // the name of the command (the part after "bin/console")
+            ->setName('workflow:generate:list')
+
+            // the short description shown while running "php bin/console list"
+            ->setDescription('Genera el contenido para el archivo workflow_list.yml.')
+
+            // the full command description shown when running the command with
+            // the "--help" option
+            ->setHelp('Genera el contenido para el archivo workflow_list.yml.')
+        ;
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        // Init
+        $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 += 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);
+
+    }
+}

+ 34 - 14
src/WorkflowBundle/Entity/Workflow.php

@@ -380,7 +380,6 @@ class Workflow
     public function postPersist(LifecycleEventArgs $event) 
     {
         $this->updateWorkflows();
-        $this->reloadCache();
     }
 
     /**  
@@ -389,16 +388,25 @@ class Workflow
     public function postUpdate(LifecycleEventArgs $event) 
     {
         $this->updateWorkflows();
-        $this->reloadCache();
     }
-
+    
     /**  
      *  @ORM\PreRemove
      */
     public function preRemove(LifecycleEventArgs $event) 
     {
         $this->updateWorkflows();
-        $this->reloadCache();
+    }
+
+    // La idea era peticionar el comando y que actualice, pero desde aquí, el comando no obtiene el enable actualizado.
+    public function updateWorkflowsCommand() 
+    {
+        global $kernel;
+
+        $console = $kernel->getRootDir()."/../bin/console";
+
+        exec("php {$console} workflow:generate:list");
+        exec("php {$console} cache:clear --env=prod");
     }
 
     public function updateWorkflows() 
@@ -406,17 +414,34 @@ class Workflow
         global $kernel;
 
         $em = $kernel->getContainer()->get("doctrine.orm.entity_manager");
-        $workflows = $em->getRepository("WorkflowBundle:Workflow")->findBy(array("enable"=>1));
+        $workflows = $em->getRepository("WorkflowBundle:Workflow")->findBy(array('enable'=>1));
+
+        $rootDir = $kernel->getRootDir();
 
         $workflow_template = array();
         $workflow_template['framework'] = array();
 
         $templates = array();
         foreach($workflows as $k => $workflow) {
-           $templates[$workflow->getName()] = Yaml::parse($workflow->getTemplate());
+
+            $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 += Yaml::parse($workflow->getTemplate());
+
+            $templates[$workflow->getName()] = $body;
+
         }
 
-        $workflow_file = $kernel->getRootDir()."/Resources/workflows/workflow_list.yml";
+        $workflow_file = $rootDir."/Resources/workflows/workflow_list.yml";
         
         $handle = fopen($workflow_file,"w+");
 
@@ -430,15 +455,10 @@ class Workflow
 
         fclose($handle);
         chmod($workflow_file, 0777);
-    }
 
-    public function reloadCache() 
-    {
-        global $kernel;
-        
-        $console = $kernel->getRootDir()."/../bin/console";
+        $console = $rootDir."/../bin/console";
+        exec("php {$console} cache:clear --env=prod");
 
-        exec("{$console} cache:clear --env=prod");
     }
 
 }

+ 12 - 0
src/WorkflowBundle/Resources/translations/WorkflowBundle.es.yml

@@ -20,6 +20,9 @@ form:
     label_created: Creado
     label_updated: Actualizado
     label_enable : Habilitado
+    label_type : Tipo de Workflow
+    label_marking_type : Tipo de marcador
+    label_marking_name : Nombre de marcador
 list:
     label_id: Id
     label_name: Nombre
@@ -29,6 +32,9 @@ list:
     label_created: Creado
     label_updated: Actualizado
     label_enable : Habilitado
+    label_type : Tipo de Workflow
+    label_marking_type : Tipo de marcador
+    label_marking_name : Nombre de marcador
 show:
     label_id: Id
     label_name: Nombre
@@ -38,6 +44,12 @@ show:
     label_created: Creado
     label_updated: Actualizado
     label_enable : Habilitado
+    label_type : Tipo de Workflow
+    label_marking_type : Tipo de marcador
+    label_marking_name : Nombre de marcador
 helps:
     workflow_label_name: Nombre con el que se identificará el workflow. Se convertirá a minúscula y los espacios se reemplazarán por "_"
+    workflow_label_type: "Tipo de Workflow: state_machine o workflow"
+    workflow_label_marking_type: "Tipo de Marcador: single_state o multiple_state"
+    workflow_label_marking_name: "Nombre del Marcador, atributo de la entidad que tendrá el estado, por defecto: currentState"