• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/tree.php
  • Класс: BitrixSaleLocationis
  • Вызов: is::manageFreeSpace
static function manageFreeSpace($right, $length = 2, $op = self::SPACE_ADD, $exceptId = false)
{
	if($length <= 1 || $right <= 0)
		return;

	// LEFT_MARGIN & RIGHT_MARGIN are system fields, user should not know about them ever, so no orm events needed to be fired on update of them

	$sign = $op == self::SPACE_ADD ? '+' : '-';

	$tableName = static::getTableName();
	$exceptId = intval($exceptId);

	$query = "update {$tableName} set 
		LEFT_MARGIN = case when LEFT_MARGIN > {$right} then LEFT_MARGIN {$sign} {$length} else LEFT_MARGIN end,
		RIGHT_MARGIN = case when RIGHT_MARGIN >= {$right} then RIGHT_MARGIN {$sign} {$length} else RIGHT_MARGIN end 
		where RIGHT_MARGIN >= {$right}".($exceptId ? " and ID <> {$exceptId}" : "");

	$shifted = MainHttpApplication::getConnection()->query($query);

	if(!$shifted)
		throw new MainSystemException('Query failed: managing free space in a tree', 0, __FILE__, __LINE__); // SaleTreeSystemException
}