- Модуль: lists
- Путь к файлу: ~/bitrix/modules/lists/lib/importer.php
- Класс: BitrixListsImporter
- Вызов: Importer::export
static function export($iblockId)
{
$iblockId = intval($iblockId);
if ($iblockId <= 0)
throw new MainArgumentNullException("iblockId");
$db = CIBlock::GetList(Array(), Array("ID" => $iblockId, "CHECK_PERMISSIONS" => "N"));
$iblock = $db->Fetch();
if (!$iblock)
throw new MainArgumentOutOfRangeException("iblockId");
if(!$iblock["CODE"])
throw new MainArgumentException("Parameter 'CODE' is required.", "matches");
foreach(CIBlock::getMessages($iblockId) as $messageKey => $message)
$iblock[$messageKey] = $message;
$list = new CList($iblockId);
$fields = $list->getFields();
foreach($fields as $fieldId => $field)
{
if ($field["TYPE"] == "NAME")
{
$iblock["~NAME_FIELD"] = array(
"NAME" => $field["NAME"],
"SETTINGS" => $field["SETTlINGS"],
"DEFAULT_VALUE" => $field["DEFAULT_VALUE"],
"SORT" => $field["SORT"],
);
break;
}
}
$iblockUtf8 = MainTextEncoding::convertEncodingArray($iblock, LANG_CHARSET, "UTF-8");
$iblockUtf8 = serialize($iblockUtf8);
$iblockUtf8Length = MainTextBinaryString::getLength($iblockUtf8);
$datum = str_pad($iblockUtf8Length, 10, "0", STR_PAD_LEFT).$iblockUtf8;
if (intval($iblock["PICTURE"]) > 0)
{
$picture = CFile::MakeFileArray($iblock["PICTURE"]);
if (isset($picture["tmp_name"]) && !empty($picture["tmp_name"]))
{
$f = fopen($picture["tmp_name"], "rb");
$pictureData = fread($f, filesize($picture["tmp_name"]));
fclose($f);
$pictureTypeLength = MainTextBinaryString::getLength($picture["type"]);
$pictureLength = MainTextBinaryString::getLength($pictureData);
$datum .= "P".str_pad($pictureTypeLength, 10, "0", STR_PAD_LEFT).$picture["type"].str_pad($pictureLength, 10, "0", STR_PAD_LEFT).$pictureData;
}
}
$documentType = self::getDocumentType($iblock["IBLOCK_TYPE_ID"], $iblockId);
$templatesList = CBPWorkflowTemplateLoader::GetList(
array(),
array("DOCUMENT_TYPE" => $documentType),
false,
false,
array("ID", "AUTO_EXECUTE", "NAME", "DESCRIPTION", "SYSTEM_CODE")
);
while ($templatesListItem = $templatesList->Fetch())
{
$bpDescrUtf8 = MainTextEncoding::convertEncodingArray($templatesListItem, LANG_CHARSET, "UTF-8");
$bpDescrUtf8 = serialize($bpDescrUtf8);
$bpDescrUtf8Length = MainTextBinaryString::getLength($bpDescrUtf8);
$datum .= "B".str_pad($bpDescrUtf8Length, 10, "0", STR_PAD_LEFT).$bpDescrUtf8;
$bp = CBPWorkflowTemplateLoader::ExportTemplate($templatesListItem["ID"], false);
$bpLength = MainTextBinaryString::getLength($bp);
$datum .= str_pad($bpLength, 10, "0", STR_PAD_LEFT).$bp;
}
if (function_exists("gzcompress"))
$datum = "compressed".gzcompress($datum, 9);
return $datum;
}