X-Git-Url: https://git.cweiske.de/grauphel.git/blobdiff_plain/eb5c81dea5a60bc65d3ec607daf5ad81fd709928..a921b71a121666b9973e1b2815f55dc416d96d28:/controller/apicontroller.php diff --git a/controller/apicontroller.php b/controller/apicontroller.php index 688d0b0..90c036f 100644 --- a/controller/apicontroller.php +++ b/controller/apicontroller.php @@ -119,7 +119,7 @@ class ApiController extends Controller 'grauphel.api.user', array('username' => $username) ) ), - 'href' => null,//FIXME + 'href' => null, ); } @@ -167,7 +167,9 @@ class ApiController extends Controller 'grauphel.api.notes', array('username' => $username) ) ), - 'href' => null, + 'href' => $this->deps->urlGen->getAbsoluteURL( + $this->deps->urlGen->linkToRoute('grauphel.gui.index') + ), ), 'latest-sync-revision' => $syncdata->latestSyncRevision, 'current-sync-guid' => $syncdata->currentSyncGuid, @@ -214,7 +216,7 @@ class ApiController extends Controller ) ); $syncdata = $this->notes->loadSyncData(); - + $res = $this->handleNoteSave($username, $syncdata); if ($res instanceof \OCP\AppFramework\Http\Response) { return $res; @@ -256,8 +258,8 @@ class ApiController extends Controller return; } - //note that we have more data in $arPut than just our JSON - // request object merges it with other data + //Note that we have more data in $arPut than just our JSON. + // The request object merges it with other data. $arPut = $this->request->put; //structural validation @@ -285,23 +287,30 @@ class ApiController extends Controller } //update - ++$syncdata->latestSyncRevision; - foreach ($arPut['note-changes'] as $noteUpdate) { - //owncloud converts object to array, so we reverse - $noteUpdate = (object) $noteUpdate; - - $note = $this->notes->load($noteUpdate->guid); - if (isset($noteUpdate->command) && $noteUpdate->command == 'delete') { - $this->notes->delete($noteUpdate->guid); - } else { - $this->notes->update( - $note, $noteUpdate, $syncdata->latestSyncRevision - ); - $this->notes->save($note); + \OC_DB::beginTransaction(); + try { + ++$syncdata->latestSyncRevision; + foreach ($arPut['note-changes'] as $noteUpdate) { + //owncloud converts object to array, so we reverse + $noteUpdate = (object) $noteUpdate; + + $note = $this->notes->load($noteUpdate->guid); + if (isset($noteUpdate->command) && $noteUpdate->command == 'delete') { + $this->notes->delete($noteUpdate->guid); + } else { + $this->notes->update( + $note, $noteUpdate, $syncdata->latestSyncRevision + ); + $this->notes->save($note); + } } - } - $this->notes->saveSyncData($syncdata); + $this->notes->saveSyncData($syncdata); + \OC_DB::commit(); + } catch (\DatabaseException $e) { + \OC_DB::getConnection()->rollBack(); + throw $e; + } } /**