Skip to content

Instantly share code, notes, and snippets.

@SeRGei93
Last active November 4, 2021 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeRGei93/211fe996b691f688b29931b9d727a90b to your computer and use it in GitHub Desktop.
Save SeRGei93/211fe996b691f688b29931b9d727a90b to your computer and use it in GitHub Desktop.
Чистка не используемых свойств инфоблока
\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