21 private const PREFIX_LOC_ID =
'BIZPROC_LIB_API_WORKFLOW_SERVICE_';
22 private const UNKNOWN_CREATE_WORKFLOW_ERROR =
'UNKNOWN_CREATE_WORKFLOW_ERROR';
39 complexDocumentId:
$request->complexDocumentId,
41 \CBPDocument::PARAM_TAGRET_USER =>
'user_' .
$request->targetUserId,
42 'DocumentCategoryId' =>
$request->documentCategoryId,
43 'WorkflowTemplateId' =>
$request->templateId,
47 $accessResponse = $this->accessService->checkStartWorkflow($accessRequest);
48 if (!$accessResponse->isSuccess())
50 $response->addErrors($accessResponse->getErrors());
61 $startWorkflowErrors = [];
62 $instanceId = \CBPDocument::startWorkflow(
70 if ($startWorkflowErrors)
72 foreach ($startWorkflowErrors as
$error)
74 if (is_numeric(
$error[
'code']))
84 elseif (is_null($instanceId))
87 new Error(Loc::getMessage(static::PREFIX_LOC_ID . static::UNKNOWN_CREATE_WORKFLOW_ERROR))
96 $metadata->setWorkflowId($instanceId);
97 $metadata->setStartDuration(
$request->startDuration);
115 Loc::getMessage(
'BIZPROC_LIB_API_WORKFLOW_SERVICE_COMPLETED')
119 $documentStates = \CBPDocument::getActiveStates($documentId);
121 if (empty($documentStates[
$request->workflowId]))
124 Loc::getMessage(
'BIZPROC_LIB_API_WORKFLOW_SERVICE_COMPLETED')
128 $canTerminate = \CBPDocument::CanUserOperateDocument(
132 [
'DocumentStates' => $documentStates]
138 Loc::getMessage(
'BIZPROC_LIB_API_WORKFLOW_SERVICE_NO_ACCESS')
152 $documentStates = \CBPDocument::getActiveStates(
$request->documentId);
154 $canTerminate = \CBPDocument::CanUserOperateDocument(
158 [
'DocumentStates' => $documentStates]
164 Loc::getMessage(
'BIZPROC_LIB_API_WORKFLOW_SERVICE_ROBOTS_NO_ACCESS')
170 $instanceIds = $this->getWorkflowInstanceIds(
$request->templateId,
$request->documentId);
172 if (empty($instanceIds))
175 Loc::getMessage(
'BIZPROC_LIB_API_WORKFLOW_SERVICE_ROBOTS_NOT_FOUND')
179 foreach ($instanceIds as $instanceId)
189 $ids = WorkflowInstanceTable::getList([
193 '=MODULE_ID' => $documentId[0],
194 '=ENTITY' => $documentId[1],
195 '=DOCUMENT_ID' => $documentId[2],
196 '@TEMPLATE.TYPE' => [WorkflowTemplateType::CustomRobots->value, WorkflowTemplateType::Robots->value],
200 return array_column($ids,
'ID');
203 private function terminateWorkflowById(
string $workflowId,
array $documentId, TerminateWorkflowResponse
$response)
206 \CBPDocument::TerminateWorkflow($workflowId, $documentId,
$errors);
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)