rollback() public method

public rollback ( $all = false )
Ejemplo n.º 1
0
}
$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();
}