foreach ($state_fields as $k => $discard) {
if ($k === 'body') {
$modified_state[$k] = $post->rawBody();
} else {
$v = $post->{$k};
if ($v instanceof GBDateTime) {
$v = strval($v);
}
$modified_state[$k] = $v;
}
}
}
# commit?
if ($input['commit']) {
git::add($post->name);
git::commit(($created ? 'Created' : 'Updated') . ' post ' . r($post->title), gb::$authorized, $post->name);
}
# build response entity
$rsp = array('name' => $post->name, 'version' => $post->id, 'exists' => $post->exists(), 'isTracked' => $post->isTracked(), 'isDirty' => $post->isDirty(), 'state' => $modified_state);
# status
$status = '200 OK';
if ($created) {
$status = '201 Created';
}
# send JSON response
gb_admin::json_rsp($rsp, $status);
gb::log('saved post %s', $post->name);
} catch (Exception $e) {
gb::log('failed to save post: %s', GBException::format($e, true, false, null, 0));
gb_admin::json_rsp($e->getMessage(), '400 Bad Request');
}