Guest User

Untitled

a guest
Apr 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.71 KB | None | 0 0
  1. --- commerce.controller.inc 2011-12-08 15:59:41.000000000 +0000
  2. +++ commerce.controller.new.inc 2011-12-08 16:34:18.000000000 +0000
  3. @@ -13,6 +13,12 @@
  4.     * Stores our transaction object, necessary for pessimistic locking to work.
  5.     */
  6.    protected $controllerTransaction = NULL;
  7. +  
  8. +  /**
  9. +   * Stores ids of locked entities, necessary for knowing when to
  10. +   * release the lock by committing the transaction.
  11. +   */
  12. +  protected $lockedEntities = array();
  13.  
  14.    /**
  15.     * Override of DrupalDefaultEntityController::buildQuery().
  16. @@ -29,6 +35,7 @@
  17.          $this->controllerTransaction = db_transaction();
  18.        }
  19.  
  20. +      $this->lockedEntities += array_flip($ids);
  21.        $query->forUpdate();
  22.      }
  23.  
  24. @@ -37,12 +44,29 @@
  25.  
  26.    public function resetCache(array $ids = NULL) {
  27.      parent::resetCache($ids);
  28. -    if (empty($this->entityCache) && !empty($this->controllerTransaction)) {
  29. -      // If we don't have any entity in our local cache anymore, we commit the
  30. -      // transaction so as to remove the locks we acquired.
  31. -      // This will not commit the translation directly. Drupal will commit
  32. -      // it as soon as possible given the state of the transaction stack.
  33. -      unset($this->controllerTransaction);
  34. +    
  35. +    // Maintain the list of locked entities, so that the releaeLock() method
  36. +    // can know when it's time to commit the transaction.
  37. +    if (!empty($this->lockedEntities)) {
  38. +      foreach ($ids as $id) {
  39. +        unset($this->lockedEntities[$id]);
  40. +      }
  41. +    }
  42. +    // Try to release the lock, if possible.
  43. +    $this->releaseLock();
  44. +  }
  45. +  
  46. +  /**
  47. +   * Checks the list of tracked locked entities, and if it's empty, commits
  48. +   * the transaction in order to remove the acquired locks.
  49. +   * The transaction is not committed directly, Drupal commits it as soon
  50. +   * as possible given the state of the transaction stack.
  51. +   */
  52. +  protected function releaseLock() {
  53. +    if (isset($this->entityInfo['locking mode']) && $this->entityInfo['locking mode'] == 'pessimistic') {
  54. +      if (empty($this->lockedEntities)) {
  55. +        unset($this->controllerTransaction);
  56. +      }
  57.      }
  58.    }
  59.  
  60. @@ -194,8 +218,13 @@
  61.          ->execute();
  62.        }
  63.  
  64. -      $this->resetCache(array($entity->{$this->idKey}));
  65.        $this->invoke($op, $entity);
  66. +      // Update the static cache so that the next entity_load() is going
  67. +      // to return this newly saved entity.
  68. +      $this->entityCache[$entity->{$this->idKey}] = $entity;
  69. +      // Maintain the list of locked entities and release the lock if possible.
  70. +      unset($this->lockedEntities[$entity->{$this->idKey}]);
  71. +      $this->releaseLock();
  72.  
  73.        // Ignore slave server temporarily.
  74.        db_ignore_slave();
Add Comment
Please, Sign In to add comment