aboutsummaryrefslogtreecommitdiff
path: root/controller
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2014-10-14 07:54:56 +0200
committerChristian Weiske <cweiske@cweiske.de>2014-10-14 18:12:45 +0200
commit62340c61f3ab49aa405c549b43e2cd910ab4d834 (patch)
treec83c2267beca48c919c983278f5a9c709d033b8a /controller
parent0b208d3ef2a8501713169b74eb0b48e2e3bb10a6 (diff)
downloadgrauphel-62340c61f3ab49aa405c549b43e2cd910ab4d834.tar.gz
grauphel-62340c61f3ab49aa405c549b43e2cd910ab4d834.zip
Use SQL transactions during sync
Diffstat (limited to 'controller')
-rw-r--r--controller/apicontroller.php43
1 files changed, 25 insertions, 18 deletions
diff --git a/controller/apicontroller.php b/controller/apicontroller.php
index 688d0b0..39de60d 100644
--- a/controller/apicontroller.php
+++ b/controller/apicontroller.php
@@ -214,7 +214,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 +256,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 +285,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;
+ }
}
/**