• Модуль: location
  • Путь к файлу: ~/bitrix/modules/location/lib/repository/location/database.php
  • Класс: BitrixLocationRepositoryLocationDatabase
  • Вызов: Database::save
public function save(Location $location): Result
{
	$isNewLocation = false;

	// We can have already saved location with the same externalId and source code.
	if($location->getId() <= 0)
	{
		[$locationId, $locationCode] = $this->obtainLocationKeys($location);

		if($locationId > 0)
		{
			$location->setId($locationId);
			$location->setCode($locationCode);
		}
		else
		{
			$location->setCode($this->generateLocationCode());
		}
	}

	$fields = LocationConverterDbFieldConverter::convertToDbFields($location);

	if($location->getId() > 0)
	{
		$result = $this->locationTable::update($location->getId(), $fields);
	}
	else
	{
		$result  = $this->locationTable::add($fields);
		$isNewLocation = true;

		if($result->isSuccess())
		{
			$location->setId($result->getId());
		}
	}

	if($result->isSuccess())
	{
		$res = $this->saveName($location, $isNewLocation);

		if(!$res->isSuccess())
		{
			$result->addErrors($res->getErrors());
		}

		$res = $this->saveFields($location);

		if(!$res->isSuccess())
		{
			$result->addErrors($res->getErrors());
		}
	}

	return $result;
}