1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
stepper.php
См. документацию.
1<?php
2namespace Bitrix\Bizproc\Script\Queue;
3
4use Bitrix\Bizproc\Script\Entity\EO_Script;
5use Bitrix\Bizproc\Script\Entity\EO_ScriptQueueDocument;
6use Bitrix\Bizproc\Script\Entity\ScriptQueueTable;
7use Bitrix\Bizproc\Script\Manager;
8use Bitrix\Main;
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
21
22 $result['count'] = $counters['all'];
23 $result['steps'] = $counters['completed'];
24
25 if ($result['steps'] >= $result['count'])
26 {
28 return self::FINISH_EXECUTION;
29 }
30
31 $script = Manager::getById($scriptId);
32
33 if (!$script)
34 {
35 ScriptQueueTable::delete($queueId);
36 return self::FINISH_EXECUTION;
37 }
38
39 $document = ScriptQueueTable::getNextQueuedDocument($queueId);
40
41 if (!$document)
42 {
44 return self::FINISH_EXECUTION;
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
58 if (!$queue)
59 {
60 // queue is deleted
61
62 return self::FINISH_EXECUTION;
63 }
64
65 $documentType = $documentId = [$script->getModuleId(), $script->getEntity(), $script->getDocumentType()];
66 $documentId[2] = $document->getDocumentId();
67
68 $workflowId = null;
69 $errors = [];
70
71 $canStart = \CBPDocument::canUserOperateDocument(
73 $queue->getStartedBy(),
74 $documentId
75 );
76
77 if ($canStart)
78 {
79 $startParameters = $queue->getWorkflowParameters();
80 if (!is_array($startParameters))
81 {
82 $startParameters = [];
83 }
84
85 $startParameters[\CBPDocument::PARAM_TAGRET_USER] = 'user_' . $queue->getStartedBy();
86 $startParameters[\CBPDocument::PARAM_USE_FORCED_TRACKING] = true;
87 $startParameters[\CBPDocument::PARAM_IGNORE_SIMULTANEOUS_PROCESSES_LIMIT] = true;
88 $startParameters[\CBPDocument::PARAM_DOCUMENT_TYPE] = $documentType;
89 $startParameters[\CBPDocument::PARAM_DOCUMENT_EVENT_TYPE] = \CBPDocumentEventType::Script;
90
91 $workflowId = \CBPDocument::StartWorkflow($script->getWorkflowTemplateId(), $documentId, $startParameters, $errors);
92 }
93 else
94 {
95 $errors[] = ['message' => Main\Localization\Loc::getMessage('BIZPROC_SCRIPT_QUEUE_CAN_START_ERROR')];
96 }
97
98 if ($workflowId)
99 {
100 $document->setWorkflowId($workflowId);
101 $document->setStatus(Status::COMPLETED);
102 }
103 if ($errors)
104 {
105 $document->setStatus(Status::FAULT);
106 $document->setStatusMessage(reset($errors)['message']);
107 }
108
109 $document->save();
110 return self::CONTINUE_EXECUTION;
111 }
112
113 public static function getTitle()
114 {
115 return "Script queues";
116 }
117}
static markCompleted(int $queueId)
Определения scriptqueue.php:154
static getDocumentCounters(int $queueId)
Определения scriptqueue.php:82
static getNextQueuedDocument(int $queueId)
Определения scriptqueue.php:112
static markExecuting(int $queueId)
Определения scriptqueue.php:149
static getById($id)
Определения manager.php:52
const EXECUTING
Определения status.php:9
const COMPLETED
Определения status.php:12
execute(array &$result)
Определения stepper.php:14
static getTitle()
Определения stepper.php:113
static getMessage($code, $replace=null, $language=null)
Определения loc.php:30
getOuterParams()
Определения stepper.php:212
const StartWorkflow
Определения constants.php:212
const Script
Определения constants.php:158
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$errors
Определения iblock_catalog_edit.php:74
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$counters
Определения options.php:100