/** * {@inheritdoc} */ public function executeCommand(ProcessEngine $engine) { $task = $engine->getTaskService()->createTaskQuery()->taskId($this->taskId)->findOne(); if (!$task->isClaimed()) { throw new \RuntimeException(sprintf('User task %s is not claimed', $task->getId())); } $sql = "\tUPDATE `#__bpmn_user_task`\r\n\t\t\t\t\tSET `claimed_at` = :time,\r\n\t\t\t\t\t\t`claimed_by` = :assignee\r\n\t\t\t\t\tWHERE `id` = :id\r\n\t\t"; $stmt = $engine->prepareQuery($sql); $stmt->bindValue('time', NULL); $stmt->bindValue('assignee', NULL); $stmt->bindValue('id', $task->getId()); $stmt->execute(); $task = $engine->getTaskService()->createTaskQuery()->taskId($this->taskId)->findOne(); $engine->notify(new UserTaskUnclaimedEvent($task, $engine)); $engine->debug('User task "{task}" unclaimed', ['task' => $task->getName()]); }
/** * {@inheritdoc} */ public function executeCommand(ProcessEngine $engine) { $task = $engine->getTaskService()->createTaskQuery()->taskId($this->taskId)->findOne(); $sql = "\tDELETE FROM `#__bpmn_user_task`\r\n\t\t\t\t\tWHERE `id` = :id\r\n\t\t"; $stmt = $engine->prepareQuery($sql); $stmt->bindValue('id', $task->getId()); $stmt->execute(); $engine->debug('Removed user task "{task}" with id {id}', ['task' => $task->getName(), 'id' => (string) $task->getId()]); }
/** * {@inheritdoc} */ public function executeCommand(ProcessEngine $engine) { $task = $engine->getTaskService()->createTaskQuery()->taskId($this->taskId)->findOne(); $engine->notify(new UserTaskCompletedEvent($task, $engine)); $sql = "\tDELETE FROM `#__bpmn_user_task`\r\n\t\t\t\t\tWHERE `id` = :id\r\n\t\t"; $stmt = $engine->prepareQuery($sql); $stmt->bindValue('id', $this->taskId); $stmt->execute(); $engine->debug('Completed user task "{task}" with id {id}', ['task' => $task->getName(), 'id' => (string) $task->getId()]); $executionId = $task->getExecutionId(); if ($executionId !== NULL) { $engine->findExecution($executionId)->signal('user-task', unserialize($this->variables)); } }
/** * {@inheritdoc} */ public function executeCommand(ProcessEngine $engine) { $id = UUID::createRandom(); $activityId = NULL; if ($this->executionId !== NULL) { $activityId = $engine->findExecution($this->executionId)->getNode()->getId(); } $sql = "\tINSERT INTO `#__bpmn_user_task`\r\n\t\t\t\t\t\t(`id`, `execution_id`, `name`, `documentation`, `activity`, `created_at`, `priority`, `due_at`)\r\n\t\t\t\t\tVALUES\r\n\t\t\t\t\t\t(:id, :eid, :name, :doc, :activity, :created, :priority, :due)\r\n\t\t"; $stmt = $engine->prepareQuery($sql); $stmt->bindValue('id', $id); $stmt->bindValue('eid', $this->executionId); $stmt->bindValue('name', $this->name); $stmt->bindValue('doc', $this->documentation); $stmt->bindValue('activity', $activityId); $stmt->bindValue('created', time()); $stmt->bindValue('priority', $this->priority); $stmt->bindValue('due', $this->dueDate); $stmt->execute(); $engine->debug('Created user task "{task}" with id {id}', ['task' => $this->name, 'id' => (string) $id]); $task = $engine->getTaskService()->createTaskQuery()->taskId($id)->findOne(); $engine->notify(new UserTaskCreatedEvent($task, $engine)); return $task; }
protected function setUp() { parent::setUp(); $this->eventDispatcher = new EventDispatcher(); $this->conn = static::createConnection('bpm_', $this->eventDispatcher); static::migrateDirectoryUp($this->conn, __DIR__ . '/../../migration'); $logger = NULL; if (NULL !== ($logLevel = $this->getLogLevel())) { $stderr = fopen('php://stderr', 'wb'); $levels = array_change_key_case(Logger::getLevels(), CASE_UPPER); $logger = new Logger('BPMN'); $logger->pushHandler(new StreamHandler($stderr, $levels[strtoupper($logLevel)])); $logger->pushProcessor(new PsrLogMessageProcessor()); fwrite($stderr, "\n"); fwrite($stderr, sprintf("TEST CASE: %s\n", $this->getName())); // $this->conn$conn->setDebug(true); // $this->conn->setLogger($logger); } $this->messageHandlers = []; $this->serviceTaskHandlers = []; // Provide message handler subscriptions. $this->eventDispatcher->connect(function (MessageThrownEvent $event) { $def = $this->repositoryService->createProcessDefinitionQuery()->processDefinitionId($event->execution->getProcessDefinitionId())->findOne(); $key = $def->getKey(); $id = $event->execution->getActivityId(); if (isset($this->messageHandlers[$key][$id])) { return $this->messageHandlers[$key][$id]($event); } }); $this->eventDispatcher->connect(function (TaskExecutedEvent $event) { $execution = $this->runtimeService->createExecutionQuery()->executionId($event->execution->getExecutionId())->findOne(); $key = $execution->getProcessDefinition()->getKey(); $id = $event->execution->getActivityId(); if (isset($this->serviceTaskHandlers[$key][$id])) { $this->serviceTaskHandlers[$key][$id]($event->execution); } }); // Allow for assertions in expressions, e.g. #{ @test.assertEquals(2, processVariable) } $this->eventDispatcher->connect(function (CreateExpressionContextEvent $event) { $event->access->setVariable('@test', $this); }); $this->delegateTasks = new DelegateTaskRegistry(); $this->processEngine = new ProcessEngine($this->conn, $this->eventDispatcher, new ExpressionContextFactory()); $this->processEngine->setDelegateTaskFactory($this->delegateTasks); $this->processEngine->setLogger($logger); $scheduler = new TestJobScheduler($this->processEngine); $this->jobExecutor = new JobExecutor($this->processEngine, $scheduler); $this->processEngine->setJobExecutor($this->jobExecutor); $this->repositoryService = $this->processEngine->getRepositoryService(); $this->runtimeService = $this->processEngine->getRuntimeService(); $this->taskService = $this->processEngine->getTaskService(); $this->historyService = $this->processEngine->getHistoryService(); $this->managementService = $this->processEngine->getManagementService(); if ($this->typeInfo === NULL) { $this->typeInfo = new ReflectionTypeInfo(new \ReflectionClass(get_class($this))); } foreach ($this->typeInfo->getMethods() as $method) { if (!$method->isPublic() || $method->isStatic()) { continue; } foreach ($method->getAnnotations() as $anno) { if ($anno instanceof MessageHandler) { $this->messageHandlers[$anno->processKey][$anno->value] = [$this, $method->getName()]; } if ($anno instanceof ServiceTaskHandler) { $this->serviceTaskHandlers[$anno->processKey][$anno->value] = [$this, $method->getName()]; } } } }