Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workgrouptaskspinmigration.php
1<?php
2
4
5use Bitrix\Main\Entity\ReferenceField;
14use Bitrix\Tasks\Internals\Project\UserOption\UserOptionTypeDictionary;
15use Bitrix\Tasks\Internals\Task\ProjectUserOptionTable;
16
17Loc::loadMessages(__FILE__);
18
20{
21 protected static $moduleId = 'socialnetwork';
22
23 public function execute(array &$result)
24 {
25 if (
26 !(
27 Loader::includeModule(self::$moduleId)
28 && Loader::includeModule('tasks')
29 && Option::get('socialnetwork', 'needWorkgroupTaskPinMigration', 'Y') === 'Y'
30 )
31 )
32 {
33 return false;
34 }
35
36 $return = false;
37
38 $params = Option::get('socialnetwork', 'workgrouptaskspinmigration');
39 $params = ($params !== '' ? @unserialize($params, [ 'allowed_classes' => false ]) : []);
40 $params = (is_array($params) ? $params : []);
41
42 if (empty($params))
43 {
44 $params = [
45 'lastId' => 0,
46 'number' => 0,
47 'count' => $this->getCount(),
48 ];
49 }
50
51 if ($params['count'] > 0)
52 {
53 $result['title'] = Loc::getMessage('FUPD_WORKGROUP_TASKS_PIN_MIGRATION_TITLE');
54 $result['progress'] = 1;
55 $result['steps'] = '';
56 $result['count'] = $params['count'];
57
58 $res = (new \Bitrix\Main\Entity\Query(ProjectUserOptionTable::getEntity()))
59 ->registerRuntimeField(
60 new ReferenceField(
61 'PROJECT',
62 WorkgroupTable::getEntity(),
63 [ '=this.PROJECT_ID' => 'ref.ID' ],
64 [ 'join_type' => 'INNER' ]
65 )
66 )
67 ->addFilter('>ID', $params['lastId'])
68 ->addFilter('=OPTION_CODE', UserOptionTypeDictionary::OPTION_PINNED)
69 ->addSelect('ID')
70 ->addSelect('PROJECT_ID')
71 ->addSelect('USER_ID')
72 ->addSelect('PROJECT.SCRUM_MASTER_ID')
73 ->setOffset(0)
74 ->setLimit(50)
75 ->exec();
76
77 $found = false;
78 while ($userOptionItem = $res->fetchObject())
79 {
80 $groupId = $userOptionItem->get('PROJECT_ID');
81 $userId = $userOptionItem->get('USER_ID');
82 $projectItem = $userOptionItem->get('PROJECT');
83 $context = (
84 (int)$projectItem->get('SCRUM_MASTER_ID') > 0
87 );
88
89 $params['number']++;
90 $params['lastId'] = $userOptionItem->getId();
91
92 if (WorkgroupPinTable::getList([
93 'filter' => [
94 '=GROUP_ID' => $groupId,
95 '=USER_ID' => $userId,
96 '=CONTEXT' => $context,
97 ],
98 ])->fetchObject())
99 {
100 continue;
101 }
102
103 WorkgroupPinTable::add([
104 'GROUP_ID' => $groupId,
105 'USER_ID' => $userId,
106 'CONTEXT' => $context,
107 ]);
108
109 $found = true;
110 }
111
112 if ($found)
113 {
114 Option::set('socialnetwork', 'workgrouptaskspinmigration', serialize($params));
115 $return = true;
116 }
117
118 $result['progress'] = (int)($params['number'] * 100 / $params['count']);
119 $result['steps'] = $params['number'];
120
121 if ($found === false)
122 {
123 Option::delete('socialnetwork', [ 'name' => 'workgrouptaskspinmigration' ]);
124 Option::set('socialnetwork', 'needWorkgroupTaskPinMigration', 'N');
125 }
126 }
127
128 return $return;
129 }
130
131 private function getCount(): int
132 {
133 return (new \Bitrix\Main\Entity\Query(ProjectUserOptionTable::getEntity()))
134 ->addFilter('=OPTION_CODE', UserOptionTypeDictionary::OPTION_PINNED)
135 ->addSelect('ID')
136 ->countTotal(true)
137 ->exec()
138 ->getCount();
139 }
140}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29