|
@@ -56,17 +56,32 @@ class WorkflowApplyCommand extends ContainerAwareCommand
|
|
|
$entityClass = $input->getOption('entity');
|
|
|
$entityId = $input->getOption('id');
|
|
|
|
|
|
+ if(!class_exists($entityClass)){
|
|
|
+ throw new \Exception("Class '$entityClass' not found");
|
|
|
+ }
|
|
|
+
|
|
|
$entity = $entity_manager->getRepository($entityClass)->find($entityId);
|
|
|
if(!$entity){
|
|
|
- throw \Exception("Entity $entityClass with id $entityId not found");
|
|
|
+ throw new \Exception("Entity $entityClass with id $entityId not found");
|
|
|
}
|
|
|
|
|
|
$wreg = $this->getContainer()->get("workflow.registry");
|
|
|
$wf = $wreg->get($entity, $workflow);
|
|
|
|
|
|
+ $transitions = array_map(function($obj){
|
|
|
+ return $obj->getName();
|
|
|
+ }, $wf->getEnabledTransitions($entity));
|
|
|
+
|
|
|
+ if(!in_array($transition, $transitions)){
|
|
|
+ throw new \Exception ("Can't apply transition '$transition', only allowed transitions for this entity are '". implode("','", $transitions). "'");
|
|
|
+ }
|
|
|
+ $from = array_keys($wf->getMarking($entity)->getPlaces());
|
|
|
$newState = $wf->apply($entity, $transition);
|
|
|
$entity_manager->persist($entity);
|
|
|
$entity_manager->flush($entity);
|
|
|
|
|
|
+ $to = array_keys($wf->getMarking($entity)->getPlaces());
|
|
|
+ $output->writeln("Applyed ". $transition . "(".(string)$entity. ") : " . json_encode($from) . " -> " . json_encode($to));
|
|
|
+
|
|
|
}
|
|
|
}
|