Error logging on save

This commit is contained in:
Victor Dubiniuk 2013-09-03 00:06:21 +03:00
parent 158db50966
commit cc1a5d5945

View File

@ -92,22 +92,42 @@ class SessionController extends Controller{
*/ */
public static function save(){ public static function save(){
$uid = self::preDispatch(); $uid = self::preDispatch();
try {
$sessionID = @$_SERVER['HTTP_WEBODF_SESSION_ID']; $sessionID = @$_SERVER['HTTP_WEBODF_SESSION_ID'];
if (!$sessionID){
throw new \Exception('Session id can not be empty');
}
$memberId = @$_SERVER['HTTP_WEBODF_MEMBER_ID']; $memberId = @$_SERVER['HTTP_WEBODF_MEMBER_ID'];
$sessionRevision = @$_SERVER['HTTP_WEBODF_SESSION_REVISION']; $sessionRevision = @$_SERVER['HTTP_WEBODF_SESSION_REVISION'];
$content = fopen('php://input','r'); $content = fopen('php://input','r');
if ($sessionID && $content){ if (!$content){
throw new \Exception('New conent missing');
}
$session = Session::getSession($sessionID); $session = Session::getSession($sessionID);
if (!$session){
throw new \Exception('Session does not exist');
}
$fileInfo = \OC\Files\Cache\Cache::getById($session['file_id']); $fileInfo = \OC\Files\Cache\Cache::getById($session['file_id']);
$path = $fileInfo[1]; $path = $fileInfo[1];
$view = new \OC\Files\View('/' . $session['owner']); $view = new \OC\Files\View('/' . $session['owner']);
$canWrite = ($view->file_exists($path) && $view->isUpdatable($path)) || $view->isCreatable($path); $isWritable = ($view->file_exists($path) && $view->isUpdatable($path)) || $view->isCreatable($path);
if ($canWrite){ if (!$isWritable){
$view->file_put_contents($path, $content); throw new \Exception('Document does not exist or is not writable for this user');
} else {
// TODO: report an error, break a plate, burn a house, conquer the galaxy
} }
$view->file_put_contents($path, $content);
\OCP\JSON::success();
exit();
} catch (\Exception $e){
Helper::warnLog('Saving failed. Reason:' . $e->getMessage());
\OCP\JSON::error(array('message'=>$e->getMessage()));
exit();
} }
} }