Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| Zmsdldb | n/a |
0 / 0 |
n/a |
0 / 0 |
24 | 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 |
7 | |||||
| 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 Zmsdldb 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\Zmsdldb\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 | if ($topic && isset($topic['name'])) { |
| 59 | $request['group'] = $topic['name']; |
| 60 | } |
| 61 | } |
| 62 | $requestQuery->writeImportEntity($request); |
| 63 | } |
| 64 | $time = round(microtime(true) - $startTime, 3); |
| 65 | if (self::$verbose) { |
| 66 | print("Requests: Took $time seconds\n\n"); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | protected function writeProviderList() |
| 71 | { |
| 72 | $startTime = microtime(true); |
| 73 | (new \BO\Zmsdb\Provider())->writeDeleteListBySource('dldb'); |
| 74 | $providers = (new \BO\Zmsdb\Provider())->writeImportList(self::$repository->fromLocation()->fetchList()); |
| 75 | |
| 76 | $time = round(microtime(true) - $startTime, 3); |
| 77 | if (self::$verbose) { |
| 78 | print("Provider: Took $time seconds\n\n"); |
| 79 | } |
| 80 | |
| 81 | return $providers; |
| 82 | } |
| 83 | |
| 84 | protected function updateAvailability($providers) |
| 85 | { |
| 86 | foreach ($providers as $provider) { |
| 87 | $providerData = $provider->data; |
| 88 | |
| 89 | $scopes = (new \BO\Zmsdb\Scope())->readByProviderId($provider->getId()); |
| 90 | foreach ($scopes as $scope) { |
| 91 | $availabilities = (new \BO\Zmsdb\Availability())->readList($scope->getId()); |
| 92 | |
| 93 | foreach ($availabilities as $availability) { |
| 94 | if ((int) $availability->slotTimeInMinutes === (int) $providerData['slotTimeInMinutes']) { |
| 95 | continue; |
| 96 | } |
| 97 | |
| 98 | $availability->slotTimeInMinutes = $providerData['slotTimeInMinutes']; |
| 99 | $availability->version = $availability->version + 1; |
| 100 | (new \BO\Zmsdb\Availability()) |
| 101 | ->updateEntity($availability->getId(), $availability, 2); |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | protected function writeRequestRelationList() |
| 108 | { |
| 109 | $startTime = microtime(true); |
| 110 | (new \BO\Zmsdb\RequestRelation())->writeDeleteListBySource('dldb'); |
| 111 | (new \BO\Zmsdb\RequestRelation())->writeImportList(self::$repository->fromLocation()->fetchList()); |
| 112 | $time = round(microtime(true) - $startTime, 3); |
| 113 | if (self::$verbose) { |
| 114 | print("RequestRelation: Took $time seconds\n\n"); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | protected function writeLastUpdate() |
| 119 | { |
| 120 | $startTime = microtime(true); |
| 121 | (new \BO\Zmsdb\Config())->replaceProperty('sources_dldb_last', date('c')); |
| 122 | $time = round(microtime(true) - $startTime, 3); |
| 123 | if (self::$verbose) { |
| 124 | print("LastImportTimeToConfig: Took $time seconds\n\n"); |
| 125 | } |
| 126 | } |
| 127 | } |