/**
  * @param ChangeWorkflowName $command
  * @throws Exception\WorkflowNotFound
  */
 public function handle(ChangeWorkflowName $command)
 {
     $workflow = $this->workflowCollection->get($command->workflowId());
     if (is_null($workflow)) {
         throw WorkflowNotFound::withId($command->workflowId());
     }
     $workflow->changeName($command->name());
 }
 /**
  * @param PublishWorkflow $command
  * @throws Exception\WorkflowNotFound
  */
 public function handle(PublishWorkflow $command)
 {
     $workflow = $this->workflowCollection->get($command->workflowId());
     if (is_null($workflow)) {
         throw WorkflowNotFound::withId($command->workflowId());
     }
     $workflow->releaseCurrentVersion($command->releaseNumber(), $this->workflowPublisher);
 }
 /**
  * @param ScheduleFirstTasksForWorkflow $command
  * @throws Exception\WorkflowNotFound
  * @throws \Prooph\Link\ProcessManager\Model\MessageHandler\Exception\MessageHandlerNotFound
  */
 public function handle(ScheduleFirstTasksForWorkflow $command)
 {
     $workflow = $this->workflowCollection->get($command->workflowId());
     if (is_null($workflow)) {
         throw WorkflowNotFound::withId($command->workflowId());
     }
     $messageHandler = $this->messageHandlerCollection->get($command->firstMessageHandlerId());
     if (is_null($messageHandler)) {
         throw MessageHandlerNotFound::withId($command->firstMessageHandlerId());
     }
     $tasks = $workflow->determineFirstTasks($command->startMessage(), $messageHandler);
     foreach ($tasks as $task) {
         $this->taskCollection->add($task);
     }
 }
 public function handle(ScheduleNextTasksForWorkflow $command)
 {
     $workflow = $this->workflowCollection->get($command->workflowId());
     if (is_null($workflow)) {
         throw WorkflowNotFound::withId($command->workflowId());
     }
     $previousTask = $this->taskCollection->get($command->previousTaskId());
     if (is_null($previousTask)) {
         throw TaskNotFound::withId($command->previousTaskId());
     }
     $previousMessageHandler = $this->messageHandlerCollection->get($previousTask->messageHandlerId());
     if (is_null($previousMessageHandler)) {
         throw MessageHandlerNotFound::withId($previousTask->messageHandlerId());
     }
     $nextMessageHandler = $this->messageHandlerCollection->get($command->nextMessageHandlerId());
     if (is_null($nextMessageHandler)) {
         throw MessageHandlerNotFound::withId($command->nextMessageHandlerId());
     }
     $nextTasks = $workflow->determineNextTasks($previousTask, $previousMessageHandler, $nextMessageHandler);
     foreach ($nextTasks as $nextTask) {
         $this->taskCollection->add($nextTask);
     }
 }