/** * Updates an existed location * * @param integer $primary location primary key of a element being updated * @param mixed[] $data new data to set. Additional data keys could be passed: * * <ul> * <li> * NAME string[] : update name string for specified location * </li> * <li> * EXTERNAL string[] : update external data records for specified location * </li> * </ul> * * @param mixed[] $behaviour an additional behaviour flags: * * <ul> * <li> * REBALANCE boolean (default: true) : do rebalancing after add * </li> * </ul> * * @return Bitrix\Main\Entity\UpdateResult the result of update operation */ public static function update($primary, $data = array(), $behaviour = array('REBALANCE' => true)) { $primary = Assert::expectIntegerPositive($primary, false, Loc::getMessage('SALE_LOCATION_LOCATION_ENTITY_BAD_ARGUMENT_PRIMARY_UNSET_EXCEPTION')); if (!is_array($behaviour)) { $behaviour = array(); } if (!isset($behaviour['REBALANCE'])) { $behaviour['REBALANCE'] = true; } if (!isset($behaviour['RESET_LEGACY'])) { $behaviour['RESET_LEGACY'] = true; } // first update parent, and if it succeed, do updates of the connected data if (isset($data['EXTERNAL'])) { $external = $data['EXTERNAL']; unset($data['EXTERNAL']); } if (isset($data['NAME'])) { $name = $data['NAME']; unset($data['NAME']); } // force code to lowercase if (isset($data['CODE'])) { $data['CODE'] = ToLower($data['CODE']); } // you are not allowed to modify tree data over LocationTable::update() self::applyRestrictions($data); $updResult = parent::update($primary, $data, $behaviour); // update connected data if ($updResult->isSuccess()) { // external if (isset($external)) { ExternalTable::updateMultipleForOwner($primary, $external); } // names if (isset($name)) { Name\LocationTable::updateMultipleForOwner($primary, $name); } if ($behaviour['RESET_LEGACY'] && (intval($data['TYPE_ID']) || isset($data['PARENT_ID']))) { $type = TypeTable::getList(array('filter' => array('=ID' => $data['TYPE_ID']), 'select' => array('CODE')))->fetch(); if (strlen($type['CODE']) && in_array($type['CODE'], array('COUNTRY', 'REGION', 'CITY'))) { static::resetLegacyPath(); } } $GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data'); } return $updResult; }
/** * Updates an existed location * * @param integer $primary location primary key of a element being updated * @param mixed[] $data new data to set. Additional data keys could be passed: * * <ul> * <li> * NAME string[] : update name string for specified location * </li> * <li> * EXTERNAL string[] : update external data records for specified location * </li> * </ul> * * @param mixed[] $behaviour an additional behaviour flags: * * <ul> * <li> * REBALANCE boolean (default: true) : do rebalancing after add * </li> * </ul> * * @return Bitrix\Main\Entity\UpdateResult the result of update operation */ public static function update($primary, $data = array(), $behaviour = array('REBALANCE' => true)) { $primary = Assert::expectIntegerPositive($primary, false, Loc::getMessage('SALE_LOCATION_LOCATION_ENTITY_BAD_ARGUMENT_PRIMARY_UNSET_EXCEPTION')); // first update parent, and if it succeed, do updates of the connected data if (isset($data['EXTERNAL'])) { $external = $data['EXTERNAL']; unset($data['EXTERNAL']); } if (isset($data['NAME'])) { $name = $data['NAME']; unset($data['NAME']); } // force code to lowercase if (isset($data['CODE'])) { $data['CODE'] = ToLower($data['CODE']); } // you are not allowed to modify tree data over LocationTable::update() self::applyRestrictions($data); $updResult = parent::update($primary, $data, $behaviour); // update connected data if ($updResult->isSuccess()) { // external if (isset($external)) { ExternalTable::updateMultipleForOwner($primary, $external); } // names if (isset($name)) { Name\LocationTable::updateMultipleForOwner($primary, $name); } } $GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data'); return $updResult; }