From fc15b514bf6ad7257b131a0b16237ae40cc7e49b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 19 Sep 2022 08:21:29 +0000 Subject: [PATCH] Add file id. #704 --- src/Command/LoadWarrantySerialCommand.php | 4 -- .../CAPI/WarrantySerialController.php | 20 +++++++--- src/Entity/WarrantySerialQueue.php | 38 ++++++++++++++++++- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/Command/LoadWarrantySerialCommand.php b/src/Command/LoadWarrantySerialCommand.php index 41fcb15d..fc861a20 100644 --- a/src/Command/LoadWarrantySerialCommand.php +++ b/src/Command/LoadWarrantySerialCommand.php @@ -377,8 +377,6 @@ class LoadWarrantySerialCommand extends Command error_log(print_r($json_output, true)); - // TODO: sent json output somewhere - $curl = curl_init(); $options = [ @@ -388,8 +386,6 @@ class LoadWarrantySerialCommand extends Command CURLOPT_POSTFIELDS => $body, CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', - 'Ocp-Apim-Subscription-Key: ' . $this->sub_key, - 'Authorization: Bearer ' . $this->token, ], ]; diff --git a/src/Controller/CAPI/WarrantySerialController.php b/src/Controller/CAPI/WarrantySerialController.php index db447dd5..7595d3ff 100644 --- a/src/Controller/CAPI/WarrantySerialController.php +++ b/src/Controller/CAPI/WarrantySerialController.php @@ -66,12 +66,17 @@ class WarrantySerialController extends APIController protected function registerWarrantySerialFile($em, $file, $serial_filename, $user_id) { + // parse the serial filename to get the file id + $parts = explode('/', $serial_filename); + $file_id = $parts[0]; $orig_filename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME) . '.' . $file->getClientOriginalExtension(); $ws_file = new WarrantySerialQueue(); $ws_file->setFileSerial($serial_filename) - ->setStatus('pending'); + ->setStatus('pending') + ->setOrigFileSerial($orig_filename) + ->setFileID($file_id); $em->persist($ws_file); @@ -85,7 +90,11 @@ class WarrantySerialController extends APIController $this->upload_logger->logWarrantySerialUploadInfo($log_data); - return new APIResponse(true, 'Warranty serial file uploaded.'); + $data = [ + 'id' => $file_id, + ]; + + return new APIResponse(true, 'Warranty serial file uploaded.', $data); } protected function handleSerialFileUpload($file, $target_dir) @@ -109,13 +118,14 @@ class WarrantySerialController extends APIController // get current date $curr_date = new DateTime(); - $str_curr_date = $curr_date->format('YmdHis'); + $str_curr_date = $curr_date->format('Ymd'); + $file_id = $str_curr_date . uniqid(); // move file $filename = 'warranty_serial' . '.' . $file->getClientOriginalExtension(); - $file->move($target_dir . '/' . $str_curr_date, $filename); + $file->move($target_dir . '/' . $file_id, $filename); - return $str_curr_date . '/' . $filename; + return $file_id . '/' . $filename; } protected function checkRequiredParamsForFiles(Request $req, $params, $user_id) diff --git a/src/Entity/WarrantySerialQueue.php b/src/Entity/WarrantySerialQueue.php index 585be163..d139a173 100644 --- a/src/Entity/WarrantySerialQueue.php +++ b/src/Entity/WarrantySerialQueue.php @@ -27,7 +27,13 @@ class WarrantySerialQueue */ protected $date_create; - // warranty serial file + // original filename of warranty serial + /** + * @ORM\Column(type="string", length=80, nullable=true) + */ + protected $orig_file_serial; + + // warranty serial file that we created /** * @ORM\Column(type="string", length=80, nullable=true) */ @@ -45,12 +51,20 @@ class WarrantySerialQueue */ protected $api_user; + // file identifier that we send back + /** + * @ORM\Column(type="string", length=21) + */ + protected $file_id; + public function __construct() { $this->date_create = new DateTime(); $this->file_serial = null; + $this->orig_file_serial = null; $this->status = ''; $this->api_user = ''; + $this->file_id = ''; } public function getID() @@ -90,4 +104,26 @@ class WarrantySerialQueue { return $this->api_user; } + + public function setFileID($file_id) + { + $this->file_id = $file_id; + return $this; + } + + public function getFileID() + { + return $this->file_id; + } + + public function setOrigFileSerial($file = null) + { + $this->orig_file_serial = $file; + return $this; + } + + public function getOrigFileSerial() + { + return $this->orig_file_serial; + } }