Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usertoworkflowstepper.php
1<?php
2
4
7
9{
10 protected static $moduleId = 'bizproc';
11
12 private const STEP_ROWS_LIMIT = 100;
13
14 public function execute(array &$option)
15 {
16 $userId = (int)$this->getOuterParams()[0];
17 $lastId = (int)($option['lastId'] ?? 0);
18 $limit = self::STEP_ROWS_LIMIT;
19
20 $connection = Application::getConnection();
21
22 $idCondition = $lastId > 0 ? " AND tu.ID < {$lastId} " : '';
23 $queryRows = $connection->query(
24 <<<SQL
25 select tu.ID from b_bp_task_user tu
26 where tu.USER_ID = {$userId} {$idCondition} order by tu.ID DESC LIMIT {$limit}
27 SQL
28 )->fetchAll();
29
30 $ids = array_column($queryRows, 'ID');
31
32 if (empty($ids))
33 {
35 }
36
37 $option['lastId'] = end($ids);
38 $idsSql = implode(',', $ids);
39
40 $connection->query(
41 <<<SQL
42 INSERT INTO b_bp_workflow_user
43 (USER_ID, WORKFLOW_ID, IS_AUTHOR, WORKFLOW_STATUS, TASK_STATUS, MODIFIED)
44 (
45 select tu.USER_ID, t.WORKFLOW_ID, 0, case when wi.id is null then 1 else 0 end,
46 case when tu.STATUS = '0' then 2 else 1 end,
47 case when tu.DATE_UPDATE is null then now() else tu.DATE_UPDATE end
48 from b_bp_task_user tu
49 inner join b_bp_task t on (t.ID = tu.TASK_ID)
50 left join b_bp_workflow_instance wi on (t.WORKFLOW_ID = wi.ID)
51 where tu.ID IN ({$idsSql})
52 )
53 ON DUPLICATE KEY UPDATE WORKFLOW_STATUS = VALUES(WORKFLOW_STATUS), TASK_STATUS = VALUES(TASK_STATUS), MODIFIED = VALUES(MODIFIED)
54 SQL
55 );
56
58 }
59
60 public static function bindUser(int $userId): void
61 {
62 static::bind(0, [$userId]);
63 }
64}
static getConnection($name="")