[bitrix] export sections

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
CModule::IncludeModule("iblock");
$new_path = "/upload/full_export_iblock_12/sections_files/";
$fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/upload/full_export_iblock_12/sections.xml", "w+");
fwrite($fp, "<" . "?xml version=\"1.0\" encoding=\"UTF8\"?" . ">\n");
fwrite($fp, "<sections>\n");
$arFilter = Array('IBLOCK_ID'=>12);
$db_list = CIBlockSection::GetList(Array("ID"=>"DESC"), $arFilter, false, array("UF_*"));
while ($ar_res = $db_list->Fetch()) {
fwrite($fp, "<item>\n");
// $ipropValues = new \Bitrix\Iblock\InheritedProperty\SectionValues(
// 12,
// $ar_res["ID"]
// );
// DebugInfo::d($ipropValues->getValues());
// DebugInfo::d($ar_res);
fwrite($fp, "<name>".str_replace("&", "&amp;", $ar_res["NAME"])."</name>\n");
fwrite($fp, "<code>".$ar_res["CODE"]."</code>\n");
if(trim($ar_res["DESCRIPTION"])!="")
fwrite($fp, "<description>".htmlentities($ar_res["DESCRIPTION"], ENT_IGNORE, "UTF-8")."</description>\n");
if($ar_res["PICTURE"]) {
$pPicture = CFile::GetPath($ar_res["PICTURE"]);
$fName = basename($pPicture);
$bSaved = copy($_SERVER["DOCUMENT_ROOT"] . $pPicture, $_SERVER["DOCUMENT_ROOT"] . $new_path . $fName);
if($bSaved)
fwrite($fp, "<picture>" . $new_path . $fName . "</picture>\n");
}
if($ar_res["DETAIL_PICTURE"]) {
$dPicture = CFile::GetPath($ar_res["DETAIL_PICTURE"]);
$fName = basename($dPicture);
$bSaved = copy($_SERVER["DOCUMENT_ROOT"] . $dPicture, $_SERVER["DOCUMENT_ROOT"] . $new_path . $fName);
if($bSaved)
fwrite($fp, "<detail_picture>" . $new_path . $fName . "</detail_picture>\n");
}
if($ar_res["UF_BROWSER_TITLE"])
fwrite($fp, "<UF_BROWSER_TITLE>".$ar_res["UF_BROWSER_TITLE"]."</UF_BROWSER_TITLE>\n");
if($ar_res["UF_BROWSER_KEYWORDS"])
fwrite($fp, "<UF_BROWSER_KEYWORDS>".$ar_res["UF_BROWSER_KEYWORDS"]."</UF_BROWSER_KEYWORDS>\n");
if($ar_res["UF_BROWSER_DESCR"])
fwrite($fp, "<UF_BROWSER_DESCR>".$ar_res["UF_BROWSER_DESCR"]."</UF_BROWSER_DESCR>\n");
fwrite($fp, "</item>\n");
}
fwrite($fp, "</sections>\n");
fclose($fp);