1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-07-16 22:46:49 +00:00

Add query + routes to drop all user messages

This commit is contained in:
Loic Blot 2018-09-08 00:18:56 +02:00 committed by Loïc Blot
parent 615ba409e5
commit 267872b396
3 changed files with 22 additions and 2 deletions

View File

@ -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

View File

@ -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"));
}
}

View File

@ -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();