Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- commerce.controller.inc 2011-12-08 15:59:41.000000000 +0000
- +++ commerce.controller.new.inc 2011-12-08 16:34:18.000000000 +0000
- @@ -13,6 +13,12 @@
- * Stores our transaction object, necessary for pessimistic locking to work.
- */
- protected $controllerTransaction = NULL;
- +
- + /**
- + * Stores ids of locked entities, necessary for knowing when to
- + * release the lock by committing the transaction.
- + */
- + protected $lockedEntities = array();
- /**
- * Override of DrupalDefaultEntityController::buildQuery().
- @@ -29,6 +35,7 @@
- $this->controllerTransaction = db_transaction();
- }
- + $this->lockedEntities += array_flip($ids);
- $query->forUpdate();
- }
- @@ -37,12 +44,29 @@
- public function resetCache(array $ids = NULL) {
- parent::resetCache($ids);
- - if (empty($this->entityCache) && !empty($this->controllerTransaction)) {
- - // If we don't have any entity in our local cache anymore, we commit the
- - // transaction so as to remove the locks we acquired.
- - // This will not commit the translation directly. Drupal will commit
- - // it as soon as possible given the state of the transaction stack.
- - unset($this->controllerTransaction);
- +
- + // Maintain the list of locked entities, so that the releaeLock() method
- + // can know when it's time to commit the transaction.
- + if (!empty($this->lockedEntities)) {
- + foreach ($ids as $id) {
- + unset($this->lockedEntities[$id]);
- + }
- + }
- + // Try to release the lock, if possible.
- + $this->releaseLock();
- + }
- +
- + /**
- + * Checks the list of tracked locked entities, and if it's empty, commits
- + * the transaction in order to remove the acquired locks.
- + * The transaction is not committed directly, Drupal commits it as soon
- + * as possible given the state of the transaction stack.
- + */
- + protected function releaseLock() {
- + if (isset($this->entityInfo['locking mode']) && $this->entityInfo['locking mode'] == 'pessimistic') {
- + if (empty($this->lockedEntities)) {
- + unset($this->controllerTransaction);
- + }
- }
- }
- @@ -194,8 +218,13 @@
- ->execute();
- }
- - $this->resetCache(array($entity->{$this->idKey}));
- $this->invoke($op, $entity);
- + // Update the static cache so that the next entity_load() is going
- + // to return this newly saved entity.
- + $this->entityCache[$entity->{$this->idKey}] = $entity;
- + // Maintain the list of locked entities and release the lock if possible.
- + unset($this->lockedEntities[$entity->{$this->idKey}]);
- + $this->releaseLock();
- // Ignore slave server temporarily.
- db_ignore_slave();
Add Comment
Please, Sign In to add comment