Fix CSV import 0.1 #175

This commit is contained in:
Jokob-sk
2023-02-10 20:51:56 +11:00
parent 4b9117dcb4
commit 33f0356ca7

View File

@@ -488,23 +488,29 @@ function ImportCSV() {
$columns = getDevicesColumns(); $columns = getDevicesColumns();
$rowArray = array();
// Parse data from CSV file line by line (max 10000 lines) // Parse data from CSV file line by line (max 10000 lines)
foreach($data as $row) foreach($data as $row)
{ {
// Check if not empty and skipping first line // Check if not empty and skipping first line
if(count(explode(',',$row)) == count($columns) && explode(',',$row)[0] != "\"dev_MAC\"") $rowArray = explode(',',$row);
if(count($rowArray) > 20)
{ {
$sql = "INSERT INTO Devices (".implode(',', $columns).") VALUES (" . $row.")"; $cleanMac = str_replace("\"","",$rowArray[0]);
$result = $db->query($sql);
// check result if(filter_var($cleanMac , FILTER_VALIDATE_MAC) == True || $cleanMac == "Internet")
if ($result != TRUE) { {
$error = $db->lastErrorMsg(); $sql = "INSERT INTO Devices (".implode(',', $columns).") VALUES (" . $row.")";
// break the while loop on error $result = $db->query($sql);
break;
} // check result
if ($result != TRUE) {
$error = $db->lastErrorMsg();
// break the while loop on error
break;
}
}
} }
} }