Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
stepper.php
1<?php
3
4use Bitrix\Bizproc\Script\Entity\EO_Script;
5use Bitrix\Bizproc\Script\Entity\EO_ScriptQueueDocument;
9
10final class Stepper extends Main\Update\Stepper
11{
12 protected static $moduleId = 'bizproc';
13
14 public function execute(array &$result)
15 {
16 $params = $this->getOuterParams();
17 $queueId = reset($params);
18 $scriptId = next($params);
19
20 $counters = ScriptQueueTable::getDocumentCounters($queueId);
21
22 $result['count'] = $counters['all'];
23 $result['steps'] = $counters['completed'];
24
25 if ($result['steps'] >= $result['count'])
26 {
29 }
30
31 $script = Manager::getById($scriptId);
32
33 if (!$script)
34 {
35 ScriptQueueTable::delete($queueId);
37 }
38
39 $document = ScriptQueueTable::getNextQueuedDocument($queueId);
40
41 if (!$document)
42 {
45 }
46
48 return $this->executeDocument($document, $script);
49 }
50
51 private function executeDocument(EO_ScriptQueueDocument $document, EO_Script $script)
52 {
53 $document->setStatus(Status::EXECUTING)->save();
54
55 $document->fillQueue();
56 $queue = $document->getQueue();
57 $documentType = $documentId = [$script->getModuleId(), $script->getEntity(), $script->getDocumentType()];
58 $documentId[2] = $document->getDocumentId();
59
60 $workflowId = null;
61 $errors = [];
62
63 $canStart = \CBPDocument::canUserOperateDocument(
64 \CBPCanUserOperateOperation::StartWorkflow,
65 $queue->getStartedBy(),
66 $documentId
67 );
68
69 if ($canStart)
70 {
71 $startParameters = $queue->getWorkflowParameters();
72 if (!is_array($startParameters))
73 {
74 $startParameters = [];
75 }
76
77 $startParameters[\CBPDocument::PARAM_TAGRET_USER] = $queue->getStartedBy();
78 $startParameters[\CBPDocument::PARAM_USE_FORCED_TRACKING] = true;
79 $startParameters[\CBPDocument::PARAM_IGNORE_SIMULTANEOUS_PROCESSES_LIMIT] = true;
80 $startParameters[\CBPDocument::PARAM_DOCUMENT_TYPE] = $documentType;
81 $startParameters[\CBPDocument::PARAM_DOCUMENT_EVENT_TYPE] = \CBPDocumentEventType::Script;
82
83 $workflowId = \CBPDocument::StartWorkflow($script->getWorkflowTemplateId(), $documentId, $startParameters, $errors);
84 }
85 else
86 {
87 $errors[] = ['message' => Main\Localization\Loc::getMessage('BIZPROC_SCRIPT_QUEUE_CAN_START_ERROR')];
88 }
89
90 if ($workflowId)
91 {
92 $document->setWorkflowId($workflowId);
93 $document->setStatus(Status::COMPLETED);
94 }
95 if ($errors)
96 {
97 $document->setStatus(Status::FAULT);
98 $document->setStatusMessage(reset($errors)['message']);
99 }
100
101 $document->save();
103 }
104
105 public static function getTitle()
106 {
107 return "Script queues";
108 }
109}