Last active
August 29, 2015 14:09
-
-
Save helloris25/39ff341b35664ed7621e to your computer and use it in GitHub Desktop.
Быстрый импорт элементов инфоблока из xml-файла с настройками по умолчанию:
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
<?php | |
$ABS_FILE_NAME = $_SERVER["DOCUMENT_ROOT"]."/xml/demo.xml"; | |
$WORK_DIR_NAME = substr($ABS_FILE_NAME, 0, strrpos($ABS_FILE_NAME, "/")+1); | |
$obXMLFile = new CIBlockXMLFile; | |
// Удаляем результат предыдущей загрузки | |
$obXMLFile->DropTemporaryTables(); | |
// Подготавливаем БД | |
if($obXMLFile->CreateTemporaryTables()) | |
{ | |
if($fp = fopen($ABS_FILE_NAME, "rb")) | |
{ | |
// Чтение содержимого файла за один шаг | |
$obXMLFile->ReadXMLToDatabase($fp, $NS, 0); | |
fclose($fp); | |
// Индексируем загруженные данные для ускорения доступа | |
if(CIBlockXMLFile::IndexTemporaryTables()){ | |
$obCatalog = new CIBlockCMLImport; | |
$obCatalog->InitEx($NS, array( | |
"files_dir" => $WORK_DIR_NAME | |
)); | |
$result = $obCatalog->ImportMetaData(1, $IBLOCK_TYPE_ID, "s1"); | |
if($result === true){ | |
$result = $obCatalog->ImportSections(); | |
$obCatalog->SectionsResort(); | |
$obCatalog->ReadCatalogData($_SESSION["BX_CML2_IMPORT"]["SECTION_MAP"], $_SESSION["BX_CML2_IMPORT"]["PRICES_MAP"]); | |
$result = $obCatalog->ImportElements(time(), 0); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment