- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/update/block/nodeimg.php
- Класс: BitrixLandingUpdateBlockNodeImg
- Вызов: NodeImg::execute
public function execute(array &$result)
{
$lastId = Option::get('landing', 'update_block_nodeimg', 0);
$toSave = array();
$finished = true;
// gets common quantity
$res = BlockTable::getList(array(
'select' => array(
new BitrixMainEntityExpressionField(
'CNT', 'COUNT(*)'
)
)
));
if ($row = $res->fetch())
{
$result['count'] = $row['CNT'];
}
// gets group for update
$res = BlockTable::getList(array(
'select' => array(
'ID', 'CONTENT'
),
'filter' => array(
'>ID' => $lastId
),
'order' => array(
'ID' => 'ASC'
),
'limit' => 100
));
while ($row = $res->fetch())
{
$files = array();
$fileExist = preg_match_all(
'/data-([?fileid|filehash]+)="([^"]+)"[^>]+data-[?fileid|filehash]+="([^"]+)"/is',
$row['CONTENT'],
$matches
);
if ($fileExist)
{
foreach ($matches[1] as $i => $attr)
{
if ($attr == 'fileid')
{
$files[$matches[2][$i]] = $matches[3][$i];
}
else
{
$files[$matches[3][$i]] = $matches[2][$i];
}
}
foreach ($files as $fileId => $fileHash)
{
if ($fileId > 0 && $this->getFileHash($fileId) == $fileHash)
{
if (!isset($toSave[$row['ID']]))
{
$toSave[$row['ID']] = array();
}
$toSave[$row['ID']][] = $fileId;
}
}
}
$lastId = $row['ID'];
$result['steps']++;
$finished = false;
}
// add files from blocks
foreach ($toSave as $block => $files)
{
File::addToBlock($block, $files);
}
// clear handlers all continue work
if (!$finished)
{
Option::set('landing', 'update_block_nodeimg', $lastId);
return true;
}
else
{
Option::delete('landing', array('name' => 'update_block_nodeimg'));
$eventManager = BitrixMainEventManager::getInstance();
$eventManager->unregisterEventHandler(
'landing',
'BitrixLandingInternalsBlock::OnBeforeDelete',
'landing',
'BitrixLandingUpdateBlockNodeImg',
'disableBlockDelete');
$eventManager->unregisterEventHandler(
'landing',
'onLandingPublication',
'landing',
'BitrixLandingUpdateBlockNodeImg',
'disablePublication'
);
return false;
}
}