-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.php
52 lines (45 loc) · 1.26 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Created by PhpStorm.
* Parses an XML file and puts predefined entities to the DB with (almost) the same field names
* User: danil
* Date: 31.05.2018
* Time: 17:39
*/
use Models\XmlEntities\BaseEntity;
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
ini_set('display_errors', true);
ini_set('error_reporting', E_ALL);
require_once('config.php');
if (!empty(Models\DB::get())) {
echo 'DB connect OK! <br>' . PHP_EOL;
} else {
die('Exiting<br>' . PHP_EOL);
}
echo 'Opening XML...<br>' . PHP_EOL;
flush();
$data = simplexml_load_file(XML_PATH);
echo 'Found sections:<br>' . PHP_EOL;
$dbh = \Models\DB::get();
$dbh->beginTransaction();
foreach ($data as $key => $val) {
echo $key;
flush();
$classPath = \Models\XmlEntities\BaseEntity::getClassPath($key);
if ($classPath) {
/**
* @var BaseEntity $entity
*/
$entity = new $classPath();
echo '->Deprecating old items...';
flush();
$entity->deprecateOldItems($dbh);
echo '->Adding new items...';
flush();
$entity->insertNewItems($val, $entity->getFields(), $dbh);
}
echo '<br>' . PHP_EOL;
}
echo 'Importing data complete, commiting transaction<br>' . PHP_EOL;
$dbh->commit();