You are here

public function MaestroBatchFunctionTask::execute in Maestro 8.2

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

Part of the ExecutableInterface Execution of the Batch Function task will use the handler for this task as the executable function. The handler must return TRUE in order for this function to be completed by the engine. We simply pass the return boolean value back from the called handler to the engine for processing. .

Overrides ExecutableInterface::execute

File

src/Plugin/EngineTasks/MaestroBatchFunctionTask.php, line 84

Class

MaestroBatchFunctionTask
Maestro Batch Function Task Plugin.

Namespace

Drupal\maestro\Plugin\EngineTasks

Code

public function execute() {
  $returnValue = FALSE;
  $returnStatus = FALSE;
  $queueRecord = MaestroEngine::getQueueEntryById($this->queueID);
  if ($queueRecord) {

    // Pick off the handler here and call the code via the user func array.
    if ($queueRecord->handler != NULL) {
      $handler = $queueRecord->handler
        ->getString();
      if (function_exists($handler)) {
        $returnStatus = call_user_func_array($handler, [
          $this->processID,
          $this->queueID,
        ]);

        // Lets see if the return status is an array.  if so, we will check if it has any established structure to set status codes.
        if (is_array($returnStatus)) {
          if (array_key_exists('completion_status', $returnStatus)) {
            $this->completionStatus = $returnStatus['completion_status'];
          }
          if (array_key_exists('execution_status', $returnStatus)) {
            $this->executionStatus = $returnStatus['execution_status'];
          }
          if (array_key_exists('status', $returnStatus)) {

            // On false, this holds the engine at this task.
            $returnValue = $returnStatus['status'];
          }
        }
        else {
          $returnValue = $returnStatus;
        }
      }
    }
    else {

      // Just do a NOOP here.
      $returnValue = TRUE;
    }
  }

  // True or false to complete the task.
  return $returnValue;
}