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/iblock/lib/FullIndex/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/iblock/lib/FullIndex/FullText.php
<?php

namespace Bitrix\Iblock\FullIndex;

use Bitrix\Main\DB\Connection;
use CIBlock;

final class FullText
{
	private const INDEX_NAME = 'IBLOCK_ELEMENT_FT_INDEX';

	private static array $existTables = [];

	public static function isTableExist(int $iblockId): bool
	{
		if (empty(self::$existTables[$iblockId]))
		{
			$connection = \Bitrix\Main\Application::getConnection();

			FullText::$existTables[$iblockId] = $connection->isTableExists(FullText::getTableName($iblockId));
		}

		return FullText::$existTables[$iblockId];
	}

	public static function isExist(int $iblockId, int $elementId): bool
	{
		$connection = \Bitrix\Main\Application::getConnection();

		$searchIndexTableName = FullText::getTableName($iblockId);

		if (!FullText::isTableExist($iblockId))
		{
			return false;
		}

		$sqlHelper = $connection->getSqlHelper();

		return !empty(
			$connection->query(
				"SELECT ELEMENT_ID FROM "
				. $sqlHelper->quote($searchIndexTableName)
				. " WHERE ELEMENT_ID = "
				. $elementId
			)->Fetch()
		);
	}

	public static function createTable(int $iblockId): void
	{
		$connection = \Bitrix\Main\Application::getConnection();

		$searchIndexTableName = FullText::getTableName($iblockId);

		if (FullText::isTableExist($iblockId))
		{
			return;
		}

		$fields = [
			'ELEMENT_ID' => (new \Bitrix\Main\ORM\Fields\IntegerField('ELEMENT_ID')),
			'SEARCH_CONTENT' => (new \Bitrix\Main\ORM\Fields\TextField('SEARCH_CONTENT'))->configureNullable(),
		];

		$connection->createTable($searchIndexTableName, $fields, ['ELEMENT_ID']);
		$connection->createIndex($searchIndexTableName, FullText::INDEX_NAME, ['SEARCH_CONTENT'], null, Connection::INDEX_FULLTEXT);

		FullText::$existTables[$iblockId] = true;
	}

	public static function drop(int $iblockId): void
	{
		$connection = \Bitrix\Main\Application::getConnection();

		if (!FullText::isTableExist($iblockId))
		{
			return;
		}

		$connection->dropTable(FullText::getTableName($iblockId));

		FullText::$existTables[$iblockId] = false;
	}

	public static function add(int $iblockId, array $searchIndexParams): void
	{
		$connection = \Bitrix\Main\Application::getConnection();

		$searchIndexTableName = FullText::getTableName($iblockId);

		if (!FullText::isTableExist($iblockId))
		{
			FullText::createTable($iblockId);
		}

		$connection->add($searchIndexTableName, $searchIndexParams, null);
	}

	public static function delete(int $iblockId, int $elementId): void
	{
		$connection = \Bitrix\Main\Application::getConnection();

		$searchIndexTableName = FullText::getTableName($iblockId);

		if (!FullText::isTableExist($iblockId))
		{
			return;
		}

		$sqlHelper = $connection->getSqlHelper();

		$connection->queryExecute("DELETE FROM " . $sqlHelper->quote($searchIndexTableName) . " WHERE ELEMENT_ID = " . $elementId);
	}

	public static function update(int $iblockId, int $elementId, array $searchIndexParams): void
	{
		$connection = \Bitrix\Main\Application::getConnection();

		$searchIndexTableName = FullText::getTableName($iblockId);

		if (!FullText::isTableExist($iblockId))
		{
			FullText::createTable($iblockId);
		}

		$helper = $connection->getSqlHelper();

		$queries = $helper->prepareMerge(
			$searchIndexTableName,
			['ELEMENT_ID'],
			array_merge(['ELEMENT_ID' => $elementId], $searchIndexParams),
			$searchIndexParams,
		);

		foreach($queries as $query)
		{
			$connection->queryExecute($query);
		}
	}

	public static function getTableName(int $iblockId): string
	{
		return 'b_iblock_' . $iblockId . '_element_search_index';
	}

	public static function doesIblockSupportById(int $iblockId): bool
	{
		return CIBlock::GetArrayByID($iblockId, "FULLTEXT_INDEX") === 'Y';
	}

	public static function doesIblockSupportByData(array $data): bool
	{
		return isset($data['FULLTEXT_INDEX']) && ($data['FULLTEXT_INDEX'] === 'Y');
	}

	public static function canUseFulltextSearch(int $iblockId): bool
	{
		return FullText::doesIblockSupportById($iblockId) && FullText::isTableExist($iblockId);
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit