1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
UpdateLogEntryHandler.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Collab\Control\Handler\Update;
6
7use Bitrix\Main\DI\ServiceLocator;
8use Bitrix\Main\Error;
9use Bitrix\Socialnetwork\Collab\Collab;
10use Bitrix\Socialnetwork\Collab\Control\Command\CollabUpdateCommand;
11use Bitrix\Socialnetwork\Collab\Log\CollabLogEntryCollection;
12use Bitrix\Socialnetwork\Collab\Log\Entry\UpdateCollabLogEntry;
13use Bitrix\Socialnetwork\Control\Command\UpdateCommand;
14use Bitrix\Socialnetwork\Control\Handler\HandlerResult;
15use Bitrix\Socialnetwork\Control\Handler\Update\UpdateHandlerInterface;
16use Bitrix\Socialnetwork\Item\Workgroup;
17
19{
20 private const FIELDS = [
21 'name',
22 'description',
23 ];
24
25 private const IGNORE_VALUE_FIELDS = [
26 'description',
27 ];
28
29 public function update(UpdateCommand $command, Workgroup $entityBefore, Workgroup $entityAfter): HandlerResult
30 {
31 $handlerResult = new HandlerResult();
32
33 if (!$command instanceof CollabUpdateCommand)
34 {
35 $handlerResult->addError(new Error('Unexpected command type'));
36
37 return $handlerResult;
38 }
39
40 $logEntryCollection = new CollabLogEntryCollection();
41
44
45 foreach (self::FIELDS as $field)
46 {
47 $methodName = 'get' . ucfirst($field);
48
49 if (!method_exists($entityBefore, $methodName))
50 {
51 continue;
52 }
53
54 if ($command->$methodName() === null || $entityBefore->$methodName() === $command->$methodName())
55 {
56 continue;
57 }
58
59 $logEntry = new UpdateCollabLogEntry(
60 userId: $command->getInitiatorId(),
61 collabId: $entityAfter->getId(),
62 );
63
64 $logEntry->setFieldName($field);
65
66 if (!in_array($field, self::IGNORE_VALUE_FIELDS, true))
67 {
68 $logEntry
69 ->setPreviousValue($entityBefore->$methodName())
70 ->setCurrentValue($command->$methodName())
71 ;
72 }
73
74 $logEntryCollection->add($logEntry);
75 }
76
77 $service = ServiceLocator::getInstance()->get('socialnetwork.collab.log.service');
78 $service->saveCollection($logEntryCollection);
79
80 return $handlerResult;
81 }
82}
Определения error.php:15
Определения UpdateLogEntryHandler.php:19
Определения CollabLogEntryCollection.php:9
Определения UpdateCollabLogEntry.php:8
update(UpdateCommand $command, Workgroup $entityBefore, Workgroup $entityAfter)
$service
Определения payment.php:18