• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblock_rights.php
  • Класс: CIBlockRightsStorage
  • Вызов: CIBlockRightsStorage::CleanUp
function CleanUp($bFull = false)
{
	$conn = MainApplication::getConnection();
	$helper = $conn->getSqlHelper();

	$iblockRightsTable = $helper->quote('b_iblock_right');
	$sectionRightsTable = $helper->quote('b_iblock_section_right');
	$elementRightsTable = $helper->quote('b_iblock_element_right');

	$iblockField = $helper->quote('IBLOCK_ID');
	$entityField = $helper->quote('ENTITY_TYPE');
	$idField = $helper->quote('ID');
	$rightIdField = $helper->quote('RIGHT_ID');

	if ($bFull)
	{
		$conn->queryExecute(
			'delete from ' . $elementRightsTable . ' where ' . $iblockField . ' = ' . $this->IBLOCK_ID
		);
		$conn->queryExecute(
			'delete from ' . $sectionRightsTable . ' where ' . $iblockField . ' = ' . $this->IBLOCK_ID
		);
		$conn->queryExecute(
			'delete from ' . $iblockRightsTable . ' where ' . $iblockField . ' = ' . $this->IBLOCK_ID
		);
	}
	else
	{
		$entityExists = $conn->queryScalar(
			'select 1 from ' . $iblockRightsTable
			. ' where ' . $iblockField . ' = ' . $this->IBLOCK_ID
			. ' and ' . $entityField . ' != 'iblock''
		);
		if ($entityExists !== null)
		{
			$subSectionRights =
				'select ' . $rightIdField . ' from  ' . $sectionRightsTable
				. ' where ' . $iblockField . ' = ' . $this->IBLOCK_ID
			;
			$subElementRights =
				'select ' . $rightIdField . ' from  ' . $elementRightsTable
				. ' where ' . $iblockField . ' = ' . $this->IBLOCK_ID
			;
			$conn->queryExecute(
				'delete from ' . $iblockRightsTable
				. ' where ' . $iblockField . ' = ' . $this->IBLOCK_ID
				. ' and ' . $entityField . ' != 'iblock''
				. ' and ' . $idField . ' not in ('
				. $subSectionRights
				. ')'
				. ' and ' . $idField . ' not in ('
				. $subElementRights
				. ')'
			);
		}
	}
}