update() public method

public update ( )
}
$news = json_decode(file_get_contents('http://6al.de/efsched/getconnews'));
Log::info("Importing ConNews");
try {
    $database->startTransaction();
    foreach ($news as $entry) {
        Log::info(sprintf("Id: %s, Type: %s -> %s", $entry->id, $entry->news->type, $entry->news->title));
        $dbItem = @$database->query("SELECT * FROM Announcement WHERE ExternalId=%s", "connews:" . $entry->id)[0];
        if ($dbItem) {
            $dbItem["ValidFromDateTimeUtc"] = new DateTime($dbItem["ValidFromDateTimeUtc"]);
            $dbItem["ValidUntilDateTimeUtc"] = new DateTime($dbItem["ValidUntilDateTimeUtc"]);
        }
        if ($entry->news->type == "new" || $entry->news->type == "reschedule") {
            $entry->news->valid_until = $entry->date + 60 * 60 * 48;
        }
        $sourceItem = array("ExternalId" => "connews:" . $entry->id, "ValidFrom" => DateTime::createFromFormat('U', $entry->date), "ValidUntil" => DateTime::createFromFormat('U', $entry->news->valid_until), "Area" => ucwords($entry->news->type), "Author" => isset($entry->news->department) ? ucwords($entry->news->department) : "Eurofurence", "Title" => $entry->news->title, "Content" => strip_tags($parsedown->text($entry->news->message)));
        $patchedItem = patch($sourceItem, $dbItem, array("ExternalId" => "ExternalId", "ValidFrom" => "ValidFromDateTimeUtc", "ValidUntil" => "ValidUntilDateTimeUtc", "Area" => "Area", "Author" => "Author", "Title" => "Title", "Content" => "Content"));
        if ($patchedItem) {
            if (!$dbItem) {
                $database->insert("Announcement", $patchedItem);
            } else {
                $database->update("Announcement", $patchedItem, "Id=%s", $dbItem["Id"]);
            }
        }
    }
    $database->commit();
} catch (Exception $e) {
    var_dump($e->getMessage());
    Log::error("Rolling back changes to database");
    $database->rollback();
}
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) {
            return strpos($v["name"], sprintf("thumbnail_%s.", $row['RegistrationNumber'])) !== false;
        })->singleOrDefault();
        $artistThumbnailImageKey = sprintf("dealer:artistThumbnailImage[%s]", $row['RegistrationNumber']);
        if (!$artistThumbnailImageEntry) {
            $row["ArtistThumbnailImageId"] = null;
            deleteImageByTitle($database, $artistThumbnailImageKey);
        } else {
            $imageData = getZipContentOfFile($zipArchiveLocation, $artistThumbnailImageEntry['name']);
 $database->startTransaction();
 /* Import Conference Tracks */
 Log::info("Importing Conference Tracks");
 $importConferenceTracks = Enumerable::from($eventQuery->select('$v["conference_track"]')->distinct()->toList());
 $importConferenceRooms = Enumerable::from($eventQuery->select('$v["conference_room"]')->distinct()->toList());
 $dbConferenceTracks = Enumerable::from($database->query("SELECT * FROM EventConferenceTrack"));
 $importConferenceTracks->each(function ($iItem) use($dbConferenceTracks, $database) {
     $dbItem = $dbConferenceTracks->where(function ($a) use($iItem) {
         return $a["Name"] == $iItem;
     })->singleOrDefault();
     $patchedItem = patch(array("Name" => $iItem), $dbItem, array("Name" => "Name"));
     if ($patchedItem) {
         if (!$dbItem) {
             $database->insert("EventConferenceTrack", $patchedItem);
         } else {
             $database->update("EventConferenceTrack", $patchedItem, "Id=%s", $dbItem["Id"]);
         }
     }
 });
 $dbConferenceTracks->where(function ($a) use($importConferenceTracks) {
     return $a["IsDeleted"] == 0 && $importConferenceTracks->where(function ($b) use($a) {
         return $b == $a["Name"];
     })->count() == 0;
 })->each(function ($a) use($database) {
     $database->update("EventConferenceTrack", array("LastChangeDateTimeUtc" => $database->sqleval("utc_timestamp()"), "IsDeleted" => 1), "Id=%s", $a["Id"]);
 });
 $dbConferenceTracks = Enumerable::from($database->query("SELECT * FROM EventConferenceTrack WHERE IsDeleted = 0"));
 Log::info("Importing Conference Rooms");
 $dbConferenceRooms = Enumerable::from($database->query("SELECT * FROM EventConferenceRoom"));
 $importConferenceRooms->each(function ($iItem) use($dbConferenceRooms, $database) {
     $dbItem = $dbConferenceRooms->where(function ($a) use($iItem) {