From 3ea5fee3502bee6e10a7761e92260fb1ba8d993b Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Mon, 15 Sep 2014 13:31:32 +0200 Subject: [PATCH] Use transaction before writing to database --- db/smsmapper.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/db/smsmapper.php b/db/smsmapper.php index 0144ed9..fcd0f1d 100644 --- a/db/smsmapper.php +++ b/db/smsmapper.php @@ -20,14 +20,14 @@ class SmsMapper extends Mapper { parent::__construct($db, 'ocsms_smsdatas'); } - // @TODO public function writeToDB($userId, $smsList) { + \OCP\DB::beginTransaction(); foreach ($smsList as $sms) { $smsFlags = sprintf("%s%s", $sms["read"] === "true" ? "1" : "0", $sms["seen"] === "true" ? "1" : "0" ); - + $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 ' . @@ -38,7 +38,10 @@ class SmsMapper extends Mapper { $sms["address"], $sms["body"], (int) $sms["mbox"], (int) $sms["type"] )); + + } + \OCP\DB::commit(); } public function find($id) {