Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workflowinstance.php
1<?php
2
4
7
24class WorkflowInstanceTable extends Entity\DataManager
25{
27
31 public static function getTableName()
32 {
33 return 'b_bp_workflow_instance';
34 }
35
39 public static function getMap()
40 {
41 return array(
42 'ID' => array(
43 'data_type' => 'string',
44 'primary' => true,
45 ),
46 'MODULE_ID' => array(
47 'data_type' => 'string'
48 ),
49 'ENTITY' => array(
50 'data_type' => 'string'
51 ),
52 'DOCUMENT_ID' => array(
53 'data_type' => 'string'
54 ),
55 'WORKFLOW_TEMPLATE_ID' => array(
56 'data_type' => 'integer'
57 ),
58 'WORKFLOW' => array(
59 'data_type' => 'string'
60 ),
61 'WORKFLOW_RO' => array(
62 'data_type' => 'string'
63 ),
64 'STARTED' => array(
65 'data_type' => 'datetime'
66 ),
67 'STARTED_BY' => array(
68 'data_type' => 'integer'
69 ),
70 'STARTED_USER' => array(
71 'data_type' => '\Bitrix\Main\UserTable',
72 'reference' => array(
73 '=this.STARTED_BY' => 'ref.ID'
74 ),
75 'join_type' => 'LEFT',
76 ),
77 'STARTED_EVENT_TYPE' => array(
78 'data_type' => 'integer'
79 ),
80 'STATUS' => array(
81 'data_type' => 'integer'
82 ),
83 'MODIFIED' => array(
84 'data_type' => 'datetime'
85 ),
86 'OWNER_ID' => array(
87 'data_type' => 'string'
88 ),
89 'OWNED_UNTIL' => array(
90 'data_type' => 'datetime'
91 ),
92 'STATE' => array(
93 'data_type' => '\Bitrix\Bizproc\Workflow\Entity\WorkflowStateTable',
94 'reference' => array(
95 '=this.ID' => 'ref.ID'
96 ),
97 'join_type' => 'LEFT',
98 ),
99 'TEMPLATE' => array(
100 'data_type' => '\Bitrix\Bizproc\WorkflowTemplateTable',
101 'reference' => array(
102 '=this.WORKFLOW_TEMPLATE_ID' => 'ref.ID'
103 ),
104 'join_type' => 'LEFT'
105 ),
106 );
107 }
108
109 public static function exists(string $workflowId)
110 {
111 return static::getCount(['=ID' => $workflowId]) > 0;
112 }
113
114 public static function getIdsByDocument(array $documentId)
115 {
116 $documentId = \CBPHelper::ParseDocumentId($documentId);
117 $rows = static::getList([
118 'select' => ['ID'],
119 'filter' => [
120 '=MODULE_ID' => $documentId[0],
121 '=ENTITY' => $documentId[1],
122 '=DOCUMENT_ID' => $documentId[2]
123 ]
124 ])->fetchAll();
125
126 return array_column($rows, 'ID');
127 }
128
129 public static function getIdsByTemplateId(int ...$tplIds)
130 {
131 $filterKeyPrefix = count($tplIds) < 2 ? '=' : '@';
132 if (count($tplIds) < 2)
133 {
134 $tplIds = reset($tplIds);
135 }
136
137 $rows = static::getList([
138 'select' => ['ID'],
139 'filter' => [
140 $filterKeyPrefix.'WORKFLOW_TEMPLATE_ID' => $tplIds,
141 ]
142 ])->fetchAll();
143
144 return array_column($rows, 'ID');
145 }
146
147 public static function mergeByDocument($paramFirstDocumentId, $paramSecondDocumentId)
148 {
149 $firstDocumentId = \CBPHelper::parseDocumentId($paramFirstDocumentId);
150 $secondDocumentId = \CBPHelper::parseDocumentId($paramSecondDocumentId);
151
152 $connection = Main\Application::getConnection();
153 $sqlHelper = $connection->getSqlHelper();
154 $table = $sqlHelper->forSql(static::getTableName());
155
156 $firstDocId = $sqlHelper->forSql($firstDocumentId[2]);
157 $firstEntity = $sqlHelper->forSql($firstDocumentId[1]);
158 $firstModule = $sqlHelper->forSql($firstDocumentId[0]);
159
160 $secondDocId = $sqlHelper->forSql($secondDocumentId[2]);
161 $secondEntity = $sqlHelper->forSql($secondDocumentId[1]);
162 $secondModule = $sqlHelper->forSql($secondDocumentId[0]);
163
164 $connection->queryExecute("UPDATE {$table}
165 SET
166 DOCUMENT_ID = '{$firstDocId}',
167 ENTITY = '{$firstEntity}',
168 MODULE_ID = '{$firstModule}'
169 WHERE
170 DOCUMENT_ID = '{$secondDocId}'
171 AND ENTITY = '{$secondEntity}'
172 AND MODULE_ID = '{$secondModule}'
173 ");
174
175 return true;
176 }
177
178 public static function migrateDocumentType($paramOldType, $paramNewType, $workflowTemplateIds)
179 {
180 $oldType = \CBPHelper::parseDocumentId($paramOldType);
181 $newType = \CBPHelper::parseDocumentId($paramNewType);
182
183 $connection = Main\Application::getConnection();
184 $sqlHelper = $connection->getSqlHelper();
185 $table = $sqlHelper->forSql(static::getTableName());
186
187 $firstEntity = $sqlHelper->forSql($oldType[1]);
188 $firstModule = $sqlHelper->forSql($oldType[0]);
189
190 $secondEntity = $sqlHelper->forSql($newType[1]);
191 $secondModule = $sqlHelper->forSql($newType[0]);
192
193 $templates = implode(",", array_map('intval', $workflowTemplateIds));
194
195 $connection->queryExecute("UPDATE {$table}
196 SET
197 ENTITY = '{$firstEntity}',
198 MODULE_ID = '{$firstModule}'
199 WHERE
200 ENTITY = '{$secondEntity}'
201 AND MODULE_ID = '{$secondModule}'
202 AND WORKFLOW_TEMPLATE_ID IN ({$templates})
203 ");
204
205 return true;
206 }
207
208 public static function isDebugWorkflow(string $workflowId)
209 {
210 $row = static::getList([
211 'select' => ['STARTED_EVENT_TYPE'],
212 'filter' => [
213 '=ID' => $workflowId,
214 ]
215 ])->fetch();
216
217 return $row && (int)$row['STARTED_EVENT_TYPE'] === \CBPDocumentEventType::Debug;
218 }
219
225 public static function add(array $data)
226 {
227 throw new Main\NotImplementedException("Use CBPStateService class.");
228 }
229
236 public static function update($primary, array $data)
237 {
238 throw new Main\NotImplementedException("Use CBPStateService class.");
239 }
240}
static mergeByDocument($paramFirstDocumentId, $paramSecondDocumentId)
static migrateDocumentType($paramOldType, $paramNewType, $workflowTemplateIds)