You are here

protected function MaestroEngine::createProductionTask in Maestro 8.2

Same name and namespace in other branches
  1. 3.x src/Engine/MaestroEngine.php \Drupal\maestro\Engine\MaestroEngine::createProductionTask()

Creates a task in the Maestro Queue table.

Parameters

string $taskMachineName: The machine name of the task.

string $templateMachineName: The machine name of the template.

int $processID: The Maestro Process ID.

Return value

int|bool Returns FALSE on no queue entry. Returns the QueueID upon success.

1 call to MaestroEngine::createProductionTask()
MaestroEngine::nextStep in src/Engine/MaestroEngine.php
NextStep Engine method that determines which is the next step based on the current step and does all assignments as necessary.

File

src/Engine/MaestroEngine.php, line 1751

Class

MaestroEngine
Class MaestroEngine.

Namespace

Drupal\maestro\Engine

Code

protected function createProductionTask($taskMachineName, $templateMachineName, $processID) {
  $config = \Drupal::config('maestro.settings');
  $queueID = FALSE;
  $nextTask = $this
    ->getTemplateTaskByID($templateMachineName, $taskMachineName);
  $executableTask = MaestroEngine::getPluginTask($nextTask['tasktype']);
  $currentTime = time();
  $nextReminderTime = 0;
  $reminderInterval = 0;
  $escalationInterval = 0;
  if (array_key_exists('notifications', $nextTask)) {
    $reminderInterval = $nextTask['notifications']['reminder_after'];
    if (intval($reminderInterval) > 0) {
      $nextReminderTime = $currentTime + intval($reminderInterval) * 86400;
    }
    $escalationInterval = $nextTask['notifications']['escalation_after'];
  }
  $values = [
    'process_id' => $processID,
    'task_class_name' => $nextTask['tasktype'],
    'task_id' => $nextTask['id'],
    'task_label' => $nextTask['label'],
    'engine_version' => 2,
    'is_interactive' => $executableTask
      ->isInteractive() ? 1 : 0,
    'show_in_detail' => isset($nextTask['showindetail']) ? $nextTask['showindetail'] : 0,
    'handler' => isset($nextTask['handler']) ? $nextTask['handler'] : '',
    'task_data' => isset($nextTask['data']) ? $nextTask['data'] : '',
    'status' => 0,
    'run_once' => $executableTask
      ->isInteractive() ? 1 : 0,
    // This should probably be 0 to signify the engine.
    'uid' => 0,
    'archived' => 0,
    'started_date' => $currentTime,
    'num_reminders_sent' => 0,
    'num_escalations_sent' => 0,
    'next_reminder_time' => $nextReminderTime,
    'reminder_interval' => $reminderInterval,
    'escalation_interval' => $escalationInterval,
  ];
  $queue = \Drupal::entityTypeManager()
    ->getStorage('maestro_queue')
    ->create($values);
  $queue
    ->save();

  // Now to do assignments if the queue ID has been set.
  if ($queue
    ->id()) {

    // Perform maestro assignments.
    $this
      ->productionAssignments($templateMachineName, $taskMachineName, $queue
      ->id());
    $queueID = $queue
      ->id();
    if ($config
      ->get('maestro_send_notifications')) {
      $this
        ->doProductionAssignmentNotifications($templateMachineName, $taskMachineName, $queue
        ->id(), 'assignment');
    }

    // Now lets set the workflow status process variables if the task requires us to do so.
    // Relates to the checkbox on the task editor.
    if (isset($nextTask['participate_in_workflow_status_stage']) && $nextTask['participate_in_workflow_status_stage'] == 1) {
      if (isset($nextTask['workflow_status_stage_number'])) {
        $this
          ->setProcessVariable('workflow_current_stage', $nextTask['workflow_status_stage_number'], $processID);
      }
      if (isset($nextTask['workflow_status_stage_message'])) {
        $this
          ->setProcessVariable('workflow_current_stage_message', $nextTask['workflow_status_stage_message'], $processID);
      }
    }
  }
  else {

    // TODO: throw maestro exception here.
  }
  return $queueID;
}