Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
migration.php
1<?
10
11use Bitrix\Main;
13
14include_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/sale/lib/location/migration/migrate.php");
15
17{
18 const SESS_KEY = 'location_migration';
19 const NOTIF_TAG = 'SALE_LOCATIONPRO_PLZ_MIGRATE';
20
21 private $migrator = null;
22
23 public function __construct()
24 {
25 parent::__construct();
26
27 $this->addStage(array(
28 'PERCENT' => 10,
29 'CODE' => 'CREATE_TYPES',
30 'CALLBACK' => 'stageCreateTypes'
31 ));
32
33 $this->addStage(array(
34 'PERCENT' => 30,
35 'CODE' => 'CONVERT_TREE',
36 'CALLBACK' => 'stageConvertTree'
37 ));
38
39 $this->addStage(array(
40 'PERCENT' => 50,
41 'CODE' => 'CONVERT_ZONES',
42 'CALLBACK' => 'stageConvertZones'
43 ));
44
45 $this->addStage(array(
46 'PERCENT' => 70,
47 'CODE' => 'CONVERT_LINKS',
48 'CALLBACK' => 'stageConvertLinks'
49 ));
50
51 $this->addStage(array(
52 'PERCENT' => 90,
53 'STEP_SIZE' => 1,
54 'CODE' => 'COPY_DEFAULT_LOCATIONS',
55 'CALLBACK' => 'stageCopyDefaultLocations'
56 ));
57
58 $this->addStage(array(
59 'PERCENT' => 100,
60 'STEP_SIZE' => 1,
61 'CODE' => 'COPY_ZIP_CODES',
62 'CALLBACK' => 'stageCopyZipCodes'
63 ));
64 }
65
66 public function onBeforePerformIteration()
67 {
68 if(\CSaleLocation::isLocationProMigrated())
69 throw new Main\SystemException('Already migrated');
70
71 if(!isset($this->data['migrator_data']))
72 $this->migrator = new CUpdaterLocationPro();
73 else
74 $this->migrator = unserialize($this->data['migrator_data'], ['allowed_classes' => false]);
75 }
76
77 public function onAfterPerformIteration()
78 {
79 $this->data['migrator_data'] = serialize($this->migrator);
80 if($this->getPercent() == 100)
81 {
82 \CSaleLocation::locationProSetMigrated();
83 \CSaleLocation::locationProEnable();
84 }
85 }
86
87 protected function stageCreateTypes()
88 {
89 $this->migrator->createTypes();
90 $this->nextStage();
91 }
92
93 protected function stageConvertTree()
94 {
95 if($this->getStep() == 0)
96 {
97 $this->migrator->convertTree();
98 $this->nextStep();
99 }
100 else
101 {
102 $this->migrator->resetLegacyPath();
103 $this->nextStage();
104 }
105 }
106
107 protected function stageConvertZones()
108 {
109 $this->migrator->convertSalesZones();
110 $this->nextStage();
111 }
112
113 protected function stageConvertLinks()
114 {
115 $this->migrator->convertGroupLocationLinks();
116 $this->migrator->convertDeliveryLocationLinks();
117 $this->migrator->convertTaxRateLocationLinks();
118 $this->nextStage();
119 }
120
121 protected function stageCopyDefaultLocations()
122 {
123 $this->migrator->copyDefaultLocations();
124 $this->nextStage();
125 }
126
127 protected function stageCopyZipCodes()
128 {
129 $this->migrator->copyZipCodes();
130 $this->nextStage();
131 }
132
133 public function hideNotifier()
134 {
135 \CAdminNotify::DeleteByTag(
136 self::NOTIF_TAG
137 );
138 }
139}