You are here

public function MaestroAndTask::execute in Maestro 8.2

Same name and namespace in other branches
  1. 3.x src/Plugin/EngineTasks/MaestroAndTask.php \Drupal\maestro\Plugin\EngineTasks\MaestroAndTask::execute()

Part of the ExecutableInterface Execution of the AND task returns TRUE when all pointers are complete and FALSE when still waiting.. .

Overrides ExecutableInterface::execute

File

src/Plugin/EngineTasks/MaestroAndTask.php, line 82

Class

MaestroAndTask
Maestro And Task Plugin.

Namespace

Drupal\maestro\Plugin\EngineTasks

Code

public function execute() {

  // Determine who is pointing at me.
  $templateMachineName = MaestroEngine::getTemplateIdFromProcessId($this->processID);
  $taskMachineName = MaestroEngine::getTaskIdFromQueueId($this->queueID);
  $pointers = MaestroEngine::getTaskPointersFromTemplate($templateMachineName, $taskMachineName);

  // Now that we have pointers, let's determine if they're all complete
  // otherwise, return false.
  $query = \Drupal::entityQuery('maestro_queue');
  $andMainConditions = $query
    ->andConditionGroup()
    ->condition('status', '1')
    ->condition('archived', '2', '!=')
    ->condition('process_id', $this->processID);
  $orConditionGroup = $query
    ->orConditionGroup();
  foreach ($pointers as $taskID) {
    $orConditionGroup
      ->condition('task_id', $taskID);
  }
  $andMainConditions
    ->condition($orConditionGroup);
  $query
    ->condition($andMainConditions);
  $queueIdCount = $query
    ->count()
    ->execute();
  if (count($pointers) == $queueIdCount) {
    return TRUE;
  }
  return FALSE;
}