use \OCP\AppFramework\Controller;
use \OCP\AppFramework\Http\JSONResponse;
+use \OCA\Grauphel\Lib\Client;
use \OCA\Grauphel\Lib\NoteStorage;
use \OCA\Grauphel\Lib\OAuth;
use \OCA\Grauphel\Lib\OAuthException;
'api-version' => '1.0',
);
+ $cl = new Client();
+ $client = $cl->getClient();
+ if ($client !== false) {
+ $data['oauth_authorize_url'] .= '?client=' . urlencode($client);
+ }
+
if ($authenticated) {
$data['user-ref'] = array(
'api-ref' => $urlGen->getAbsoluteURL(
)
);
$syncdata = $this->notes->loadSyncData();
-
+
$res = $this->handleNoteSave($username, $syncdata);
if ($res instanceof \OCP\AppFramework\Http\Response) {
return $res;
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
}
//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;
+ }
}
/**