diff -u b/includes/commerce.controller.inc b/includes/commerce.controller.inc --- b/includes/commerce.controller.inc +++ b/includes/commerce.controller.inc @@ -39,6 +39,11 @@ */ public function skipLocking(); + /** + * releases locking on all entities, use with caution + */ + public function releaseLocking(); + } class DrupalCommerceEntityController extends DrupalDefaultEntityController implements DrupalCommerceEntityControllerInterface { @@ -113,6 +118,11 @@ } } + public function releaseLocking() { + unset($this->controllerTransaction); + $this->lockedEntities = array(); + } + /** * Overrides DrupalDefaultEntityController::load(). */ @@ -161,26 +171,6 @@ return $query; } - public function resetCache(array $ids = NULL) { - parent::resetCache($ids); - - // Maintain the list of locked entities, so that the releaseLock() method - // can know when it's time to commit the transaction. - if (!empty($this->lockedEntities)) { - if (isset($ids)) { - foreach ($ids as $id) { - unset($this->lockedEntities[$id]); - } - } - else { - $this->lockedEntities = array(); - } - } - - // Try to release the lock, if possible. - $this->releaseLock(); - } - /** * (Internal use) Invokes a hook on behalf of the entity. * diff -u b/modules/order/tests/commerce_order.test b/modules/order/tests/commerce_order.test --- b/modules/order/tests/commerce_order.test +++ b/modules/order/tests/commerce_order.test @@ -110,9 +110,11 @@ $locked_order = commerce_order_load($created_order->order_id); $this->assertTrue(commerce_order_is_locked($locked_order), 'commerce_order_load() returned a locked order.'); $this->assertTrue(commerce_order_is_cached($locked_order), 'commerce_order_load() cached the order.'); + entity_get_controller('commerce_order')->releaseLocking(); + $this->assertTrue(commerce_order_is_cached($locked_order), 'commerce_order_load() cached the order.'); // Ensure that skipLocking() works. - entity_get_controller('commerce_order')->resetCache(); + entity_get_controller('commerce_order')->releaseLocking(); entity_get_controller('commerce_order')->skipLocking(); $unlocked_order = commerce_order_load($created_order->order_id); $this->assertFalse(commerce_order_is_locked($unlocked_order), 'commerce_order_load() returned an unlocked order.'); only in patch2: unchanged: --- a/modules/order/includes/commerce_order.controller.inc +++ b/modules/order/includes/commerce_order.controller.inc @@ -54,8 +54,14 @@ class CommerceOrderEntityController extends DrupalCommerceEntityController { * SAVED_NEW or SAVED_UPDATED depending on the operation performed. */ public function save($order, DatabaseTransaction $transaction = NULL) { - if (!isset($transaction)) { - $transaction = db_transaction(); + //we don't really ever want to have 2 transactions, should we really even accept passed in transactions? or at least flush our internal one immediately? + if (isset($transaction)) { + $this->controllerTransaction = $transaction; + } + + //check if we already have a transaction, else create one + if(!isset($this->controllerTransaction)){ + $this->controllerTransaction = db_transaction(); $started_transaction = TRUE; }