• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/internals/counter/event/usereventprocessor.php
  • Класс: BitrixTasksInternalsCounterEventUserEventProcessor
  • Вызов: UserEventProcessor::process
public function process(): void
{
	$deletedTasks = EventCollection::getInstance()->getTasksByEventType(EventDictionary::EVENT_AFTER_TASK_DELETE);

	$toUpdate = [
		CounterDictionary::COUNTER_NEW_COMMENTS => [],
		CounterDictionary::COUNTER_EXPIRED => []
	];
	$efficiencyUpdated = [];
	$readAll = null;
	$toDelete = [];

	$originData = $this->getResourceCollection()->getOrigin();
	$updatedData = $this->getResourceCollection()->getModified();

	$events = (EventCollection::getInstance())->list();
	foreach ($events as $event)
	{
		/* @var $event Event */
		$userId = $event->getUserId();
		$taskId = $event->getTaskId();
		$eventType = $event->getType();

		if ($eventType === EventDictionary::EVENT_AFTER_COMMENTS_READ_ALL)
		{
			$readAll = $event;
			continue;
		}

		if ($eventType === EventDictionary::EVENT_AFTER_TASK_DELETE)
		{
			$efficiencyUpdated[$taskId] = $taskId;
			if (array_key_exists($taskId, $originData))
			{
				$toDelete[$taskId] = $originData[$taskId];
			}
		}

		/**
		 * need to update expires and comments counter
		 */
		if (in_array($eventType, [
			EventDictionary::EVENT_AFTER_TASK_RESTORE,
			EventDictionary::EVENT_AFTER_TASK_ADD,
			EventDictionary::EVENT_AFTER_TASK_MUTE,
			EventDictionary::EVENT_AFTER_TASK_UPDATE,
			EventDictionary::EVENT_TASK_EXPIRED
		]))
		{
			$toUpdate[CounterDictionary::COUNTER_EXPIRED][] = $taskId;
			$toUpdate[CounterDictionary::COUNTER_NEW_COMMENTS][] = $taskId;
			$efficiencyUpdated[$taskId] = $taskId;
		}

		/**
		 * need to update comments counter
		 */
		if ($eventType === EventDictionary::EVENT_AFTER_TASK_VIEW)
		{
			$counts = Counter::getInstance($userId)->getCommentsCount([$taskId]);
			if (isset($counts[$taskId]) && $counts[$taskId] > 0)
			{
				$toUpdate[CounterDictionary::COUNTER_NEW_COMMENTS][] = $taskId;
			}
		}

		if (in_array($eventType, [
			EventDictionary::EVENT_AFTER_COMMENT_ADD,
			EventDictionary::EVENT_AFTER_COMMENT_DELETE,
			EventDictionary::EVENT_AFTER_TASK_MUTE
		]))
		{
			$toUpdate[CounterDictionary::COUNTER_NEW_COMMENTS][] = $taskId;
		}

		/**
		 * need to remove agent
		 */
		if ($eventType === EventDictionary::EVENT_AFTER_TASK_DELETE)
		{
			Agent::remove($taskId);
		}

		/**
		 * need to add agent
		 */
		if (
			in_array($eventType, [
				EventDictionary::EVENT_AFTER_TASK_RESTORE,
				EventDictionary::EVENT_AFTER_TASK_ADD
			])
			&& array_key_exists($taskId, $updatedData)
			&& !in_array($taskId, $deletedTasks)
		)
		{
			/** @var EventResource $task */
			$task = $updatedData[$taskId];
			if ($task->getDeadline() && !$task->isExpired())
			{
				Agent::add($taskId, $task->getDeadline());
			}
		}

		/**
		 * need to update agent
		 */
		if (
			$eventType === EventDictionary::EVENT_AFTER_TASK_UPDATE
			&& array_key_exists($taskId, $originData)
			&& array_key_exists($taskId, $updatedData)
			&& !in_array($taskId, $deletedTasks)
		)
		{
			/** @var EventResource $oldTask */
			$oldTask = $originData[$taskId];
			/** @var EventResource $newTask */
			$newTask = $updatedData[$taskId];
			$this->updateAgents($oldTask, $newTask);
		}
	}

	$readAllUser = 0;
	if ($readAll)
	{
		$readAllUser = $readAll->getUserId();
		(new CounterController($readAllUser))->readAll($readAll->getGroupId(), $readAll->getData()['ROLE']);
	}

	$deletedMembers = $this->handleDeleted($toDelete);
	$members = $this->handleUpdated($toUpdate, $toDelete, $readAllUser);

	$users = array_unique(array_merge($members, $deletedMembers));
	(new PushSender())->sendUserCounters($users);

	if (!empty($efficiencyUpdated))
	{
		(new CounterProcessorEfficiencyProcessor())->recount($efficiencyUpdated);
	}
}