Пример #1
0
 /**
  * @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;
 }
Пример #2
0
 public function processActionDeleteBizProc()
 {
     $this->checkRequiredPostParams(array('fileId', 'idBizProc'));
     if (!Loader::includeModule("bizproc")) {
         $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_FILE_VIEW_BIZPROC_LOAD')));
     }
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $fileId = (int) $this->request->getPost('fileId');
     /** @var File $file */
     $file = File::loadById((int) $fileId);
     if (!$file) {
         $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_FILE_VIEW_ERROR_COULD_NOT_FIND_OBJECT'), self::ERROR_COULD_NOT_FIND_OBJECT));
         $this->sendJsonErrorResponse();
     }
     $documentData = array('DISK' => array('DOCUMENT_ID' => \Bitrix\Disk\BizProcDocument::getDocumentComplexId($fileId)), 'WEBDAV' => array('DOCUMENT_ID' => \Bitrix\Disk\BizProcDocumentCompatible::getDocumentComplexId($fileId)));
     $webdavFileId = $file->getXmlId();
     if (!empty($webdavFileId)) {
         $documentData['OLD_FILE_COMMON'] = array('DOCUMENT_ID' => array('webdav', 'CIBlockDocumentWebdav', $webdavFileId));
         $documentData['OLD_FILE_GROUP'] = array('DOCUMENT_ID' => array('webdav', 'CIBlockDocumentWebdavSocnet', $webdavFileId));
     }
     $workflowId = $this->request->getPost('idBizProc');
     foreach ($documentData as $nameModule => $data) {
         $availabilityProcess = CBPDocument::GetDocumentState($data['DOCUMENT_ID'], $workflowId);
         if (!empty($availabilityProcess)) {
             if (CBPDocument::CanUserOperateDocument(CBPCanUserOperateOperation::CreateWorkflow, $this->getUser()->getId(), $data['DOCUMENT_ID'])) {
                 CBPTrackingService::deleteByWorkflow($workflowId);
                 CBPTaskService::deleteByWorkflow($workflowId);
                 /** @noinspection PhpDynamicAsStaticMethodCallInspection */
                 CBPStateService::deleteWorkflow($workflowId);
             }
         }
     }
     $this->sendJsonSuccessResponse();
 }