Add validation for invalid number of fields. #704
This commit is contained in:
parent
f40155e1f5
commit
9efe73e8b2
1 changed files with 23 additions and 9 deletions
|
|
@ -23,6 +23,8 @@ use DateTime;
|
|||
|
||||
class LoadWarrantySerialCommand extends Command
|
||||
{
|
||||
const FIELD_COUNT = 7;
|
||||
|
||||
protected $em;
|
||||
protected $upload_logger;
|
||||
protected $load_logger;
|
||||
|
|
@ -214,13 +216,11 @@ class LoadWarrantySerialCommand extends Command
|
|||
// (5) Empty line - ignore
|
||||
// (6) empty sku - log
|
||||
|
||||
// TODO: count the number of fields
|
||||
|
||||
// check if the line is a header
|
||||
if ($row[0] == 'SerialNumber')
|
||||
// check if empty line
|
||||
if ($row == array(null))
|
||||
{
|
||||
// no need to log, but send back error
|
||||
$error = 'Invalid information.';
|
||||
$error = 'Empty line';
|
||||
$data = [
|
||||
'serial' => '',
|
||||
'status' => 'error',
|
||||
|
|
@ -231,11 +231,25 @@ class LoadWarrantySerialCommand extends Command
|
|||
return $data;
|
||||
}
|
||||
|
||||
// check if empty line
|
||||
if ($row == array(null))
|
||||
// check the number of fields
|
||||
if (count($row) != self::FIELD_COUNT)
|
||||
{
|
||||
$error = 'Invalid number of fields.';
|
||||
$data = [
|
||||
'serial' => '',
|
||||
'status' => 'error',
|
||||
'has_error' => true,
|
||||
'error_message' => $error,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// check if the line is a header
|
||||
if ($row[0] == 'SerialNumber')
|
||||
{
|
||||
// no need to log, but send back error
|
||||
$error = 'Empty line';
|
||||
$error = 'Invalid information.';
|
||||
$data = [
|
||||
'serial' => '',
|
||||
'status' => 'error',
|
||||
|
|
@ -412,7 +426,7 @@ class LoadWarrantySerialCommand extends Command
|
|||
curl_close($curl);
|
||||
|
||||
// check result
|
||||
// error_log('Result ' . $res);
|
||||
error_log('Result ' . $res);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue