function DeactivateElement($action, $start_time, $interval) { $counter = array("DEL" => 0, "DEA" => 0, "NON" => 0); if (array_key_exists("bUpdateOnly", $this->next_step) && $this->next_step["bUpdateOnly"]) { return $counter; } if ($action != "D" && $action != "A") { return $counter; } $bDelete = $action == "D"; //This will protect us from deactivating when next_step is lost $IBLOCK_ID = intval($this->next_step["IBLOCK_ID"]); if ($IBLOCK_ID < 1) { return $counter; } $arFilter = array(">ID" => $this->next_step["LAST_ID"], "IBLOCK_ID" => $IBLOCK_ID); if (!$bDelete) { $arFilter["ACTIVE"] = "Y"; } $obElement = new CIBlockElement(); $rsElement = $obElement->GetList(array("ID" => "asc"), $arFilter, false, false, array("ID", "ACTIVE")); while ($arElement = $rsElement->Fetch()) { $rs = $this->_xml_file->GetList(array(), array("PARENT_ID+0" => 0, "LEFT_MARGIN" => $arElement["ID"]), array("ID")); $ar = $rs->Fetch(); if (!$ar) { if ($bDelete) { $obElement->Delete($arElement["ID"]); $counter["DEL"]++; } else { $obElement->Update($arElement["ID"], array("ACTIVE" => "N")); $counter["DEA"]++; } } else { $counter["NON"]++; } $this->next_step["LAST_ID"] = $arElement["ID"]; if ($interval > 0 && time() - $start_time > $interval) { break; } } return $counter; }
/** * <p>Индексация таблиц для ускорения доступа. Необходимо вызвать после загрузки данных из файла в таблицы БД, но до обработки этих данных. Метод динамичный. <br></p> * * * @param bool $with_sess_id = false Если значение <i>true</i>, то будут создаваться временные таблицы с * поддержкой нескольких сессий "одновременного" импорта. Введён * для совместимости. Необязательный параметр. * * @return bool <p>Если во время создания индексов произойдет ошибка БД, метод * вернет false.</p> * * <h4>See Also</h4> * <ul> <li><a href="http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblockxmlfile/index.php">CIBlockXMLFile</a></li> * </ul><br> * * * @static * @link http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblockxmlfile/indextemporarytables.php * @author Bitrix */ public static function IndexTemporaryTables($with_sess_id = false) { if (!is_object($this) || strlen($this->_table_name) <= 0) { $ob = new CIBlockXMLFile(); return $ob->IndexTemporaryTables(); } else { global $DB; $res = true; if ($with_sess_id) { if (!$DB->IndexExists($this->_table_name, array("SESS_ID", "PARENT_ID"))) { $res = $DB->DDL("CREATE INDEX ix_" . $this->_table_name . "_parent on " . $this->_table_name . "(SESS_ID, PARENT_ID)"); } if ($res && !$DB->IndexExists($this->_table_name, array("SESS_ID", "LEFT_MARGIN"))) { $res = $DB->DDL("CREATE INDEX ix_" . $this->_table_name . "_left on " . $this->_table_name . "(SESS_ID, LEFT_MARGIN)"); } } else { if (!$DB->IndexExists($this->_table_name, array("PARENT_ID"))) { $res = $DB->DDL("CREATE INDEX ix_" . $this->_table_name . "_parent on " . $this->_table_name . "(PARENT_ID)"); } if ($res && !$DB->IndexExists($this->_table_name, array("LEFT_MARGIN"))) { $res = $DB->DDL("CREATE INDEX ix_" . $this->_table_name . "_left on " . $this->_table_name . "(LEFT_MARGIN)"); } } return $res; } }
public function _testBitrixXMLParser() { \CModule::IncludeModule('iblock'); $BXParser = new \CIBlockXMLFile('dvt_yml_import_temp'); $BXParser->CreateTemporaryTables(); $NS = array(); $fp = fopen(static::_DIR_ . '/data/yml_catalog_example.xml', 'r'); $BXParser->ReadXMLToDatabase($fp, $NS, 0, 10240); }
$_SESSION["BX_HL_IMPORT"]["zip"] = $ABS_FILE_NAME; } } else { echo "failure\n", GetMessage("CC_BCIH_ERROR_FILE_WRITE", array("#FILE_NAME#" => $FILE_NAME)); } } else { echo "failure\n", GetMessage("CC_BCIH_ERROR_FILE_OPEN", array("#FILE_NAME#" => $FILE_NAME)); } } else { echo "failure\n", GetMessage("CC_BCIH_ERROR_HTTP_READ"); } } elseif ($_GET["mode"] == "import" && $_SESSION["BX_HL_IMPORT"]["zip"]) { if (!array_key_exists("last_zip_entry", $_SESSION["BX_HL_IMPORT"])) { $_SESSION["BX_HL_IMPORT"]["last_zip_entry"] = ""; } $result = CIBlockXMLFile::UnZip($_SESSION["BX_HL_IMPORT"]["zip"], $_SESSION["BX_HL_IMPORT"]["last_zip_entry"]); if ($result === false) { echo "failure\n", GetMessage("CC_BCIH_ZIP_ERROR"); } elseif ($result === true) { $_SESSION["BX_HL_IMPORT"]["zip"] = false; echo "progress\n" . GetMessage("CC_BCIH_ZIP_DONE"); } else { $_SESSION["BX_HL_IMPORT"]["last_zip_entry"] = $result; echo "progress\n" . GetMessage("CC_BCIH_ZIP_PROGRESS"); } } elseif ($_GET["mode"] == "import" && $ABS_FILE_NAME) { $this->NS =& $_SESSION["BX_HL_IMPORT"]["NS"]; $this->xmlStream = new CXMLFileStream(); $this->xmlStream->registerElementHandler("/" . GetMessage("CC_BCIH_XML_COM_INFO") . "/" . GetMessage("CC_BCIH_XML_REFERENCES"), array($this, "referenceHead")); $this->xmlStream->registerElementHandler("/" . GetMessage("CC_BCIH_XML_COM_INFO") . "/" . GetMessage("CC_BCIH_XML_REFERENCES") . "/" . GetMessage("CC_BCIH_XML_REFERENCE"), array($this, "referenceStart")); $this->xmlStream->registerElementHandler("/" . GetMessage("CC_BCIH_XML_COM_INFO") . "/" . GetMessage("CC_BCIH_XML_REFERENCES") . "/" . GetMessage("CC_BCIH_XML_REFERENCE") . "/" . GetMessage("CC_BCIH_XML_FIELDS"), array($this, "referenceItemsStart"));
$NS["STEP"] = 1; } elseif ($NS["STEP"] == 1) { if (CIBlockXMLFile::CreateTemporaryTables()) { $strMessage = GetMessage("CC_BSC1_TABLES_CREATED"); $NS["STEP"] = 2; foreach (GetModuleEvents("catalog", "OnBeforeCatalogImport1C", true) as $arEvent) { $strError = ExecuteModuleEventEx($arEvent, array($arParams, $ABS_FILE_NAME)); } } else { $strError = GetMessage("CC_BSC1_TABLE_CREATE_ERROR"); } } elseif ($NS["STEP"] == 2) { $fp = fopen($ABS_FILE_NAME, "rb"); $total = filesize($ABS_FILE_NAME); if ($total > 0 && is_resource($fp)) { $obXMLFile = new CIBlockXMLFile(); if ($obXMLFile->ReadXMLToDatabase($fp, $NS, $arParams["INTERVAL"])) { $NS["STEP"] = 3; $strMessage = GetMessage("CC_BSC1_FILE_READ"); } else { $strMessage = GetMessage("CC_BSC1_FILE_PROGRESS", array("#PERCENT#" => $total > 0 ? round($obXMLFile->GetFilePosition() / $total * 100, 2) : 0)); } fclose($fp); } else { $strError = GetMessage("CC_BSC1_FILE_ERROR"); } } elseif ($NS["STEP"] == 3) { if (CIBlockXMLFile::IndexTemporaryTables()) { $strMessage = GetMessage("CC_BSC1_INDEX_CREATED"); $NS["STEP"] = 4; } else {
//We have to strongly check all about file names at server side $ABS_FILE_NAME = false; $WORK_DIR_NAME = false; if(isset($NS["URL_DATA_FILE"]) && (strlen($NS["URL_DATA_FILE"])>0)) { $filename = trim(str_replace("\\", "/", trim($NS["URL_DATA_FILE"])), "/"); $FILE_NAME = rel2abs($_SERVER["DOCUMENT_ROOT"], "/".$filename); if((strlen($FILE_NAME) > 1) && ($FILE_NAME === "/".$filename) && ($APPLICATION->GetFileAccessPermission($FILE_NAME) >= "W")) { $ABS_FILE_NAME = $_SERVER["DOCUMENT_ROOT"].$FILE_NAME; $WORK_DIR_NAME = substr($ABS_FILE_NAME, 0, strrpos($ABS_FILE_NAME, "/")+1); } } //This object will load file into database $obXMLFile = new CIBlockXMLFile; if(!check_freetrix_sessid()) { $arErrors[] = GetMessage("IBLOCK_CML2_ACCESS_DENIED"); } elseif($ABS_FILE_NAME) { if($NS["STEP"] < 1) { //This will save mapping for ID to XML_ID translation $_SESSION["FX_CML2_IMPORT"] = array( "SECTION_MAP" => false, "PRICES_MAP" => false, );
$f = fopen($_SERVER['DOCUMENT_ROOT'] . $UPLOAD_DIR . "/bx_orders.xml", 'a+'); fwrite($f, $xml); fclose($f); $xml = trim($xml); echo '<pre style="background:white; text-align:right">текст xml-файла, который будет передан в 1С при следующем обмене</pre>'; echo '<div onmousedown="moveState = false;" onmousemove="moveState = false;" style="overflow-y:scroll;height:90%;width:100%;background:white;">'; highlight_string($xml); echo '</div>'; } else { echo $xml; } die; } if ($_GET["action"] == "show_bxmltree") { CModule::IncludeModule('iblock'); $xmlfile = new CIBlockXMLFile(); $dbres = $xmlfile->GetList(); if (!$dbres) { die; } echo '<div style="overflow:auto;height:100%;width:100%;">'; echo '<table cellspacing=2 cellpadding=5 style="border:0px solid #E6E6FA;font-size:11px;background:white;">'; echo '<tr style="background:grey;color:white;">'; echo '<td>' . 'ID' . '</td>'; echo '<td>' . 'PARENT_ID' . '</td>'; echo '<td>' . 'LEFT_MARGIN' . '</td>'; echo '<td>' . 'RIGHT_MARGIN' . '</td>'; echo '<td>' . 'DEPTH_LEVEL' . '</td>'; echo '<td>' . 'NAME' . '</td>'; echo '<td>' . 'VALUE' . '</td>'; echo '<td>' . 'ATTRIBUTES' . '</td>';