protected function terminateWorkflow($workflowId, $elementId) { $this->checkPermission(); if (!CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::StartWorkflow, $this->getUser(), BizProcDocument::getDocumentComplexId($this->iblockTypeId, $elementId), array("DocumentStates" => $this->documentStates))) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_LAC_ACCESS_DENIED')))); } if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } if (CIBlockElementRights::userHasRightTo($this->iblockId, $elementId, "element_rights_edit")) { $errors = array(); CBPDocument::terminateWorkflow($workflowId, BizProcDocument::getDocumentComplexId($this->iblockTypeId, $elementId), $errors); foreach ($errors as $error) { $this->errorCollection->add(array(new Error($error["message"]))); } } else { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_LAC_ACCESS_DENIED')))); } if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } }
/** * @param string $workflowId * @param string $iblockType * @param int $elementId * @param int $iblockId * @param string $action Action stop or delete * @return string error */ public static function completeWorkflow($workflowId, $iblockType, $elementId, $iblockId, $action) { if (!Loader::includeModule('bizproc')) { return Loc::getMessage('LISTS_MODULE_BIZPROC_NOT_INSTALLED'); } 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; }