1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
UpdateOwnerHandler.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Collab\Control\Handler\Update;
6
7use Bitrix\Main\Error;
8use Bitrix\SocialNetwork\Collab\Analytics\CollabAnalytics;
9use Bitrix\Socialnetwork\Collab\Control\Command\CollabUpdateCommand;
10use Bitrix\Socialnetwork\Collab\Control\Handler\Trait\UpdateMemberRoleLogTrait;
11use Bitrix\Socialnetwork\Control\Command\UpdateCommand;
12use Bitrix\Socialnetwork\Control\Handler\HandlerResult;
13use Bitrix\Socialnetwork\Control\Handler\Update\UpdateHandlerInterface;
14use Bitrix\Socialnetwork\Control\Member\Trait\UpdateMemberRoleTrait;
15use Bitrix\Socialnetwork\Item\Workgroup;
16use Bitrix\Socialnetwork\UserToGroupTable;
17use CSocNetUserToGroup;
18
20{
21 use UpdateMemberRoleLogTrait;
22 use UpdateMemberRoleTrait;
23
24 public function update(UpdateCommand $command, Workgroup $entityBefore, Workgroup $entityAfter): HandlerResult
25 {
26 $handlerResult = new HandlerResult();
27
28 if (!$command instanceof CollabUpdateCommand)
29 {
30 $handlerResult->addError(new Error('Unexpected command type'));
31
32 return $handlerResult;
33 }
34
35 $ownerId = $command->getOwnerId();
36 if ($ownerId <= 0)
37 {
38 return $handlerResult;
39 }
40
41 $beforeOwnerId = $entityBefore->getOwnerId();
42 if ($beforeOwnerId === $ownerId)
43 {
44 return $handlerResult;
45 }
46
47 $result = CSocNetUserToGroup::SetOwner($ownerId, $command->getId(), [], true);
48
49 if ($result === false)
50 {
51 $handlerResult->addApplicationError();
52 }
53
54 $result = $this->updateMembersRole($command->getId(), $command->getInitiatorId(), UserToGroupTable::ROLE_MODERATOR, $beforeOwnerId);
55
56 $handlerResult->merge($result);
57
58 $oldOwnerChangeRoleLogResult =
59 $this->writeMemberRoleUpdateLog(
60 [$entityBefore->getOwnerId()],
61 $command->getId(),
62 $command->getInitiatorId(),
64 )
65 ;
66
67 $newOwnerChangeRoleLogResult =
68 $this->writeMemberRoleUpdateLog(
69 [$command->getOwnerId()],
70 $command->getId(),
71 $command->getInitiatorId(),
73 )
74 ;
75
76 $handlerResult
77 ->merge($oldOwnerChangeRoleLogResult)
78 ->merge($newOwnerChangeRoleLogResult)
79 ;
80
81 CollabAnalytics::getInstance()->onOwnerChanged($command->getInitiatorId(), $command->getId());
82
83 return $handlerResult;
84 }
85}
Определения error.php:15
update(UpdateCommand $command, Workgroup $entityBefore, Workgroup $entityAfter)
Определения UpdateOwnerHandler.php:24
$result
Определения get_property_values.php:14