示例#1
0
 public function executeCommand(ProcessEngine $engine)
 {
     $name = $this->builder->getName();
     if ($this->builder->count() < 1) {
         throw new \RuntimeException(sprintf('Cannot deploy "%s" because it does not contain any resources', $name));
     }
     $id = UUID::createRandom();
     $sql = "\tINSERT INTO `#__bpmn_deployment`\n\t\t\t\t\t\t(`id`, `name`, `deployed_at`)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t(:id, :name, :time)\n\t\t";
     $stmt = $engine->prepareQuery($sql);
     $stmt->bindValue('id', $id);
     $stmt->bindValue('name', $name);
     $stmt->bindValue('time', time());
     $stmt->execute();
     $engine->info('Created deployment "{name}" with identifier <{id}>', ['name' => $name, 'id' => (string) $id]);
     $sql = "\tINSERT INTO `#__bpmn_resource`\n\t\t\t\t\t\t(`id`, `deployment_id`, `name`, `data`)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t(:id, :deployment, :name, :data)\n\t\t";
     $stmt = $engine->prepareQuery($sql);
     $stmt->bindValue('deployment', $id);
     $parser = new DiagramLoader();
     foreach ($this->builder as $name => $stream) {
         $in = $stream->getContents();
         $resourceId = UUID::createRandom();
         $stmt->bindValue('id', $resourceId);
         $stmt->bindValue('name', $name);
         $stmt->bindValue('data', new BinaryData($in));
         $stmt->execute();
         $engine->debug('Deployed resource "{name}" with identifer <{resourceId}>', ['name' => $name, 'resourceId' => (string) $resourceId]);
         if ($this->builder->isProcessResource($name)) {
             foreach ($parser->parseDiagramString($in) as $process) {
                 $engine->pushCommand(new DeployBusinessProcessCommand($process, $id, $resourceId));
             }
         }
     }
     return $id;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function removeJob(UUID $jobId)
 {
     $stmt = $this->engine->prepareQuery("DELETE FROM `#__bpmn_job` WHERE `id` = :id");
     $stmt->bindValue('id', $jobId);
     $stmt->execute();
     $this->engine->info('Removed job <{job}>', ['job' => (string) $jobId]);
     $this->removedJobs[] = $jobId;
 }
 public function executeCommand(ProcessEngine $engine)
 {
     $sql = "\tSELECT `revision`\r\n\t\t\t\t\tFROM `#__bpmn_process_definition`\r\n\t\t\t\t\tWHERE `process_key` = :key\r\n\t\t\t\t\tORDER BY `revision` DESC\r\n\t\t";
     $stmt = $engine->prepareQuery($sql);
     $stmt->bindValue('key', $this->builder->getKey());
     $stmt->setLimit(1);
     $stmt->execute();
     $revision = $stmt->fetchNextColumn(0);
     $model = $this->builder->build();
     $id = $model->getId();
     $time = time();
     $sql = "\tINSERT INTO `#__bpmn_process_definition`\r\n\t\t\t\t\t\t(`id`, `deployment_id`, `resource_id`, `process_key`, `revision`, `definition`, `name`, `deployed_at`)\r\n\t\t\t\t\tVALUES\r\n\t\t\t\t\t\t(:id, :deployment, :resource, :key, :revision, :model, :name, :deployed)\r\n\t\t";
     $stmt = $engine->prepareQuery($sql);
     $stmt->bindValue('id', $id);
     $stmt->bindValue('deployment', $this->deploymentId);
     $stmt->bindValue('resource', $this->resourceId);
     $stmt->bindValue('key', $this->builder->getKey());
     $stmt->bindValue('revision', $revision + 1);
     $stmt->bindValue('model', new BinaryData(serialize($model), 3));
     $stmt->bindValue('name', $model->getTitle());
     $stmt->bindValue('deployed', $time);
     $stmt->execute();
     $sql = "\tDELETE FROM `#__bpmn_process_subscription`\r\n\t\t\t\t\tWHERE `definition_id` IN (\r\n\t\t\t\t\t\tSELECT `id`\r\n\t\t\t\t\t\tFROM `#__bpmn_process_definition`\r\n\t\t\t\t\t\tWHERE `process_key` = :key\r\n\t\t\t\t\t)\r\n\t\t";
     $stmt = $engine->prepareQuery($sql);
     $stmt->bindValue('key', $this->builder->getKey());
     $stmt->execute();
     $engine->info('Deployed business process {key} revision {revision} using id {id}', ['key' => $this->builder->getKey(), 'revision' => $revision + 1, 'id' => (string) $id]);
     foreach ($model->findStartNodes() as $node) {
         $behavior = $node->getBehavior();
         if ($behavior instanceof MessageStartEventBehavior && !$behavior->isSubProcessStart()) {
             $sql = "\tINSERT INTO `#__bpmn_process_subscription`\r\n\t\t\t\t\t\t\t\t(`id`, `definition_id`, `flags`, `name`)\r\n\t\t\t\t\t\t\tVALUES\r\n\t\t\t\t\t\t\t\t(:id, :def, :flags, :message)\r\n\t\t\t\t";
             $stmt = $engine->prepareQuery($sql);
             $stmt->bindValue('id', UUID::createRandom());
             $stmt->bindValue('def', $id);
             $stmt->bindValue('flags', EventSubscription::TYPE_MESSAGE);
             $stmt->bindValue('message', $behavior->getMessageName());
             $stmt->execute();
             $engine->debug('Process {process} subscribed to message <{message}>', ['process' => $this->builder->getKey(), 'message' => $behavior->getMessageName()]);
         }
         if ($behavior instanceof SignalStartEventBehavior && !$behavior->isSubProcessStart()) {
             $sql = "\tINSERT INTO `#__bpmn_process_subscription`\r\n\t\t\t\t\t\t\t\t(`id`, `definition_id`, `flags`, `name`)\r\n\t\t\t\t\t\t\tVALUES\r\n\t\t\t\t\t\t\t\t(:id, :def, :flags, :message)\r\n\t\t\t\t";
             $stmt = $engine->prepareQuery($sql);
             $stmt->bindValue('id', UUID::createRandom());
             $stmt->bindValue('def', $id);
             $stmt->bindValue('flags', EventSubscription::TYPE_SIGNAL);
             $stmt->bindValue('message', $behavior->getSignalName());
             $stmt->execute();
             $engine->debug('Process {process} subscribed to signal <{signal}>', ['process' => $this->builder->getKey(), 'signal' => $behavior->getSignalName()]);
         }
     }
     return new ProcessDefinition($id, $this->builder->getKey(), $revision + 1, $model, $model->getTitle(), new \DateTimeImmutable('@' . $time), $this->deploymentId);
 }
 /**
  * {@inheritdoc}
  */
 public function executeCommand(ProcessEngine $engine)
 {
     $def = $engine->getRepositoryService()->createProcessDefinitionQuery()->processDefinitionId($this->definitionId)->findOne();
     $definition = $def->getModel();
     $startNode = $definition->findNode($this->startNodeId);
     $process = new VirtualExecution(UUID::createRandom(), $engine, $definition);
     $process->setBusinessKey($this->businessKey);
     $process->setNode($startNode);
     foreach (unserialize($this->variables) as $k => $v) {
         $process->setVariable($k, $v);
     }
     $engine->registerExecution($process);
     $engine->info('Started {process} using process definition "{key}" ({id})', ['process' => (string) $process, 'key' => $def->getKey(), 'id' => (string) $def->getId()]);
     $process->execute($startNode);
     return $process->getId();
 }