/** * @param $data * @param null $dbVersion * @throws \Exception * @return ApplyResult */ public function applySnapshot($data, $dbVersion = null) { $data = $this->handleNullValues($data); $prop = new \CIBlockProperty(); $res = new ApplyResult(); $extId = $data['ID']; if ($dbVersion) { $data['IBLOCK_ID'] = $this->getReferenceController()->getCurrentIdByOtherVersion($data['IBLOCK_ID'], ReferenceController::GROUP_IBLOCK, $dbVersion); $id = $this->getCurrentVersionId($extId, $dbVersion); } else { $id = $extId; } if (!$dbVersion && !PropertyTable::getById($id)->fetch()) { unset($data['VERSION']); $addRes = PropertyTable::add(array('ID' => $id, 'NAME' => $data['NAME'], 'IBLOCK_ID' => $data['IBLOCK_ID'])); if (!$addRes->isSuccess()) { throw new \Exception('Ќе удалось возобновить свойство текущей версии. ' . implode(', ', $addRes->getErrorMessages()) . "\n" . var_export($data, true)); } } if ($id && PropertyTable::getById($id)->fetch()) { $res->setSuccess((bool) $prop->Update($id, $data)); } else { $res->setSuccess((bool) ($id = $prop->Add($data))); $this->registerCurrentVersionId($id, $this->getReferenceValue($extId, $dbVersion)); } $res->setId($id); if ($data['PROPERTY_TYPE'] == self::LIST_TYPE_SIGN && !empty($data['~property_list_values'])) { $this->_applyPropertyListTypeValues($id, $data['~property_list_values']); } return $res->setMessage($prop->LAST_ERROR); }