private function executeCSV($entityType, $map, $hasHeaders)
{
$results = [RESULT_SUCCESS => [], RESULT_FAILURE => []];
$source = IMPORT_CSV;
$data = Session::get("{$entityType}-data");
$this->checkData($entityType, count($data));
$this->initMaps();
// Convert the data
$row_list = [];
foreach ($data as $row) {
if ($hasHeaders) {
$hasHeaders = false;
continue;
}
$row = $this->convertToObject($entityType, $row, $map);
$data_index = $this->transformRow($source, $entityType, $row);
if ($data_index !== false) {
if ($data_index !== true) {
// Wasn't merged with another row
$row_list[] = ['row' => $row, 'data_index' => $data_index];
}
} else {
$results[RESULT_FAILURE][] = $row;
}
}
// Save the data
foreach ($row_list as $row_data) {
$result = $this->saveData($source, $entityType, $row_data['row'], $row_data['data_index']);
if ($result) {
$results[RESULT_SUCCESS][] = $result;
} else {
$results[RESULT_FAILURE][] = $row;
}
}
Session::forget("{$entityType}-data");
return $results;
}