Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
WorkflowService.php
1<?php
2
4
9use Bitrix\Bizproc\Workflow\Entity\EO_WorkflowMetadata;
12
14{
15 private const PREFIX_LOC_ID = 'BIZPROC_LIB_API_WORKFLOW_SERVICE_';
16 private const UNKNOWN_CREATE_WORKFLOW_ERROR = 'UNKNOWN_CREATE_WORKFLOW_ERROR';
17
18 private WorkflowAccessService $accessService;
19
20 public function __construct(?WorkflowAccessService $accessService = null)
21 {
22 $this->accessService = $accessService ?? new WorkflowAccessService();
23 }
24
26 {
27 $response = new StartWorkflowResponse();
28
29 $accessRequest = new CheckStartWorkflowRequest(
30 userId: $request->userId,
31 complexDocumentId: $request->complexDocumentId,
32 parameters: [
33 \CBPDocument::PARAM_TAGRET_USER => 'user_' . $request->targetUserId,
34 'DocumentCategoryId' => $request->documentCategoryId,
35 ],
36 );
37 $accessResponse = $this->accessService->checkStartWorkflow($accessRequest);
38 if (!$accessResponse->isSuccess())
39 {
40 $response->addErrors($accessResponse->getErrors());
41
42 return $response;
43 }
44 if (isset($request->startDuration) && $request->startDuration < 0)
45 {
46 throw new ArgumentException('Start duration must be non negative');
47 }
48
49 $startWorkflowErrors = [];
50 $instanceId = \CBPDocument::startWorkflow(
51 $request->templateId,
52 $request->complexDocumentId,
53 $request->parameters,
54 $startWorkflowErrors,
55 $request->parentWorkflow,
56 );
57
58 if ($startWorkflowErrors)
59 {
60 foreach ($startWorkflowErrors as $error)
61 {
62 if (is_numeric($error['code']))
63 {
64 $response->addError(new Error($error['message'], (int)$error['code']));
65 }
66 else
67 {
68 $response->addError(new Error($error['message']));
69 }
70 }
71 }
72 elseif (is_null($instanceId))
73 {
74 $response->addError(
75 new Error(Loc::getMessage(static::PREFIX_LOC_ID . static::UNKNOWN_CREATE_WORKFLOW_ERROR))
76 );
77 }
78 else
79 {
80 if (isset($request->startDuration))
81 {
82 $metadata = new EO_WorkflowMetadata();
83
84 $metadata->setWorkflowId($instanceId);
85 $metadata->setStartDuration($request->startDuration);
86 $metadata->save();
87 }
88
89 $response->setWorkflowId($instanceId);
90 }
91
92 return $response;
93 }
94}
startWorkflow(StartWorkflowRequest $request)
__construct(?WorkflowAccessService $accessService=null)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29