1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
grouptypeconverter.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Update;
6
7use Bitrix\Main\Update\Stepper;
8use Bitrix\Socialnetwork\Internals\Group\GroupEntity;
9use Bitrix\Socialnetwork\Internals\Group\GroupEntityCollection;
10use Bitrix\Socialnetwork\Item\Workgroup\Type;
11use Bitrix\Socialnetwork\WorkgroupTable;
12
13final class GroupTypeConverter extends Stepper
14{
15 private const LIMIT = 500;
16
17 protected static $moduleId = 'socialnetwork';
18
19 private GroupEntityCollection $groups;
20
22 private array $storage = [];
23
24 private array $option;
25
26 public function execute(array &$option): bool
27 {
28 $this->option = &$option;
29
30 $this->fetchGroups();
31
32 if ($this->groups->isEmpty())
33 {
34 return self::FINISH_EXECUTION;
35 }
36
37 $this->setLastId();
38 $this->convert();
39 $this->save();
40
41 return self::CONTINUE_EXECUTION;
42 }
43
44 private function fetchGroups(): void
45 {
46 $query = WorkgroupTable::query()
47 ->setSelect(['ID', 'PROJECT', 'SCRUM_MASTER_ID', 'TYPE'])
48 // ->whereNull('TYPE') // recalc for all
49 ->where('ID', '>', $this->getLastId())
50 ->setOrder(['ID' => 'ASC'])
51 ->setLimit(self::LIMIT);
52
53 $this->groups = $query->exec()->fetchCollection();
54 }
55
56 private function convert(): void
57 {
58 foreach ($this->groups as $group)
59 {
60 $this->setType($group);
61 }
62 }
63
64 private function save(): void
65 {
66 foreach ($this->storage as $collection)
67 {
68 $collection->save(true);
69 }
70 }
71
72 private function setType(GroupEntity $group): void
73 {
74 $typeBefore = $group->getType();
75
76 if ($typeBefore === Type::Collab->value)
77 {
78 return;
79 }
80
81 if ($group->getScrumMasterId() > 0 && $group->getProject())
82 {
83 $group->setType(Type::Scrum->value);
84 }
85 elseif ($group->getProject())
86 {
87 $group->setType(Type::Project->value);
88 }
89 else
90 {
91 $group->setType(Type::getDefault()->value);
92 }
93
94 if ($typeBefore !== $group->getType())
95 {
96 $this->store($group);
97 }
98 }
99
100 private function store(GroupEntity $group): void
101 {
102 if (!isset($this->storage[$group->getType()]))
103 {
104 $this->storage[$group->getType()] = new GroupEntityCollection();
105 }
106
107 $this->storage[$group->getType()]->add($group);
108 }
109
110 private function getLastId(): int
111 {
112 return (int)($this->option['lastId'] ?? 0);
113 }
114
115 private function setLastId(): void
116 {
117 $this->option['lastId'] = max($this->groups->getIdList());
118 }
119}
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393