• Модуль: lists
  • Путь к файлу: ~/bitrix/modules/lists/classes/general/lists.php
  • Класс: CLists
  • Вызов: CLists::completeWorkflow
static function completeWorkflow($workflowId, $iblockType, $elementId, $iblockId, $action)
{
	if (!Loader::includeModule('bizproc'))
	{
		return Loc::getMessage('LISTS_MODULE_BIZPROC_NOT_INSTALLED_MSGVER_1');
	}

	global $USER;
	$userId = $USER->getID();

	$documentType = BizprocDocument::generateDocumentComplexType($iblockType, $iblockId);
	$documentId = BizprocDocument::getDocumentComplexId($iblockType, $elementId);
	$documentStates = CBPDocument::getDocumentStates($documentType, $documentId);

	$permission = CBPDocument::canUserOperateDocument(
		($action == 'stop') ? CBPCanUserOperateOperation::StartWorkflow :
			CBPCanUserOperateOperation::CreateWorkflow,
		$userId,
		$documentId,
		array("DocumentStates" => $documentStates)
	);

	if(!$permission)
	{
		return Loc::getMessage('LISTS_ACCESS_DENIED');
	}

	$stringError = '';

	if($action == 'stop')
	{
		$errors = array();
		CBPDocument::terminateWorkflow(
			$workflowId,
			$documentId,
			$errors
		);

		if (!empty($errors))
		{
			$stringError = '';
			foreach ($errors as $error)
				$stringError .= $error['message'];
			$listError[] = array('id' => 'stopBizproc', 'text' => $stringError);
		}
	}
	else
	{
		$errors = array();
		if (isset($documentStates[$workflowId]['WORKFLOW_STATUS']) &&
			$documentStates[$workflowId]['WORKFLOW_STATUS'] !== null)
		{
			CBPDocument::terminateWorkflow(
				$workflowId,
				$documentId,
				$errors
			);
		}

		if (!empty($errors))
		{
			$stringError = '';
			foreach ($errors as $error)
				$stringError .= $error['message'];
			$listError[] = array('id' => 'stopBizproc', 'text' => $stringError);
		}
		else
		{
			CBPTaskService::deleteByWorkflow($workflowId);
			CBPTrackingService::deleteByWorkflow($workflowId);
			CBPStateService::deleteWorkflow($workflowId);
		}
	}

	if(empty($listError) && Loader::includeModule('socialnetwork') &&
		$iblockType == COption::getOptionString("lists", "livefeed_iblock_type_id"))
	{
		$sourceId = CBPStateService::getWorkflowIntegerId($workflowId);
		$resultQuery = CSocNetLog::getList(
			array(),
			array('EVENT_ID' => 'lists_new_element', 'SOURCE_ID' => $sourceId),
			false,
			false,
			array('ID')
		);
		while ($log = $resultQuery->fetch())
		{
			CSocNetLog::delete($log['ID']);
		}
	}

	if (!empty($listError))
	{
		$errorObject = new CAdminException($listError);
		$stringError = $errorObject->getString();
	}

	return $stringError;
}