$database->throw_exception_on_error = true; $database->error_handler = false; $zipArchiveLocation = $fileName; $zipContentsQueryable = getZipContentsAsQueryable($zipArchiveLocation); $csvEntry = $zipContentsQueryable->where(function ($v) { return endsWith($v["name"], "csv"); })->single(); $csvData = getZipContentOfFile($zipArchiveLocation, $csvEntry['name']); while (ord($csvData[0]) > 127) { $csvData = substr($csvData, 1); } $csvParser = new parseCSV(); $csvParser->delimiter = ";"; $csvContentsQueryable = from($csvParser->parse_string(utf8_decode($csvData))); try { $database->startTransaction(); $existingRecordsQueryable = from($database->query("SELECT * FROM dealer")); $oldRecords = $existingRecordsQueryable->where('$v["IsDeleted"] == 0')->where(function ($row) use($csvContentsQueryable) { return $csvContentsQueryable->all('$v["Reg No."] != ' . $row['RegistrationNumber']); })->toArray(); Log::info(sprintf("Soft deleting old records on '%s'", 'dealer')); from($oldRecords)->each(function ($row) use($database) { Log::info(sprintf("Deleting %s", $row['RegistrationNumber'])); $database->update("dealer", array("LastChangeDateTimeUtc" => $database->sqleval("utc_timestamp()"), "IsDeleted" => 1), "Id=%s", $row["Id"]); }); Log::info(sprintf("Inserting / updating records on '%s'", 'dealer')); from($csvContentsQueryable)->each(function ($record) use($database, $existingRecordsQueryable, $zipArchiveLocation) { $row = array("LastChangeDateTimeUtc" => $database->sqleval("utc_timestamp()"), "IsDeleted" => "0", "RegistrationNumber" => $record["Reg No."], "AttendeeNickname" => $record["Nick"], "DisplayName" => $record["Display Name"], "ShortDescription" => $record["Short Description"], "AboutTheArtistText" => $record["About the Artist"], "AboutTheArtText" => $record["About the Art"], "WebsiteUri" => $record["Website Reg"], "ArtPreviewCaption" => $record["Art Preview Caption"]); $zipContentsQueryable = getZipContentsAsQueryable($zipArchiveLocation); // Artist Thumbnail $artistThumbnailImageEntry = from($zipContentsQueryable)->where(function ($v) use($row) {