Add file id. #704

This commit is contained in:
Korina Cordero 2022-09-19 08:21:29 +00:00
parent 0ffbf10879
commit fc15b514bf
3 changed files with 52 additions and 10 deletions

View file

@ -377,8 +377,6 @@ class LoadWarrantySerialCommand extends Command
error_log(print_r($json_output, true)); error_log(print_r($json_output, true));
// TODO: sent json output somewhere
$curl = curl_init(); $curl = curl_init();
$options = [ $options = [
@ -388,8 +386,6 @@ class LoadWarrantySerialCommand extends Command
CURLOPT_POSTFIELDS => $body, CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => [ CURLOPT_HTTPHEADER => [
'Content-Type: application/json', 'Content-Type: application/json',
'Ocp-Apim-Subscription-Key: ' . $this->sub_key,
'Authorization: Bearer ' . $this->token,
], ],
]; ];

View file

@ -66,12 +66,17 @@ class WarrantySerialController extends APIController
protected function registerWarrantySerialFile($em, $file, $serial_filename, $user_id) 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(); $orig_filename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME) . '.' . $file->getClientOriginalExtension();
$ws_file = new WarrantySerialQueue(); $ws_file = new WarrantySerialQueue();
$ws_file->setFileSerial($serial_filename) $ws_file->setFileSerial($serial_filename)
->setStatus('pending'); ->setStatus('pending')
->setOrigFileSerial($orig_filename)
->setFileID($file_id);
$em->persist($ws_file); $em->persist($ws_file);
@ -85,7 +90,11 @@ class WarrantySerialController extends APIController
$this->upload_logger->logWarrantySerialUploadInfo($log_data); $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) protected function handleSerialFileUpload($file, $target_dir)
@ -109,13 +118,14 @@ class WarrantySerialController extends APIController
// get current date // get current date
$curr_date = new DateTime(); $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 // move file
$filename = 'warranty_serial' . '.' . $file->getClientOriginalExtension(); $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) protected function checkRequiredParamsForFiles(Request $req, $params, $user_id)

View file

@ -27,7 +27,13 @@ class WarrantySerialQueue
*/ */
protected $date_create; 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) * @ORM\Column(type="string", length=80, nullable=true)
*/ */
@ -45,12 +51,20 @@ class WarrantySerialQueue
*/ */
protected $api_user; protected $api_user;
// file identifier that we send back
/**
* @ORM\Column(type="string", length=21)
*/
protected $file_id;
public function __construct() public function __construct()
{ {
$this->date_create = new DateTime(); $this->date_create = new DateTime();
$this->file_serial = null; $this->file_serial = null;
$this->orig_file_serial = null;
$this->status = ''; $this->status = '';
$this->api_user = ''; $this->api_user = '';
$this->file_id = '';
} }
public function getID() public function getID()
@ -90,4 +104,26 @@ class WarrantySerialQueue
{ {
return $this->api_user; 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;
}
} }