• Модуль: bizproc
  • Путь к файлу: ~/bitrix/modules/bizproc/lib/controller/script.php
  • Класс: BitrixBizprocControllerScript
  • Вызов: Script::startAction
public function startAction($scriptId, array $documentIds, array $parameters = [])
{
	$userId = $this->getCurrentUser()->getId();
	$documentIds = array_unique($documentIds);

	if (!Manager::checkDocumentIdsLimit($documentIds))
	{
		return [
			'status' => static::START_STATUS_NOT_PERMITTED,
			'error' => Loc::getMessage(
				'BIZPROC_CONTROLLER_SCRIPT_ERROR_DOCUMENT_ID_LIMIT',
				[
					'#LIMIT#' => Manager::getDocumentIdLimit(),
					'#SELECTED#' => count($documentIds),
				]
			)
		];
	}

	$script = Manager::getById($scriptId);
	if (!$script)
	{
		return [
			'status' => static::START_STATUS_NOT_EXISTS,
			'error' => Loc::getMessage('BIZPROC_CONTROLLER_SCRIPT_NOT_EXISTS')
		];
	}
	if (!$script->getActive())
	{
		return [
			'status' => static::START_STATUS_NOT_PERMITTED,
			'error' => Loc::getMessage('BIZPROC_CONTROLLER_SCRIPT_CANT_START_INACTIVE')
		];
	}

	if (!Manager::checkQueuesCount($scriptId))
	{
		return [
			'status' => static::START_STATUS_NOT_PERMITTED,
			'error' => Loc::getMessage(
				'BIZPROC_CONTROLLER_SCRIPT_ERROR_QUEUES_LIMIT',
				[
					'#LIMIT#' => Manager::getQueuesLimit(),
					'#CNT#' => Manager::getActiveQueueCountByScriptId($scriptId),
				]
			)
		];
	}

	$script->fill('WORKFLOW_TEMPLATE');
	$tpl = $script->getWorkflowTemplate();
	if (!$tpl)
	{
		return [
			'status' => static::START_STATUS_NOT_EXISTS,
			'error' => Loc::getMessage('BIZPROC_CONTROLLER_SCRIPT_NO_TEMPLATE')
		];
	}

	$templateParameters = $tpl->getParameters();
	if ($templateParameters)
	{
		$parameters = $this->grabParameters($templateParameters, $parameters);

		if (empty($parameters))
		{
			return [
				'status' => static::START_STATUS_FILL_PARAMETERS,
				'parameters' => self::convertTemplateParameters($templateParameters, $tpl->getDocumentComplexType()),
				'documentType' => $tpl->getDocumentComplexType(),
				'scriptName' => $script->getName(),
			];
		}
	}

	$result = Manager::startScript($scriptId, $userId, $documentIds, $parameters);
	if (!$result->isSuccess())
	{
		$error = $result->getErrors()[0];
		if ($error->getCode() === StartScriptResult::CODE_NOT_ENOUGH_RIGHTS)
		{
			return [
				'status' => static::START_STATUS_NOT_PERMITTED,
				'error' => $error->getMessage(),
			];
		}
		if ($error->getCode() === StartScriptResult::CODE_INVALID_PARAMETERS)
		{
			return [
				'status' => static::START_STATUS_INVALID_PARAMETERS,
				'error' => $error->getMessage(),
			];
		}

		return [
			'error' => $error->getMessage(),
		];
	}

	return [
		'status' => static::START_STATUS_QUEUED,
		'queueId' => $result->getData()['queueId'],
	];
}