Fix error checking. #576
This commit is contained in:
parent
ed14a3defd
commit
560db62a08
1 changed files with 9 additions and 11 deletions
|
|
@ -9,7 +9,7 @@ $output_file = $argv[5];
|
||||||
|
|
||||||
$output_fh = fopen($output_file, "w");
|
$output_fh = fopen($output_file, "w");
|
||||||
|
|
||||||
if (!file_exists($csv))
|
if (!file_exists($argv[1]))
|
||||||
{
|
{
|
||||||
$err_message = "No csv input file found." . "\n";
|
$err_message = "No csv input file found." . "\n";
|
||||||
fwrite($output_fh, $err_message);
|
fwrite($output_fh, $err_message);
|
||||||
|
|
@ -34,6 +34,7 @@ while (($row = fgetcsv($csv)) !== false)
|
||||||
// (2) No available data
|
// (2) No available data
|
||||||
// (3) CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF
|
// (3) CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF
|
||||||
// (4) Empty line
|
// (4) Empty line
|
||||||
|
// (5) empty sku
|
||||||
|
|
||||||
// check if No available data
|
// check if No available data
|
||||||
if ($row[0] == 'No available data')
|
if ($row[0] == 'No available data')
|
||||||
|
|
@ -43,25 +44,22 @@ while (($row = fgetcsv($csv)) !== false)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if new line
|
// check if empty line
|
||||||
if (empty($row[0]))
|
if ($row == array(null))
|
||||||
{
|
{
|
||||||
// skip
|
// skip
|
||||||
error_log('Skipping empty line...');
|
error_log('Skipping empty line...');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if csv file has a header by checking contents of line
|
// check if empty serial
|
||||||
if (($row[0] == 'SerialNumber') || ($row[1] == 'Sku') ||
|
if (empty($row[0]))
|
||||||
($row[2] == 'DispatchStatus') || ($row[3] == 'CreatedDate') ||
|
|
||||||
($row[4] == 'InventoryStatus') || ($row[5] == 'CategoryID') ||
|
|
||||||
($row[6] == 'CategoryName'))
|
|
||||||
{
|
{
|
||||||
// skip the header
|
$err_message = "Empty serial. " . "\n";
|
||||||
error_log('Skipping the headers... ');
|
fwrite($output_fh, $err_message);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sample of line in output file:
|
// sample of line in output file:
|
||||||
// serial number, sku, dispatch status, created date, inventory status, category id, category name
|
// 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
|
// CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue