1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Data Migrations class |
5
|
|
|
* |
6
|
|
|
* Migration from file, to file, from web, to web |
7
|
|
|
* |
8
|
|
|
* @author Alexey Krupskiy <[email protected]> |
9
|
|
|
* @link http://inji.ru/ |
10
|
|
|
* @copyright 2015 Alexey Krupskiy |
11
|
|
|
* @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
12
|
|
|
*/ |
13
|
|
|
class Migrations extends \Module { |
14
|
|
|
|
15
|
|
|
public $ids = []; |
16
|
|
|
public $migrationObjects = []; |
17
|
|
|
|
18
|
|
|
public function startMigration($migrationId, $mapId, $filePath) { |
19
|
|
|
$log = new \Migrations\Log(); |
20
|
|
|
$log->migration_id = $migrationId; |
21
|
|
|
$log->migration_map_id = $mapId; |
22
|
|
|
$log->source = $filePath; |
23
|
|
|
$log->save(); |
24
|
|
|
|
25
|
|
|
$reader = new Migrations\Reader\Xml(); |
26
|
|
|
if (!$reader->loadData($filePath)) { |
27
|
|
|
$event = new Migrations\Log\Event(); |
28
|
|
|
$event->log_id = $log->id; |
29
|
|
|
$event->type = 'load_data_error'; |
30
|
|
|
$event->save(); |
31
|
|
|
return false; |
32
|
|
|
} |
33
|
|
|
$walker = new \Migrations\Walker(); |
34
|
|
|
$walker->migration = Migrations\Migration::get($migrationId); |
35
|
|
|
$walker->map = Migrations\Migration\Map::get($mapId); |
36
|
|
|
$walker->data = $reader->getArray(); |
37
|
|
|
$walker->migtarionLog = $log; |
38
|
|
|
$walker->walk(); |
39
|
|
|
$log->result = 'success'; |
40
|
|
|
$log->save(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function loadParseIds($type) { |
44
|
|
|
$this->ids['parseIds'][$type] = \Migrations\Id::getList(['where' => ['type', $type], 'key' => 'parse_id']); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function loadObjectIds($type) { |
48
|
|
|
$this->ids['objectIds'][$type] = \Migrations\Id::getList(['where' => ['type', $type], 'key' => 'object_id']); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
View Code Duplication |
public function findObject($parseId, $type) { |
52
|
|
|
if (empty($this->ids['parseIds'][$type])) { |
53
|
|
|
$this->loadParseIds($type); |
54
|
|
|
ksort($this->ids['parseIds'][$type]); |
55
|
|
|
} |
56
|
|
|
if (!empty($this->ids['parseIds'][$type][$parseId])) { |
57
|
|
|
return $this->ids['parseIds'][$type][$parseId]; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
public function findParse($objectId, $type) { |
62
|
|
|
if (empty($this->ids['objectIds'][$type])) { |
63
|
|
|
$this->loadObjectIds($type); |
64
|
|
|
ksort($this->ids['objectIds'][$type]); |
65
|
|
|
} |
66
|
|
|
if (!empty($this->ids['objectIds'][$type][$objectId])) { |
67
|
|
|
return $this->ids['objectIds'][$type][$objectId]; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getMigrationObject($objectId) { |
72
|
|
|
if (empty($this->migrationObjects)) { |
73
|
|
|
$this->migrationObjects = \Migrations\Migration\Object::getList(); |
74
|
|
|
} |
75
|
|
|
if (!empty($this->migrationObjects[$objectId])) { |
76
|
|
|
return $this->migrationObjects[$objectId]; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|