Add Tasks to WebService Request

@param array $tasks List of task to perform inside this request.
If NULL, internal task list is used.

@return bool
320436
private function addTasks($tasks = null)
    {
        //====================================================================//
        // No tasks to Add
        if (is_null($tasks) && empty($this->tasks)) {
            return true;
        }

        //====================================================================//
        // Prepare Tasks To Perform
        //====================================================================//

        //====================================================================//
        // Add Internal Tasks to buffer
        if (!empty($this->tasks)) {
            $this->outputs->tasks = $this->tasks;
            $this->outputs->taskscount = count($this->outputs->tasks);
            Splash::log()->deb('[WS] Call Loaded '.$this->outputs->tasks->count().' Internal tasks');
        } else {
            $this->outputs->tasks = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
        }

        //====================================================================//
        // Add External Tasks to the request
        if (!empty($tasks)) {
            $this->outputs->tasks->append($tasks);
            $this->outputs->taskscount = count($tasks);
            Splash::log()->deb('[WS] Call Loaded '.count($tasks).' External tasks');
        }

        return true;
    }
122515
public function tasks($args = null)
    {
        $this->areArgumentsValid($args, ['filter', 'page', 'pageSize', 'startdate', 'enddate', 'updatedAfterDate', 'completedAfterDate', 'completedBeforeDate', 'showDeleted', 'includeCompletedTasks', 'includeCompletedSubtasks', 'creator-ids', 'include', 'responsible-party-ids', 'sort', 'getSubTasks', 'nestSubTasks', 'getFiles', 'dataSet', 'includeToday', 'ignore-start-date']);
    
        return $this->client->get("$this->endpoint/$this->id/tasks", $args)->response();
    }
569660
private function initRunTimeTableData(array $task, array $parseResult): bool
    {
        $runTimeTableTasks = $this->getRunTimeTable()->table;

        $min = date('YmdHi');
        $sec = strtotime(date('Y-m-d H:i'));

        foreach ($parseResult as $time) {
            $this->checkTaskQueue(false);
            $key = $this->getKey($task['rule'], $task['taskClass'], $task['taskMethod'], $min, $time + $sec);
            $runTimeTableTasks->set($key, [
                'taskClass'  => $task['taskClass'],
                'taskMethod' => $task['taskMethod'],
                'minute'     => $min,
                'sec'        => $time + $sec,
                'runStatus'  => self::NORMAL
            ]);
        }

        return true;
    }
1013704
public function does($task)
    {
        // Store the original task before transformation
        $this->setStringTask($task);

        // Wrap string tasks
        if (is_string($task) || is_array($task)) {
            $task = $this->builder->wrapStringTasks($task);
        }

        $this->setClosure($task);

        return $this;
    }
1275107
public function setTask(Task $task = null)
    {
        $this->task = $task;
        if (null !== $task) {
            $task->addTransition($this);
        }

        return $this;
    }
145297
public function add_settings(array $settingstasks) {
        global $OUTPUT;

        // Determine highest setting level, which is displayed in this stage. This is relevant for considering only
        // locks of dependency settings for parent settings, which are not displayed in this stage.
        $highestlevel = backup_setting::ACTIVITY_LEVEL;
        foreach ($settingstasks as $st) {
            list($setting, $task) = $st;
            if ($setting->get_level() < $highestlevel) {
                $highestlevel = $setting->get_level();
            }
        }

        $defaults = array();
        foreach ($settingstasks as $st) {
            list($setting, $task) = $st;
            // If the setting cant be changed or isn't visible then add it as a fixed setting.
            if (!$setting->get_ui()->is_changeable($highestlevel) ||
                $setting->get_visibility() != backup_setting::VISIBLE) {
                $this->add_fixed_setting($setting, $task);
                continue;
            }

            // First add the formatting for this setting.
            $this->add_html_formatting($setting);

            // Then call the add method with the get_element_properties array.
            call_user_func_array(array($this->_form, 'addElement'), $setting->get_ui()->get_element_properties($task, $OUTPUT));
            $this->_form->setType($setting->get_ui_name(), $setting->get_param_validation());
            $defaults[$setting->get_ui_name()] = $setting->get_value();
            if ($setting->has_help()) {
                list($identifier, $component) = $setting->get_help();
                $this->_form->addHelpButton($setting->get_ui_name(), $identifier, $component);
            }
            $this->_form->addElement('html', html_writer::end_tag('div'));
        }
        $this->_form->setDefaults($defaults);
        return true;
    }
249911
public function addTables(array $tables)
    {
        if (is_array($tables) && count($tables) > 0)
        {
            foreach ($tables as $t)
            {
                $this->addTable($t);
            }
        }

        return $this;
    }
1042752
public function onQueue(TasksHandler $tasks)
    {
        // Create the task instance
        $notify = new Notify($this->container);
        $notify->setNotifier($this);

        $tasks->addTaskListeners('deploy', 'before', [clone $notify], -10);
        $tasks->addTaskListeners('deploy', 'after', [clone $notify], -10);
        $tasks->addTaskListeners('deploy', 'halt', [clone $notify], -10);
        $tasks->addTaskListeners('rollback', 'after', [clone $notify], -10);
    }
476006
public function getTasks($tasks, $throwException = false)
    {
        $data = $this->query($throwException);

        $ret = [];
        foreach ($tasks as $task) {
            $ret[$task->getId()] = $this->formatTask($task, $data);
        }

        return $ret;
    }
1326724
public function waiting(array $tasks, $full = true) {
		$formattedTasks = $this->_formatWaiting($tasks, true);
		$tasksCount = count($formattedTasks);
		if ($tasksCount === 0) {
			return $this->_none();
		}

		if ($this->_isCli) {
			return implode(', ', $formattedTasks);
		} elseif ($full) {
			return implode(', ', $this->_formatWaiting($tasks, false));
		} else {
			$text = implode(', ', $this->_formatWaiting(array_slice($tasks, 0, Configure::read('Task.truncateWaitFor')), false));
			$text .= $tasksCount > Configure::read('Task.truncateWaitFor') ? '...' : '';
			return $this->Html->tag('span', $text, array(
						'title' => implode(', ', $formattedTasks)
			));
		}
	}
401664
public static function async(array $tasks): array
    {
        $server = App::$server->getServer();

        $result = [];
        foreach ($tasks as $task) {
            if (! isset($task['type']) || ! isset($task['name']) || ! isset($task['method']) || ! isset($task['params'])) {
                App::error(sprintf('Task %s format error.', $task['name'] ?? '[UNKNOWN]'));
                continue;
            }

            if ($task['type'] !== static::TYPE_ASYNC) {
                App::error(sprintf('Task %s is not a asynchronous task.', $task['name']));
                continue;
            }

            $data = TaskHelper::pack($task['name'], $task['method'], $task['params'], $task['type']);
            $result[] = $server->task($data);
        }

        return $result;
    }
964756
public function addHeaders(array $headers = [])
    {
        $this->headers = [];
        if($headers != []) {
            foreach ($headers as $header) {
                $this->headers[] = $header;
            }
        }
        return $this;
    }
746678
public function tasksEdit($task, $site = null)
    {
        if (!count($task)) {
            throw new \InvalidArgumentException(
                'Parameter `task` must contain a data'
            );
        }

        /* @noinspection PhpUndefinedMethodInspection */
        return $this->client->makeRequest(
            "/tasks/{$task['id']}/edit",
            "POST",
            $this->fillSite(
                $site,
                ['task' => json_encode($task)]
            )
        );
    }
885914
public function runInFolder($folder = null, $tasks = [])
    {
        // Convert to array
        if (!is_array($tasks)) {
            $tasks = [$tasks];
        }

        // Prepend folder
        array_unshift($tasks, 'cd '.$this->paths->getFolder($folder));

        return $this->run($tasks);
    }
731364
public function loadTasks()
    {
        if ($this->tasks === true || empty($this->tasks) || empty($this->Tasks)) {
            return true;
        }
        $this->_taskMap = $this->Tasks->normalizeArray((array)$this->tasks);
        $this->taskNames = array_merge($this->taskNames, array_keys($this->_taskMap));

        $this->_validateTasks();

        return true;
    }
823975
public function sendAllAsync(array $requests)
    {
        return $this->httpClient->sendAsync($this->createRequest(
            RequestInterface::BATCH,
            $this->getBatchRequestOptions($requests)
        ))->then(function (ResponseInterface $response) {
            return $this->getBatchResponses($response);
        });
    }
44585
public function canWork($task)
    {
        foreach ($this as $worker) {
            if ($worker->canWork($task)) {
                return true;
            }
        }
        return false;
    }