- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/update/block/duplicateimages.php
- Класс: BitrixLandingUpdateBlockDuplicateImages
- Вызов: DuplicateImages::onAfterFileDeleteDuplicate
static function onAfterFileDeleteDuplicate(EO_File $original, EO_File $duplicate)
{
// BLOCKS
$sitesToUpdate = [];
$oldPath = '/' . $duplicate->getSubdir() . '/' . $duplicate->getFileName();
$newPath = '/' . $original->getSubdir() . '/' . $original->getFileName();
$resFiles = FileTable::query()
->addSelect('ENTITY_ID')
->where('ENTITY_TYPE', '=', File::ENTITY_TYPE_BLOCK)
->where('FILE_ID', $duplicate->getId())
->exec()
;
while($blockFile = $resFiles->fetch())
{
$resBlocks = BlockTable::query()
->addSelect('ID')
->addSelect('CONTENT')
->addSelect('LANDING.SITE_ID')
->where('ID', $blockFile['ENTITY_ID'])
->exec()
;
while($block = $resBlocks->fetch())
{
BlockTable::update($block['ID'], [
'CONTENT' => str_replace($oldPath, $newPath, $block['CONTENT'])
]);
$siteId = (int)$block['LANDING_INTERNALS_BLOCK_LANDING_SITE_ID'];
if ($siteId && $siteId > 0)
{
$sitesToUpdate[] = $siteId;
}
}
}
$sitesToUpdate = array_unique($sitesToUpdate);
foreach($sitesToUpdate as $siteId)
{
Manager::clearCacheForSite($siteId);
}
// ASSETS
$landingsForUpdate = [];
$resFiles = FileTable::query()
->addSelect('ENTITY_ID')
->where('ENTITY_TYPE', '=', File::ENTITY_TYPE_ASSET)
->where('FILE_ID', $duplicate->getId())
->exec()
;
while($assetFile = $resFiles->fetch())
{
$landingsForUpdate[] = abs((int)$assetFile['ENTITY_ID']);
}
$landingsForUpdate = array_unique($landingsForUpdate);
foreach($landingsForUpdate as $landingId)
{
Manager::clearCacheForLanding($landingId);
}
}