You are here

public function MaestroSetProcessVariableTask::execute in Maestro 8.2

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

Part of the ExecutableInterface Execution of the set process variable task. We will read the data in the template for what we should do with the process variable .

Overrides ExecutableInterface::execute

File

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

Class

MaestroSetProcessVariableTask
Maestro Set Process Variable Task Plugin.

Namespace

Drupal\maestro\Plugin\EngineTasks

Code

public function execute() {
  $templateMachineName = MaestroEngine::getTemplateIdFromProcessId($this->processID);
  $taskMachineName = MaestroEngine::getTaskIdFromQueueId($this->queueID);
  $task = MaestroEngine::getTemplateTaskByID($templateMachineName, $taskMachineName);
  $spv = $task['data']['spv'];
  $variable = $spv['variable'];
  $variableValue = $spv['variable_value'];
  switch ($spv['method']) {
    case 'addsubtract':

      // Simple here.. our value is a floatval.  This can be negative or positive.  Just add it to the current process variable.
      $processVar = MaestroEngine::getProcessVariable($variable, $this->processID);
      $processVar = $processVar + $variableValue;
      MaestroEngine::setProcessVariable($variable, $processVar, $this->processID);
      return TRUE;

      // Completes the task here.
      break;
    case 'hardcoded':

      // As easy as just taking the variable's value and setting it to what the template tells us to do.
      MaestroEngine::setProcessVariable($variable, $variableValue, $this->processID);
      return TRUE;

      // Completes the task here.
      break;
    case 'bycontentfunction':

      // [0] is our function, the rest are arguments
      $arr = explode(':', $variableValue);
      $arguments = explode(',', $arr[1]);
      $arguments[] = $this->queueID;
      $arguments[] = $this->processID;
      $newValue = call_user_func_array($arr[0], $arguments);
      MaestroEngine::setProcessVariable($variable, $newValue, $this->processID);
      return TRUE;

      // Completes the task here.
      break;
  }

  // We are relying on the base trait's default values to set the execution and completion status.
}