Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
configurer.php
1<?php
2
4
11
13{
14 private const SERVICE_DATACENTER_RU = 'ru';
15 private const SERVICE_URL_RU = 'https://osm-ru-002.bitrix.info';
16 private const MAP_SERVICE_URL_RU = 'https://osm-ru-001.bitrix.info';
17
18 private const SERVICE_DATACENTER_DE = 'de';
19 private const SERVICE_URL_DE = 'https://osm-de-002.bitrix.info';
20 private const MAP_SERVICE_URL_DE = 'https://osm-de-001.bitrix.info';
21
22 public static function configure(): void
23 {
24 $sourceRepository = new SourceRepository(new OrmConverter());
25
26 $osmSource = $sourceRepository->findByCode(Factory::OSM_SOURCE_CODE);
27 if (!$osmSource)
28 {
29 return;
30 }
31
32 $osmConfig = $osmSource->getConfig() ?? new Config();
33
34 $datacenterEndpointsMap = self::getDatacenterEndpointsMap();
35 $datacenter = self::getServiceDatacenter();
36
37 $osmConfig->setValue(
38 'SERVICE_URL',
39 $datacenterEndpointsMap[$datacenter]['SERVICE_URL']
40 );
41
42 $mapServiceUrlConfigItem = $osmConfig->getItem('MAP_SERVICE_URL');
43 if (!$mapServiceUrlConfigItem)
44 {
45 $osmConfig->addItem(
46 (new ConfigItem('MAP_SERVICE_URL', 'string'))
47 ->setIsVisible(true)
48 ->setSort(15)
49 ->setValue($datacenterEndpointsMap[$datacenter]['MAP_SERVICE_URL'])
50 );
51 }
52 else
53 {
54 $osmConfig->setValue(
55 'MAP_SERVICE_URL',
56 $datacenterEndpointsMap[$datacenter]['MAP_SERVICE_URL']
57 );
58 }
59
60 $sourceRepository->save($osmSource);
61 }
62
66 private static function getServiceDatacenter(): string
67 {
68 $region = Application::getInstance()->getLicense()->getRegion();
69 if (!$region)
70 {
71 return self::SERVICE_DATACENTER_RU;
72 }
73
74 if (in_array($region, ['ru', 'by', 'kz'], true))
75 {
76 return self::SERVICE_DATACENTER_RU;
77 }
78
79 return self::SERVICE_DATACENTER_DE;
80 }
81
85 private static function getDatacenterEndpointsMap(): array
86 {
87 return [
88 self::SERVICE_DATACENTER_RU => [
89 'SERVICE_URL' => self::SERVICE_URL_RU,
90 'MAP_SERVICE_URL' => self::MAP_SERVICE_URL_RU,
91 ],
92 self::SERVICE_DATACENTER_DE => [
93 'SERVICE_URL' => self::SERVICE_URL_DE,
94 'MAP_SERVICE_URL' => self::MAP_SERVICE_URL_DE,
95 ],
96 ];
97 }
98}