Changeset:
c6dd493ed02c
https://sourceforge.net/p/mrbs/hg-code/ci/c6dd493ed02c3d86138d7c32c16db1587ea368aa
Author:
Campbell Morrison <[email protected]>
Date:
Thu Apr 06 17:59:13 2017 +0100
Log message:
Merge with default
diffstat:
web/edit_entry_handler.php | 10 ++++++++++
web/lib/MRBS/DB.php | 35 ++++++++++++++++++++++++++++-------
web/lib/MRBS/DB_mysql.php | 9 ---------
web/lib/MRBS/DB_pgsql.php | 20 +++++++++-----------
web/mrbs_sql.inc | 11 +----------
5 files changed, 48 insertions(+), 37 deletions(-)
diffs (205 lines):
diff -r 3c54790d1ca3 -r c6dd493ed02c web/edit_entry_handler.php
--- a/web/edit_entry_handler.php Mon Apr 03 18:47:38 2017 +0100
+++ b/web/edit_entry_handler.php Thu Apr 06 17:59:13 2017 +0100
@@ -714,7 +714,15 @@
// 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.
+
+// Acquire mutex to lock out others trying to book the same slot(s).
+if (!db()->mutex_lock($tbl_entry))
+{
+ fatal_error(get_vocab("failed_to_acquire"));
+}
+
db()->begin();
+
$transaction_ok = true;
$result = mrbsMakeBookings($bookings, $this_id, $just_check, $skip,
$original_room_id, $send_mail, $edit_type);
@@ -736,6 +744,8 @@
trigger_error('Edit failed.', E_USER_WARNING);
}
+db()->mutex_unlock($tbl_entry);
+
// If this is an Ajax request, output the result and finish
if ($ajax && function_exists('json_encode'))
diff -r 3c54790d1ca3 -r c6dd493ed02c web/lib/MRBS/DB.php
--- a/web/lib/MRBS/DB.php Mon Apr 03 18:47:38 2017 +0100
+++ b/web/lib/MRBS/DB.php Thu Apr 06 17:59:13 2017 +0100
@@ -37,7 +37,15 @@
// Establish a database connection.
try
{
- $this->dbh = new
PDO(static::DB_DBO_DRIVER.":host=$db_host;port=$db_port;dbname=$db_name",
+ if (!isset($db_host) || ($db_host == ""))
+ {
+ $hostpart = "";
+ }
+ else
+ {
+ $hostpart = "host=$db_host;";
+ }
+ $this->dbh = new
PDO(static::DB_DBO_DRIVER.":${hostpart}port=$db_port;dbname=$db_name",
$db_username,
$db_password,
array(PDO::ATTR_PERSISTENT => ($persist ? true :
false),
@@ -181,22 +189,25 @@
//
public function begin()
{
- // This method must be extended by the sub-classes, which must call the
parent as the
- // first thing they do. It only exists here in the parent class in order
that all the
- // calls to mrbs_ignore_user_abort() are grouped together.
-
// 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);
+ if (!$this->dbh->inTransaction())
+ {
+ $this->dbh->beginTransaction();
+ }
}
// Commit (end) a transaction. See begin().
public function commit()
{
- $result = $this->command("COMMIT");
+ if ($this->dbh->inTransaction())
+ {
+ $this->dbh->commit();
+ }
mrbs_ignore_user_abort(FALSE);
}
@@ -204,9 +215,19 @@
// Roll back a transaction, aborting it. See begin().
public function rollback()
{
- $result = $this->command("ROLLBACK", array());
+ if ($this->dbh->inTransaction())
+ {
+ $this->dbh->rollBack();
+ }
mrbs_ignore_user_abort(FALSE);
}
+
+
+ // Checks if inside a transaction
+ public function inTransaction()
+ {
+ return $this->dbh->inTransaction();
+ }
// Return a string identifying the database version
diff -r 3c54790d1ca3 -r c6dd493ed02c web/lib/MRBS/DB_mysql.php
--- a/web/lib/MRBS/DB_mysql.php Mon Apr 03 18:47:38 2017 +0100
+++ b/web/lib/MRBS/DB_mysql.php Thu Apr 06 17:59:13 2017 +0100
@@ -31,15 +31,6 @@
}
- // Begin a transaction, if the database supports it. This is used to
- // improve performance for multiple insert/delete/updates.
- public function begin()
- {
- parent::begin();
- $result = $this->command("START TRANSACTION");
- }
-
-
// Acquire a mutual-exclusion lock on the named table. For portability:
// This will not lock out SELECTs.
// It may lock out DELETE/UPDATE/INSERT or not, depending on the
implementation.
diff -r 3c54790d1ca3 -r c6dd493ed02c web/lib/MRBS/DB_pgsql.php
--- a/web/lib/MRBS/DB_pgsql.php Mon Apr 03 18:47:38 2017 +0100
+++ b/web/lib/MRBS/DB_pgsql.php Thu Apr 06 17:59:13 2017 +0100
@@ -62,15 +62,6 @@
return $this->dbh->lastInsertId($seq_name);
}
-
- // Begin a transaction, if the database supports it. This is used to
- // improve performance for multiple insert/delete/updates.
- public function begin()
- {
- parent::begin();
- $result = $this->command("BEGIN");
- }
-
// Acquire a mutual-exclusion lock on the named table. For portability:
// This will not lock out SELECTs.
@@ -88,7 +79,11 @@
{
try
{
- $this->command("BEGIN");
+ // LOCK TABLE can only be used in transaction blocks
+ if (!$this->dbh->inTransaction())
+ {
+ $this->begin();
+ }
$this->command("LOCK TABLE $name IN EXCLUSIVE MODE");
}
catch (DBException $e)
@@ -107,7 +102,10 @@
// is no other way.
public function mutex_unlock($name)
{
- $this->command("COMMIT");
+ if ($this->dbh->inTransaction())
+ {
+ $this->commit();
+ }
$this->mutex_lock_name = NULL;
}
diff -r 3c54790d1ca3 -r c6dd493ed02c web/mrbs_sql.inc
--- a/web/mrbs_sql.inc Mon Apr 03 18:47:38 2017 +0100
+++ b/web/mrbs_sql.inc Thu Apr 06 17:59:13 2017 +0100
@@ -1763,7 +1763,7 @@
function mrbsMakeBookings($bookings, $id=NULL, $just_check=FALSE, $skip=FALSE,
$original_room_id=NULL, $send_mail=FALSE, $edit_type='')
{
global $max_rep_entrys, $enable_periods, $resolution, $mail_settings;
- global $tbl_entry, $tbl_room, $tbl_area;
+ global $tbl_room, $tbl_area;
// All the data, except for the status and room id, will be common
// across the bookings
@@ -1820,12 +1820,6 @@
$repeat_id = NULL;
}
- // Acquire mutex to lock out others trying to book the same slot(s).
- if (!db()->mutex_lock($tbl_entry))
- {
- fatal_error(get_vocab("failed_to_acquire"));
- }
-
// Validate the booking for (a) conflicting bookings and (b) conformance to
policy rules
$valid_booking = TRUE;
$conflicts = array(); // Holds a list of all the
conflicts
@@ -1968,7 +1962,6 @@
// booking, then stop here and return the results
if ($just_check || !$valid_booking)
{
- db()->mutex_unlock($tbl_entry);
return $result;
}
@@ -2097,8 +2090,6 @@
}
}
} // end foreach $bookings
-
- db()->mutex_unlock($tbl_entry);
$result['new_details'] = $new_details;
$result['slots'] = intval(($common['end_time'] -
$common['start_time'])/$resolution);
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits