/** * Save an event to the database. If an id is given, the existing event is * updated, if not a new one is created. The event will be stored in the * events table and all properties given as arrays are stored in the * accompanying junction table. * * @param $event - map of an event with the following keys * - title => the title of the event * - summary => the summary of the post mortem * - starttime => start time as unix timestamp * - endtime => end time as unix timestamp * - statustime => status time as unix timestamp * - detecttime => detect time as unix timestamp * @param $conn - PDO connection object, will be newly instantiated when * null (default: null) * * @returns the event map including an "id" field on success and a map of the * form ( "id" => null, "error" => "an error message" ) on failure */ static function save_event($event, $conn = null) { $conn = $conn ?: Persistence::get_database_object(); if (is_null($conn)) { return array("id" => null, "error" => "Couldn't get connection object."); } $action = isset($event["id"]) ? self::ACTION_EDIT : self::ACTION_ADD; if ($action == self::ACTION_ADD) { $now = new DateTime(null, new DateTimeZone('UTC')); $event["created"] = $now->getTimestamp(); } $event = Persistence::save_event($event, $conn); if (is_null($event["id"])) { return $event; } if ($action == self::ACTION_ADD) { $app = \Slim\Slim::getInstance(); $env = $app->environment; $admin = $env['admin']['username']; $result = Postmortem::add_history($event["id"], $admin, $action); } // close connection and return $conn = null; return $event; }