Skip to content

Instantly share code, notes, and snippets.

@SergeyZaigraev
Created July 13, 2017 06:10
Show Gist options
  • Save SergeyZaigraev/62b383d5c64f6b5c384453ac3520c3aa to your computer and use it in GitHub Desktop.
Save SergeyZaigraev/62b383d5c64f6b5c384453ac3520c3aa to your computer and use it in GitHub Desktop.
translit name all image in IB
<?php
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
$iblockId = (int)$_REQUEST['iblock'];
$page = isset($_REQUEST['page']) ? (int)$_REQUEST['page'] : 1;
$pageSize = 70;
$isEnd = true;
if ($iblockId <= 0)
{
ShowError('need define iblock id request');
}
else if (!$USER->IsAdmin())
{
ShowError('access denied');
}
else if (!\Bitrix\Main\Loader::includeModule('iblock') && !\Bitrix\Main\Loader::includeModule('main'))
{
ShowError('require iblock');
}
else
{
$query = \CIBlockElement::GetList(
array(
'ID' => 'ASC'
),
array(
'ACTIVE' => "Y",
'IBLOCK_ID' => $iblockId,
),
false,
array(
'iNumPage' => $page,
'nPageSize' => $pageSize
),
array(
'IBLOCK_ID',
'ID',
'PREVIEW_PICTURE',
'DETAIL_PICTURE',
'PROPERTY_ADDITIONAL_PICTURES',
)
);
$index = ($page - 1) * $pageSize;
$el = new CIBlockElement();
while ($item = $query->Fetch())
{
$newPreviewPictureArr = CFile::MakeFileArray($item["PREVIEW_PICTURE"]);
$newPreviewPictureArr['COPY_FILE'] = "Y";
$newDetailPictureArr = CFile::MakeFileArray($item["DETAIL_PICTURE"]);
$newDetailPictureArr['COPY_FILE'] = "Y";
$res = $el->Update($item['ID'], array("PREVIEW_PICTURE" => $newPreviewPictureArr,"DETAIL_PICTURE" => $newDetailPictureArr),false,false,true);
//Update additional image
$PropFileArr = array();
foreach($item['PROPERTY_ADDITIONAL_PICTURES_VALUE'] as $item2){
$PropFileArr[]['VALUE'] = $newAdditionalArr = CFile::MakeFileArray($item2);
}
CIBlockElement::SetPropertyValuesEx($item['ID'], $IBlock_ID, array("ADDITIONAL_PICTURES"=>$PropFileArr));
$index++;
}
$isEnd = ($index >= $query->SelectedRowsCount());
}
if ($isEnd)
{
echo 'Ready!';
}
else
{
$url = $APPLICATION->GetCurPageParam('page=' . ($page + 1), array('page'));
echo 'Progress...';
?>
<script>
setTimeout(function() {
window.location = <?= json_encode($url); ?>;
}, 1000);
</script>
<?
}
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment