Fix error checking. #576

This commit is contained in:
Korina Cordero 2021-06-08 09:32:15 +00:00
parent ed14a3defd
commit 560db62a08

View file

@ -9,7 +9,7 @@ $output_file = $argv[5];
$output_fh = fopen($output_file, "w");
if (!file_exists($csv))
if (!file_exists($argv[1]))
{
$err_message = "No csv input file found." . "\n";
fwrite($output_fh, $err_message);
@ -34,6 +34,7 @@ while (($row = fgetcsv($csv)) !== false)
// (2) No available data
// (3) CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF
// (4) Empty line
// (5) empty sku
// check if No available data
if ($row[0] == 'No available data')
@ -43,22 +44,19 @@ while (($row = fgetcsv($csv)) !== false)
continue;
}
// check if new line
if (empty($row[0]))
// check if empty line
if ($row == array(null))
{
// skip
error_log('Skipping empty line...');
continue;
}
// check if csv file has a header by checking contents of line
if (($row[0] == 'SerialNumber') || ($row[1] == 'Sku') ||
($row[2] == 'DispatchStatus') || ($row[3] == 'CreatedDate') ||
($row[4] == 'InventoryStatus') || ($row[5] == 'CategoryID') ||
($row[6] == 'CategoryName'))
// check if empty serial
if (empty($row[0]))
{
// skip the header
error_log('Skipping the headers... ');
$err_message = "Empty serial. " . "\n";
fwrite($output_fh, $err_message);
continue;
}