Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
Dldb | n/a |
0 / 0 |
n/a |
0 / 0 |
22 | n/a |
0 / 0 |
|||
getFixturesImportPath | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
setImportPath | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
startImport | n/a |
0 / 0 |
n/a |
0 / 0 |
4 | |||||
writeRequestList | n/a |
0 / 0 |
n/a |
0 / 0 |
5 | |||||
writeProviderList | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
updateAvailability | n/a |
0 / 0 |
n/a |
0 / 0 |
5 | |||||
writeRequestRelationList | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
writeLastUpdate | n/a |
0 / 0 |
n/a |
0 / 0 |
2 |
1 | <?php |
2 | |
3 | namespace BO\Zmsdb\Source; |
4 | |
5 | /** |
6 | * @codeCoverageIgnore |
7 | */ |
8 | class Dldb extends \BO\Zmsdb\Base |
9 | { |
10 | public static $importPath = ''; |
11 | public static $repository = null; |
12 | public static $verbose = false; |
13 | |
14 | public static function getFixturesImportPath() |
15 | { |
16 | $dir = dirname(__FILE__); |
17 | $importPath = realpath($dir . '/../../../tests/Zmsdb/fixtures/'); |
18 | return $importPath; |
19 | } |
20 | |
21 | public static function setImportPath($path) |
22 | { |
23 | self::$importPath = $path; |
24 | } |
25 | |
26 | public function startImport($verbose = true, $updateAvailability = true) |
27 | { |
28 | if (!static::$importPath) { |
29 | throw new \Exception('No data path given'); |
30 | } |
31 | if ($verbose) { |
32 | self::$verbose = $verbose; |
33 | print("Use source-path for dldb: " . static::$importPath . "\n\n"); |
34 | } |
35 | self::$repository = new \BO\Dldb\FileAccess(); |
36 | self::$repository->loadFromPath(static::$importPath); |
37 | |
38 | \BO\Zmsdb\Connection\Select::setTransaction(); |
39 | $this->writeRequestList(); |
40 | $providers = $this->writeProviderList(); |
41 | $this->writeRequestRelationList(); |
42 | $this->writeLastUpdate($verbose); |
43 | \BO\Zmsdb\Connection\Select::writeCommit(); |
44 | |
45 | if ($updateAvailability) { |
46 | $this->updateAvailability($providers); |
47 | } |
48 | } |
49 | |
50 | protected function writeRequestList() |
51 | { |
52 | $startTime = microtime(true); |
53 | $requestQuery = (new \BO\Zmsdb\Request()); |
54 | $requestQuery->writeDeleteListBySource('dldb'); |
55 | foreach (self::$repository->fromService()->fetchList() as $request) { |
56 | if (isset($request['relation']) && isset($request['relation']['root_topic'])) { |
57 | $topic = self::$repository->fromTopic()->fetchId($request['relation']['root_topic']); |
58 | $request['group'] = $topic['name']; |
59 | } |
60 | $requestQuery->writeImportEntity($request); |
61 | } |
62 | $time = round(microtime(true) - $startTime, 3); |
63 | if (self::$verbose) { |
64 | print("Requests: Took $time seconds\n\n"); |
65 | } |
66 | } |
67 | |
68 | protected function writeProviderList() |
69 | { |
70 | $startTime = microtime(true); |
71 | (new \BO\Zmsdb\Provider())->writeDeleteListBySource('dldb'); |
72 | $providers = (new \BO\Zmsdb\Provider())->writeImportList(self::$repository->fromLocation()->fetchList()); |
73 | |
74 | $time = round(microtime(true) - $startTime, 3); |
75 | if (self::$verbose) { |
76 | print("Provider: Took $time seconds\n\n"); |
77 | } |
78 | |
79 | return $providers; |
80 | } |
81 | |
82 | protected function updateAvailability($providers) |
83 | { |
84 | foreach ($providers as $provider) { |
85 | $providerData = $provider->data; |
86 | |
87 | $scopes = (new \BO\Zmsdb\Scope())->readByProviderId($provider->getId()); |
88 | foreach ($scopes as $scope) { |
89 | $availabilities = (new \BO\Zmsdb\Availability())->readList($scope->getId()); |
90 | |
91 | foreach ($availabilities as $availability) { |
92 | if ((int) $availability->slotTimeInMinutes === (int) $providerData['slotTimeInMinutes']) { |
93 | continue; |
94 | } |
95 | |
96 | $availability->slotTimeInMinutes = $providerData['slotTimeInMinutes']; |
97 | (new \BO\Zmsdb\Availability()) |
98 | ->updateEntity($availability->getId(), $availability, 2); |
99 | } |
100 | } |
101 | } |
102 | } |
103 | |
104 | protected function writeRequestRelationList() |
105 | { |
106 | $startTime = microtime(true); |
107 | (new \BO\Zmsdb\RequestRelation())->writeDeleteListBySource('dldb'); |
108 | (new \BO\Zmsdb\RequestRelation())->writeImportList(self::$repository->fromLocation()->fetchList()); |
109 | $time = round(microtime(true) - $startTime, 3); |
110 | if (self::$verbose) { |
111 | print("RequestRelation: Took $time seconds\n\n"); |
112 | } |
113 | } |
114 | |
115 | protected function writeLastUpdate() |
116 | { |
117 | $startTime = microtime(true); |
118 | (new \BO\Zmsdb\Config())->replaceProperty('sources_dldb_last', date('c')); |
119 | $time = round(microtime(true) - $startTime, 3); |
120 | if (self::$verbose) { |
121 | print("LastImportTimeToConfig: Took $time seconds\n\n"); |
122 | } |
123 | } |
124 | } |