diff --git a/includes/commerce.controller.inc b/includes/commerce.controller.inc index b52dfa8..ac8165b 100644 --- a/includes/commerce.controller.inc +++ b/includes/commerce.controller.inc @@ -32,12 +32,13 @@ interface DrupalCommerceEntityControllerInterface extends EntityAPIControllerInt public function isCached($entity); /** - * Indicate that pessimistic locking should be skipped in this request. + * Request that locking be skipped, + * actually skipping locking may or may not be possible. * * @param $skip_locking * The boolean indicating whether locking should be skipped. */ - public function skipLocking(); + public function requestSkipLocking($skip_locking); /** * releases locking on all entities, use with caution @@ -60,14 +61,17 @@ class DrupalCommerceEntityController extends DrupalDefaultEntityController imple protected $lockedEntities = array(); /** - * Stores the flag if a condition has been passed for locking + * Stores the flag for if a condition has been passed for requesting locking. + * By default, locking is always requested unless it is specifically set to false */ protected $requestLocking = TRUE; /** - * Stores whether pessimistic locking should be skipped in this request. + * Stores whether a request for skipping locking has been set. + * If locking has been requested as well it will take preference and the entity + * load will default to locking */ - protected $skipLocking = FALSE; + protected $requestSkipLocking = FALSE; /** * Implements DrupalCommerceEntityControllerInterface::isLocked(). @@ -84,23 +88,23 @@ class DrupalCommerceEntityController extends DrupalDefaultEntityController imple } /** - * Implements DrupalCommerceEntityControllerInterface::skipLocking(). + * Implements DrupalCommerceEntityControllerInterface::requestSkipLocking(). */ - public function skipLocking($skip_locking = TRUE) { - $this->skipLocking = $skip_locking; + public function requestSkipLocking($skip_locking = TRUE) { + $this->requestSkipLocking = $skip_locking; return $this; } /** - * Determines whether the current entity type requires pessimistic locking. + * Determines whether the current entity type requires or requested pessimistic locking. * * @return * True if locking is required, false otherwise. */ - protected function requiresLocking() { + protected function requireLocking() { $enabled = isset($this->entityInfo['locking mode']) && $this->entityInfo['locking mode'] == 'pessimistic'; - $not_skipped = empty($this->skipLocking); + $not_skipped = empty($this->requestSkipLocking); return $enabled && $not_skipped && $this->requestLocking; } @@ -130,6 +134,10 @@ class DrupalCommerceEntityController extends DrupalDefaultEntityController imple /** * Overrides DrupalDefaultEntityController::load(). + * + * Accepts a condition of locking request, may not necessarily take effect + * as other options can override locking. If anything conflicts, locking always + * take precedence over not locking. */ public function load($ids = array(), $conditions = array()) { // Lock by default if the caller didn't indicate a preference. @@ -139,7 +147,7 @@ class DrupalCommerceEntityController extends DrupalDefaultEntityController imple // If locking has been required, then bypass the internal cache for any // entities that are not already locked. - if ($this->requiresLocking()) { + if ($this->requireLocking()) { foreach (array_diff_key(array_flip($ids), $this->lockedEntities) as $id => $value) { unset($this->entityCache[$id]); } @@ -156,7 +164,7 @@ class DrupalCommerceEntityController extends DrupalDefaultEntityController imple protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) { $query = parent::buildQuery($ids, $conditions, $revision_id); - if ($this->requiresLocking()) { + if ($this->requireLocking()) { // In pessimistic locking mode, we issue the load query with a FOR UPDATE // clause. This will block all other load queries to the loaded objects // but requires us to start a transaction. diff --git a/modules/order/commerce_order.module b/modules/order/commerce_order.module index 66f5a28..f16f5dd 100644 --- a/modules/order/commerce_order.module +++ b/modules/order/commerce_order.module @@ -1531,7 +1531,7 @@ function commerce_order_views_pre_execute(&$view) { $has_vbo_field = isset($view->field['views_bulk_operations']); $submitted = isset($_POST['operation']); $skip_locking = (!$has_form_elements || ($has_vbo_field && !$submitted)); - entity_get_controller('commerce_order')->skipLocking($skip_locking); + entity_get_controller('commerce_order')->requestSkipLocking($skip_locking); $previous_result = $skip_locking; } diff --git a/modules/order/tests/commerce_order.test b/modules/order/tests/commerce_order.test index af30a7f..5d46587 100644 --- a/modules/order/tests/commerce_order.test +++ b/modules/order/tests/commerce_order.test @@ -116,7 +116,7 @@ class CommerceOrderCRUDTestCase extends CommerceBaseTestCase { // Ensure that skipLocking() works. entity_get_controller('commerce_order')->releaseLocking(); - entity_get_controller('commerce_order')->skipLocking(); + entity_get_controller('commerce_order')->requestSkipLocking(); $unlocked_order = commerce_order_load($created_order->order_id); $this->assertFalse(commerce_order_is_locked($unlocked_order), 'commerce_order_load() returned an unlocked order.');