1
0
mirror of https://github.com/nextcloud/ocsms.git synced 2026-08-11 16:32:55 +00:00

Add replace function to purge all database before adding every record. Also add a delete before insert function when writing to DB, preventing SMS duplicates

This commit is contained in:
Loic Blot
2014-09-15 18:00:48 +02:00
parent 128167196a
commit ad1353c63c
3 changed files with 23 additions and 10 deletions
+10 -2
View File
@@ -35,10 +35,10 @@ class SmsMapper extends Mapper {
}
}
public function writeToDB ($userId, $smsList, $purgeBeforeInsert = false) {
public function writeToDB ($userId, $smsList, $purgeAllSmsBeforeInsert = false) {
\OCP\DB::beginTransaction();
if ($purgeBeforeInsert === true) {
if ($purgeAllSmsBeforeInsert === true) {
$query = \OC_DB::prepare('DELETE FROM *PREFIX*ocsms_smsdatas ' .
'WHERE user_id = ?');
$result = $query->execute(array($userId));
@@ -50,6 +50,14 @@ class SmsMapper extends Mapper {
$sms["seen"] === "true" ? "1" : "0"
);
// Remove previous record
// @ TODO: only update the required fields, getAllIds can be useful
$query = \OC_DB::prepare('DELETE FROM *PREFIX*ocsms_smsdatas ' .
'WHERE user_id = ? AND sms_id = ?');
$result = $query->execute(array(
$userId, (int) $sms["_id"]
));
$query = \OC_DB::prepare('INSERT INTO *PREFIX*ocsms_smsdatas ' .
'(user_id, added, lastmodified, sms_flags, sms_date, sms_id,' .
'sms_address, sms_msg, sms_mailbox, sms_type) VALUES ' .