public static function UpdatePropertyList($prop_id, $list) { foreach ($list as $id => $arEnum) { $value = trim($arEnum["VALUE"], " \t\n\r"); if (strlen($value)) { $dbEnum = CIBlockPropertyEnum::GetByID($id); if (is_array($dbEnum)) { $def = isset($arEnum["DEF"]) ? $arEnum["DEF"] : $dbEnum["DEF"]; $sort = intval($arEnum["SORT"]); if ($dbEnum["VALUE"] != $value || $dbEnum["SORT"] != $sort || $dbEnum["DEF"] != $def) { $dbEnum["VALUE"] = $value; $dbEnum["SORT"] = $sort; $dbEnum["DEF"] = $def; unset($dbEnum["ID"]); CIBlockPropertyEnum::Update($id, $dbEnum); } } else { $arEnum["PROPERTY_ID"] = $prop_id; CIBlockPropertyEnum::Add($arEnum); } } else { CIBlockPropertyEnum::Delete($id); } } }
"arProducts" => $arProducts ); } if ('N' == $keepExistingProperties) { $res = CIBlockProperty::GetList(array(), Array("IBLOCK_ID"=>$IBLOCK_ID, "!TMP_ID"=>$tmpid)); while($arr = $res->Fetch()) { CIBlockProperty::Delete($arr["ID"]); } $res = CIBlockPropertyEnum::GetList(array(), Array("IBLOCK_ID"=>$IBLOCK_ID, "!TMP_ID"=>$tmpid)); while($arr = $res->Fetch()) { CIBlockPropertyEnum::Delete($arr["ID"]); } } if ($outFileAction!="F") { $bs = new CIBlockSection; $res = CIBlockSection::GetList(array(), Array("IBLOCK_ID"=>$IBLOCK_ID, "!TMP_ID"=>$tmpid)); while($arr = $res->Fetch()) { if ($outFileAction!="H") { CIBlockSection::Delete($arr["ID"]); } else {
/** * */ public function process() { if ($this->processed) { return; } $this->processed = true; foreach ($this->generateData() as $k => $v) { $this->data[$k] = $v; } $this->update(); $o = new \CIBlock(); $mesages = $this->messages(); $o->SetMessages($this->getId(), $mesages); $fields = $this->fields(); $o->SetFields($this->getId(), $fields); $props = $this->loadProperties(); $newProps = $this->properties(); foreach ($this->urlsProps() as $key => $data) { $newProps[$key] = $data; } $o = new \CIBlockProperty(); foreach ($props as $prop => $data) { if (!isset($newProps[$prop])) { $o->Delete($data['ID']); } } foreach ($newProps as $prop => $data) { $data['CODE'] = $prop; if ($data['PROPERTY_TYPE'] == 'E' || $data['PROPERTY_TYPE'] == 'G') { if (!isset($data['LINK_IBLOCK_ID'])) { if (isset($data['LINK_IBLOCK_CODE'])) { $data['LINK_IBLOCK_ID'] = self::codeToId($data['LINK_IBLOCK_CODE']); } } } if (isset($props[$prop])) { $id = $props[$prop]['ID']; $o->Update($id, $data); } else { $data['IBLOCK_ID'] = $this->getId(); $id = $o->Add($data); } if ($data['PROPERTY_TYPE'] == 'L' && isset($data['ITEMS']) && is_array($data['ITEMS'])) { $items = array(); $newItems = $data['ITEMS']; $res = \CIBlockPropertyEnum::GetList(array(), array('PROPERTY_ID' => $id, 'CHECK_PERMISSIONS' => 'N')); while ($row = $res->Fetch()) { $iid = $row['ID']; $eid = $row['EXTERNAL_ID']; if (!isset($newItems[$eid])) { \CIBlockPropertyEnum::Delete($iid); } else { $items[$eid] = $row; } } $eo = new \CIBlockPropertyEnum(); foreach ($newItems as $eid => $edata) { if (is_string($edata)) { $edata = array('VALUE' => $edata); } $edata['PROPERTY_ID'] = $id; $edata['EXTERNAL_ID'] = $eid; $edata['XML_ID'] = $eid; if (isset($items[$eid])) { $eo->Update($items[$eid]['ID'], $edata); } else { $eo->Add($edata); } } } } }