From d85edc25ebbd9734bea3dcc75d33636b3d39b595 Mon Sep 17 00:00:00 2001 From: Vinzenz Date: Wed, 4 May 2016 12:41:43 +0200 Subject: [PATCH] update mapzen key if it already exists --- controller/apikeycontroller.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/controller/apikeycontroller.php b/controller/apikeycontroller.php index df5e3f6..f051f1c 100644 --- a/controller/apikeycontroller.php +++ b/controller/apikeycontroller.php @@ -64,8 +64,14 @@ public function addKey($key){ $apikey->setApiKey($key); $apikey->setUserId($this->userId); - /* @var $apikey ApiKey */ - $apikey = $this->apiKeyMapper->insert($apikey); + //if there is an existing key, update, insert otherwise + try { + $oldKey = $this->apiKeyMapper->findByUser($this->userId); + $this->updateKey($key, $oldKey->getId()); + } catch(\OCP\AppFramework\Db\DoesNotExistException $e) { + /* @var $apikey ApiKey */ + $apikey = $this->apiKeyMapper->insert($apikey); + } $response = array('id'=> $apikey->getId()); return new JSONResponse($response);