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/messageservice/lib/Restriction/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/messageservice/lib/Restriction/Base.php
<?php

namespace Bitrix\MessageService\Restriction;

use Bitrix\Main\Application;
use Bitrix\Main\Config\Option;
use Bitrix\Main\Engine\CurrentUser;
use Bitrix\MessageService\Internal\Entity\RestrictionTable;
use Bitrix\MessageService\Message;

abstract class Base
{
	abstract public function getEntityId(): string;
	abstract protected function getOptionLimitName(): string;
	abstract protected function getEntity(): string;
	abstract protected function getDefaultLimit(): int;

	protected Message $message;
	protected int $counter;
	protected int $limit = 0;
	/** @var string[] */
	protected array $additionalParams = [];


	public function __construct(Message $message)
	{
		$this->message = $message;
		$this->limit = $this->initLimit();
	}

	public function setCounter(int $counter): Base
	{
		$this->counter = $counter;

		return $this;
	}

	/**
	 * @param string[] $additionalParams
	 * @return $this
	 */
	public function setAdditionalParams(array $additionalParams): Base
	{
		$this->additionalParams = $additionalParams;

		return $this;
	}

	public function canUse(): bool
	{
		return $this->limit > 0;
	}

	public function lock(): void
	{
		Application::getConnection()->lock($this->getEntityId(), 60);
	}

	public function unlock(): void
	{
		Application::getConnection()->unlock($this->getEntityId());
	}

	public function isCanSend(): bool
	{
		if (isset($this->counter))
		{
			return $this->counter < $this->limit;
		}

		return true;
	}

	public function increase(): bool
	{
		if (isset($this->counter))
		{
			return $this->updateCounter();
		}

		$this->insertCounter();

		return true;
	}

	protected function updateCounter(): bool
	{
		return RestrictionTable::updateCounter($this->getEntityId(), $this->limit);
	}

	protected function insertCounter(): void
	{
		RestrictionTable::insertCounter($this->getEntityId());
	}

	private function initLimit(): int
	{
		return (int)Option::get('messageservice', $this->getOptionLimitName(), $this->getDefaultLimit());
	}

	public function log()
	{
		if (Option::get('messageservice', 'event_log_message_send', 'N') === 'Y')
		{
			$restrictionType = mb_strtoupper($this->getOptionLimitName());
			$userId = CurrentUser::get()->getId() ?: $this->message->getAuthorId();
			$phone = $this->message->getTo();

			$description = "Restriction: $restrictionType. Phone: $phone. CurrentCounter: $this->counter. Limit: $this->limit.";

			\CEventLog::Log(
				'INFO',
				'MESSAGE_BLOCK',
				'messageservice',
				$userId,
				$description
			);
		}
	}

}

Youez - 2016 - github.com/yon3zu
LinuXploit