Changeset:
804e65cfa16b
https://sourceforge.net/p/mrbs/hg-code/ci/804e65cfa16bcfc6cc4fc36fa0464e1adf5f389e
Author:
Campbell Morrison <[email protected]>
Date:
Mon Sep 26 16:33:55 2016 +0100
Log message:
Wrapped the edit procedure in a transaction. See SF Support Requests #1064
diffstat:
web/dbsys.inc | 28 ++++++++++++++++++++++++++--
web/edit_entry_handler.php | 20 +++++++++++++++++++-
web/mrbs_sql.inc | 2 +-
web/mysqli.inc | 5 +++++
4 files changed, 51 insertions(+), 4 deletions(-)
diffs (110 lines):
diff -r 35e9b7736f57 -r 804e65cfa16b web/dbsys.inc
--- a/web/dbsys.inc Sat Sep 17 09:11:18 2016 +0100
+++ b/web/dbsys.inc Mon Sep 26 16:33:55 2016 +0100
@@ -347,8 +347,8 @@
// Start a transaction
function sql_begin()
{
- // Turn off ignore_user_abort until the transaction has been committed. See
- // the warning at
http://php.net/manual/en/features.persistent-connections.php
+ // Turn off ignore_user_abort until the transaction has been committed or
rolled back.
+ // See the warning at
http://php.net/manual/en/features.persistent-connections.php
// (Only applies to persistent connections, but we'll do it for all cases to
keep
// things simple)
mrbs_ignore_user_abort(TRUE);
@@ -396,6 +396,30 @@
}
+// Finish a transaction
+function sql_rollback()
+{
+ if (func_num_args() > 0)
+ {
+ $handle = func_get_arg(0);
+ $db_sys = $handle['system'];
+ $db_conn = $handle['connection'];
+ }
+ else
+ {
+ global $dbsys;
+
+ $db_sys = $dbsys;
+ $db_conn = null;
+ }
+
+ $f = __NAMESPACE__ . "\\sql_${db_sys}_rollback";
+ $f($db_conn);
+
+ mrbs_ignore_user_abort(FALSE);
+}
+
+
// Get a mutex lock
function sql_mutex_lock($name)
{
diff -r 35e9b7736f57 -r 804e65cfa16b web/edit_entry_handler.php
--- a/web/edit_entry_handler.php Sat Sep 17 09:11:18 2016 +0100
+++ b/web/edit_entry_handler.php Mon Sep 26 16:33:55 2016 +0100
@@ -699,15 +699,33 @@
$just_check = $ajax && function_exists('json_encode') && !$commit;
$this_id = (isset($id)) ? $id : NULL;
$send_mail = ($no_mail) ? FALSE : $need_to_send_mail;
+
+// Wrap the editing process in a transaction, because if deleting the old
booking should fail for
+// some reason then we'll potentially be left with two overlapping bookings.
A deletion could fail
+// if, for example, the database user hasn't been granted DELETE rights.
+sql_begin();
+$transaction_ok = true;
+
$result = mrbsMakeBookings($bookings, $this_id, $just_check, $skip,
$original_room_id, $send_mail, $edit_type);
// If we weren't just checking and this was a succesful booking and
// we were editing an existing booking, then delete the old booking
if (!$just_check && $result['valid_booking'] && isset($id))
{
- mrbsDelEntry($user, $id, ($edit_type == "series"), 1);
+ $transaction_ok = mrbsDelEntry($user, $id, ($edit_type == "series"), 1);
}
+if ($transaction_ok)
+{
+ sql_commit();
+}
+else
+{
+ sql_rollback();
+ trigger_error('Edit failed.', E_USER_WARNING);
+}
+
+
// If this is an Ajax request, output the result and finish
if ($ajax && function_exists('json_encode'))
{
diff -r 35e9b7736f57 -r 804e65cfa16b web/mrbs_sql.inc
--- a/web/mrbs_sql.inc Sat Sep 17 09:11:18 2016 +0100
+++ b/web/mrbs_sql.inc Mon Sep 26 16:33:55 2016 +0100
@@ -574,7 +574,7 @@
{
continue;
}
-
+
if (sql_command("DELETE FROM $tbl_entry WHERE id=" . $row['id']) > 0)
{
$start_times[] = $row['start_time'];
diff -r 35e9b7736f57 -r 804e65cfa16b web/mysqli.inc
--- a/web/mysqli.inc Sat Sep 17 09:11:18 2016 +0100
+++ b/web/mysqli.inc Mon Sep 26 16:33:55 2016 +0100
@@ -75,6 +75,11 @@
{
$ret = $db_conn->affected_rows;
}
+ else
+ {
+ trigger_error($db_conn->error, E_USER_WARNING);
+ }
+
return $ret;
}
------------------------------------------------------------------------------
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits