Last active
October 19, 2024 13:56
-
-
Save SeRGei93/211fe996b691f688b29931b9d727a90b to your computer and use it in GitHub Desktop.
Чистка не используемых свойств инфоблока
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\Bitrix\Main\Loader::includeModule('iblock'); | |
$getCountValues = function ($propId){ | |
$res = \Bitrix\Iblock\ElementPropertyTable::getList([ | |
'select' => ['*'], | |
'filter' => ['ELEMENT.IBLOCK_ID' => 23, 'IBLOCK_PROPERTY_ID' => $propId], | |
'count_total' => true, | |
]); | |
return $res->getCount(); | |
}; | |
$resProp = \Bitrix\Iblock\PropertyTable::getList([ | |
'select' => ['*'], | |
'filter' => ['IBLOCK_ID' => 23, /*'=PROPERTY_TYPE' => 'S'*/] | |
]); | |
while ($propIb = $resProp->fetch()){ | |
$countValues = $getCountValues($propIb['ID']); | |
//$msg = "Свойство: {$propIb['NAME']} ({$propIb['CODE']}) - заполненных значений: {$countValues} "; | |
if ($countValues == 0){ | |
if (\CIBlockProperty::Delete($propIb['ID'])) { | |
pr("Property {$propIb['NAME']} ({$propIb['CODE']}) delete"); | |
} else { | |
throw new Exception(__METHOD__ . "Iblock property delete error!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment