From 5ab756aad1a6664e9717d9c0d4d9b2ce87986385 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 20 Mar 2020 13:16:29 +0100 Subject: [PATCH] re-enabled importing colors from rebrickable --- src/AppBundle/Service/SetService.php | 2 +- .../Service/RebrickableLoader.php | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/AppBundle/Service/SetService.php b/src/AppBundle/Service/SetService.php index 0f25392..a77ebb4 100644 --- a/src/AppBundle/Service/SetService.php +++ b/src/AppBundle/Service/SetService.php @@ -166,7 +166,7 @@ class SetService /** @var Inventory_Part $inventoryPart */ foreach ($inventoryParts as $inventoryPart) { if ($model = $inventoryPart->getPart()->getModel()) { - $color = $inventoryPart->getCOlor(); + $color = $inventoryPart->getColor(); if (!isset($colors[$color->getId()]['color'])) { $colors[$color->getId()]['color'] = $color; diff --git a/src/LoaderBundle/Service/RebrickableLoader.php b/src/LoaderBundle/Service/RebrickableLoader.php index ed43169..06333bf 100644 --- a/src/LoaderBundle/Service/RebrickableLoader.php +++ b/src/LoaderBundle/Service/RebrickableLoader.php @@ -52,6 +52,7 @@ class RebrickableLoader extends BaseLoader 'Loading CSV files into database...', ]); + $this->loadColorTable($this->csvFile['colors']); $this->loadCategoryTable($this->csvFile['part_categories']); $this->loadPartTable($this->csvFile['parts']); $this->loadThemeTable($this->csvFile['themes']); @@ -70,7 +71,7 @@ class RebrickableLoader extends BaseLoader } catch (\Exception $e) { // $this->writeOutput(['Rollback back']); // $connection->rollBack(); - + echo $e->getMessage(); throw new LoadingRebrickableFailedException(); } } @@ -80,7 +81,7 @@ class RebrickableLoader extends BaseLoader */ private function loadCsvFiles() { - $array = ['inventories', 'inventory_parts', 'inventory_sets', 'sets', 'themes', 'parts', 'part_categories']; + $array = ['inventories', 'inventory_parts', 'inventory_sets', 'sets', 'themes', 'parts', 'part_categories', 'colors']; $this->writeOutput([ '------------------------------------------------------------------------------', @@ -103,15 +104,15 @@ class RebrickableLoader extends BaseLoader private function truncateTables() { $query = ' - DELETE FROM rebrickable_inventory_parts; - DELETE FROM rebrickable_inventory_sets; - DELETE FROM rebrickable_inventory; - DELETE FROM rebrickable_set; - DELETE FROM rebrickable_theme; - DELETE FROM rebrickable_part; - DELETE FROM rebrickable_category; + TRUNCATE rebrickable_inventory_parts; + TRUNCATE rebrickable_inventory_sets; + TRUNCATE rebrickable_inventory; + TRUNCATE rebrickable_set; + TRUNCATE rebrickable_theme; + TRUNCATE rebrickable_part; + TRUNCATE rebrickable_category; + TRUNCATE color; '; - return $this->em->getConnection()->prepare($query)->execute(); } @@ -189,8 +190,8 @@ class RebrickableLoader extends BaseLoader return $this->loadCsvFile($csv, 'rebrickable_category', '(`id`,`name`)'); } -// private function loadColorTable($csv) -// { -// return $this->loadCsvFile($csv, 'color', '(`id`,`name`,`rgb`, @var) SET transparent = IF(@var=\'t\',1,0)'); -// } + private function loadColorTable($csv) + { + return $this->loadCsvFile($csv, 'color', '(`id`,`name`,`rgb`, @var) SET transparent = IF(@var=\'t\',1,0)'); + } }