From 9e1d85543302e20b48e6bfec690787c7b3d7d3f6 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 19 Apr 2021 06:16:13 +0000 Subject: [PATCH] Fix load serials script to save everything. #549 --- src/Entity/WarrantySerial.php | 22 ++++++++++++++++ utils/load_warranty_serial/load_serials.php | 28 +++++++++++++++++---- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/Entity/WarrantySerial.php b/src/Entity/WarrantySerial.php index 812e4106..ee55dd56 100644 --- a/src/Entity/WarrantySerial.php +++ b/src/Entity/WarrantySerial.php @@ -46,9 +46,16 @@ class WarrantySerial */ protected $source; + // other information + /** + * @ORM\Column(type="json") + */ + protected $meta_info; + public function __construct() { $this->date_create = new DateTime(); + $this->meta_info = []; } public function setID($id) @@ -99,4 +106,19 @@ class WarrantySerial { return $this->source; } + + public function addMetaInfo($id, $value) + { + $this->meta_info[$id] = $value; + return $this; + } + + public function getMetaInfo($id) + { + // return null if we don't have it + if (!isset($this->meta_info[$id])) + return null; + + return $this->meta_info[$id]; + } } diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index 39038556..285c4a41 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -10,7 +10,7 @@ $pass = $argv[4]; $db = new PDO($dsn, $user, $pass); // prepared statement -$sth = $db->prepare('insert into warranty_serial (id, sku, date_create, source) values (:serial, :sku, :date_create, :source)'); +$sth = $db->prepare('insert into warranty_serial (id, sku, date_create, source, meta_info) values (:serial, :sku, :date_create, :source, :meta_info)'); // go through rows @@ -32,16 +32,34 @@ while (($row = fgetcsv($csv)) !== false) $ref_id = $row[3]; */ // sample of line in output file: - // MG3101407704,N/A,Dispatch,In,2021-04-12T00:39:47.1870000+08:00 - $serial = trim(strtoupper($row[0]); + // serial number, sku, dispatch status, created date, inventory status, category id, category name + // CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF + $serial = trim(strtoupper($row[0])); $sku = trim($row[1]); - $date_create = $row[4]); + $dispatch_status = trim($row[2]); + $date_create = $row[3]; + $inventory_status = trim($row[4]); + $cat_id = trim($row[5]); + $cat_name = trim($row[6]); + + $meta_info = [ + 'dispatch_status' => $dispatch_status, + 'inventory_status' => $inventory_status, + 'category_id' => $cat_id, + 'category_name' => $cat_name, + ]; + + $info = json_encode($meta_info); + + if ($sku == 'N/A') + $sku = null; $res = $sth->execute([ ':serial' => $serial, ':sku' => $sku, ':date_create' => $date_create, - ':source' => $source + ':source' => $source, + ':meta_info' => $info, ]); if (!$res)