mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 16:06:15 +00:00
added argument to writeToDB to purge database entries before adding new records
This commit is contained in:
parent
3ea5fee350
commit
cd8c0e57f1
@ -43,7 +43,7 @@ class SmsController extends Controller {
|
|||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
public function push ($smsCount, $smsDatas) {
|
public function push ($smsCount, $smsDatas) {
|
||||||
if ($this->checkPushStructure($smsCount, $smsDatas) === false) {
|
if ($this->checkPushStructure($smsCount, $smsDatas, true) === false) {
|
||||||
return new JSONResponse(array("status" => false, "msg" => $this->errorMsg));
|
return new JSONResponse(array("status" => false, "msg" => $this->errorMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,15 +20,22 @@ class SmsMapper extends Mapper {
|
|||||||
parent::__construct($db, 'ocsms_smsdatas');
|
parent::__construct($db, 'ocsms_smsdatas');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function writeToDB($userId, $smsList) {
|
public function writeToDB($userId, $smsList, $purgeBeforeInsert = false) {
|
||||||
\OCP\DB::beginTransaction();
|
\OCP\DB::beginTransaction();
|
||||||
|
|
||||||
|
if ($purgeBeforeInsert === true) {
|
||||||
|
$query = \OCP\DB::prepare('DELETE FROM *PREFIX*ocsms_smsdatas ' .
|
||||||
|
'WHERE user_id = ?');
|
||||||
|
$result = $query->execute(array($userId));
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($smsList as $sms) {
|
foreach ($smsList as $sms) {
|
||||||
$smsFlags = sprintf("%s%s",
|
$smsFlags = sprintf("%s%s",
|
||||||
$sms["read"] === "true" ? "1" : "0",
|
$sms["read"] === "true" ? "1" : "0",
|
||||||
$sms["seen"] === "true" ? "1" : "0"
|
$sms["seen"] === "true" ? "1" : "0"
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = \OC_DB::prepare('INSERT INTO *PREFIX*ocsms_smsdatas ' .
|
$query = \OCP\DB::prepare('INSERT INTO *PREFIX*ocsms_smsdatas ' .
|
||||||
'(user_id, added, lastmodified, sms_flags, sms_date, sms_id,' .
|
'(user_id, added, lastmodified, sms_flags, sms_date, sms_id,' .
|
||||||
'sms_address, sms_msg, sms_mailbox, sms_type) VALUES ' .
|
'sms_address, sms_msg, sms_mailbox, sms_type) VALUES ' .
|
||||||
'(?,?,?,?,?,?,?,?,?,?)');
|
'(?,?,?,?,?,?,?,?,?,?)');
|
||||||
@ -41,6 +48,7 @@ class SmsMapper extends Mapper {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
\OCP\DB::commit();
|
\OCP\DB::commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user