Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
    $event = Postmortem::save_event($event);
    if (is_null($event["id"])) {
        var_dump($event);
        $app->response->status(500);
        return;
    }
    $app->redirect('/events/' . $event["id"], 201);
});
$app->post('/events/:id/history', function ($id) use($app) {
    header("Content-Type: application/json");
    $action = $app->request->post('action');
    $event = array("id" => $id, "summary" => $app->request->post('summary'), "why_surprised" => $app->request->post('why_surprised'));
    // store history
    $env = $app->environment;
    $admin = $env['admin']['username'];
    $result = Postmortem::add_history($event, $admin, $action);
    echo json_encode($result);
});
$app->post('/events/:id/tags', function ($id) use($app) {
    header("Content-Type: application/json");
    $tags = $app->request->post('tags');
    $tags = explode(",", $tags);
    $tags = array_map('trim', $tags);
    $tags = array_map('strtolower', $tags);
    $res = Postmortem::save_tags_for_event($id, $tags);
    if ($res["status"] == Postmortem::ERROR) {
        $app->response->status(400);
    } else {
        $app->response->status(201);
        $tags = Postmortem::get_tags_for_event($id);
        if ($tags["status"] == Postmortem::ERROR) {