deleteImageByTitle($database, $artistImageKey); } else { $imageData = getZipContentOfFile($zipArchiveLocation, $artistImageEntry['name']); $row["ArtistImageId"] = insertOrUpdateImageByTitle($database, $imageData, $artistImageKey); } // Art Preview Image $artPreviewImageEntry = from($zipContentsQueryable)->where(function ($v) use($row) { return strpos($v["name"], sprintf("art_%s.", $row['RegistrationNumber'])) !== false; })->singleOrDefault(); $artPreviewImageKey = sprintf("dealer:artPreviewImage[%s]", $row['RegistrationNumber']); if (!$artPreviewImageEntry) { $row["ArtPreviewImageId"] = null; deleteImageByTitle($database, $artPreviewImageKey); } else { $imageData = getZipContentOfFile($zipArchiveLocation, $artPreviewImageEntry['name']); $row["ArtPreviewImageId"] = insertOrUpdateImageByTitle($database, $imageData, $artPreviewImageKey); } $existingRow = from($existingRecordsQueryable)->where('$v["RegistrationNumber"] == ' . $row['RegistrationNumber'])->singleOrDefault(); if ($existingRow) { Log::info(sprintf("Updating %s", $row['RegistrationNumber'])); $database->update("dealer", $row, "Id=%s", $existingRow["Id"]); } else { $row["Id"] = $database->sqleval("uuid()"); Log::info(sprintf("Inserting %s", $row['RegistrationNumber'])); $database->insert("dealer", $row); } }); Log::info("Commiting changes to database"); $database->commit(); } catch (Exception $e) { var_dump($e->getMessage());
$images = []; // Images / Links if ($entryMatches[4][$entryId] != "") { preg_match_all($regexLinks, $entryMatches[4][$entryId], $linkMatches); foreach ($linkMatches[1] as $linkId => $linkTarget) { $linkText = $linkMatches[2][$linkId]; if (strtolower($linkText) == "image") { $imageTag = "info:import[" . strtolower($linkTarget) . "]"; $existingImageRow = $database->queryFirstRow("SELECT * FROM image WHERE Title=%s", $imageTag); if ($existingImageRow) { Log::info(sprintf(" Skipping import %s (exists)", $imageTag)); $images[] = $existingImageRow["Id"]; } else { Log::info(sprintf(" Fetching %s (new)", $imageTag)); $imageData = file_get_contents($linkTarget); $newImageId = insertOrUpdateImageByTitle($database, $imageData, $imageTag); $images[] = $newImageId; } } else { $links[] = array("Target" => $linkTarget, "Text" => $linkText); } } } $database->insert("Info", array("Id" => GUID(), "InfoGroupId" => $groupId, "LastChangeDateTimeUtc" => $database->sqleval("utc_timestamp()"), "IsDeleted" => "0", "Title" => trim($entry), "Text" => trim($entryMatches[2][$entryId]), "Position" => $epos, "ImageIds" => json_encode($images), "Urls" => json_encode($links))); $epos++; } } Log::info("Commiting changes to database"); $database->commit(); } catch (Exception $e) { var_dump($e->getMessage());