17 private const DEFAULT_DATA_PATH =
'/bitrix/modules/location/data';
24 $agent =
'\\Bitrix\\Location\\Infrastructure\\DataInstaller::installAreasAgent();';
28 if (!$connection->isTableExists(AreaTable::getTableName()))
33 $result = self::installAreas();
34 if (!$result->isSuccess())
45 private static function installAreas():
Result
52 return $result->addError(
new Error(
'Default data directory not found'));
55 $areasFile =
new IO\File(Path::combine($dataPath,
'areas.php'));
56 if (!$areasFile->isExists())
58 return $result->addError(
new Error(
'File with areas not found'));
61 $areas = include $areasFile->getPath();
62 if (!is_array($areas))
64 return $result->addError(
new Error(
'No data in areas file'));
67 $areaRepository =
new AreaRepository();
68 foreach ($areas as $area)
70 $existingArea = $areaRepository->findByTypeAndCode($area[
'TYPE'], $area[
'CODE']);
76 $areaFile =
new IO\File(Path::combine($dataPath,
'areas', $area[
'FILE']));
77 if (!$areaFile->isExists())
79 $result->addError(
new Error(
'Area file not found'));
83 $addResult = $areaRepository->store(
85 ->setType($area[
'TYPE'])
86 ->setCode($area[
'CODE'])
87 ->setSort($area[
'SORT'])
89 Manager::makeConverter(Manager::FORMAT_GEOJSON)
90 ->read($areaFile->getContents())
94 if (!$addResult->isSuccess())
96 $result->addErrors($addResult->getErrors());
static isDirectoryExists($path)