From 267872b396857f15da09f9c4a9e0323606db4de8 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 8 Sep 2018 00:18:56 +0200 Subject: [PATCH] Add query + routes to drop all user messages --- appinfo/routes.php | 1 + controller/smscontroller.php | 14 ++++++++++++-- db/smsmapper.php | 9 +++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 7a7da61..cc6aa65 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -27,6 +27,7 @@ $application->registerRoutes($this, array('routes' => array( array('name' => 'sms#retrieve_all_peers', 'url' => '/front-api/v1/peerlist', 'verb' => 'GET'), array('name' => 'sms#get_conversation', 'url' => '/front-api/v1/conversation', 'verb' => 'GET'), array('name' => 'sms#check_new_messages', 'url' => '/front-api/v1/new_messages', 'verb' => 'GET'), + array('name' => 'sms#wipe_all_user_messages', 'url' => '/front-api/v1/delete/all', 'verb' => 'POST'), array('name' => 'settings#get_settings', 'url'=> '/front-api/v1/settings', 'verb' => 'GET'), // Android API v1 doesn't have a version in the URL, be careful diff --git a/controller/smscontroller.php b/controller/smscontroller.php index db429c2..23d6139 100644 --- a/controller/smscontroller.php +++ b/controller/smscontroller.php @@ -211,7 +211,7 @@ class SmsController extends Controller { $this->smsMapper->removeMessagesForPhoneNumber($this->userId, $phnumber); } } - return new JSONResponse(array()); + return new JSONResponse(array("status" => "ok")); } /** @@ -263,6 +263,16 @@ class SmsController extends Controller { return new JSONResponse(array(), Http::STATUS_BAD_REQUEST); } $this->smsMapper->removeMessage($this->userId, $phoneNumber, $messageId); - return new JSONResponse(array()); + return new JSONResponse(array("status" => "ok")); + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + * @return JSONResponse + */ + public function wipeAllUserMessages () { + $this->smsMapper->removeAllMessagesForUser($this->userId); + return new JSONResponse(array("status" => "ok")); } } diff --git a/db/smsmapper.php b/db/smsmapper.php index 19ab5e2..e15cc93 100644 --- a/db/smsmapper.php +++ b/db/smsmapper.php @@ -227,6 +227,15 @@ class SmsMapper extends Mapper { return $cnt; } + public function removeAllMessagesForUser ($userId) { + $this->db->beginTransaction(); + $qb = $this->db->getQueryBuilder(); + $qb->delete('ocsms_smsdatas') + ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId))); + $qb->execute(); + $this->db->commit(); + } + public function removeMessagesForPhoneNumber ($userId, $phoneNumber) { $this->db->beginTransaction(); $qb = $this->db->getQueryBuilder();