--- lib/vendor/symfony/1.3.3/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Locking/Manager/Pessimistic.php 2010-05-06 13:45:48.581693945 +0200 +++ ./Pessimistic.php 2010-07-02 16:36:05.795879962 +0200 @@ -30,6 +30,7 @@ * @author Roman Borschel * @author Pierre Minnieur * @author Konsta Vesterinen + * @author Florian Zumkeller-Quast * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @since 1.0 * @version $Revision: 6484 $ @@ -89,6 +90,36 @@ } } + + /** + * Create and return a unique key for the the given record + * + * @author Florian Zumkeller-Quast + * + * @since 2010-07-02 + * + * @param Doctrine_Record $record The record to create the object key for + * + * @return string The object key for the given record + */ + private function getObjectKey(Doctrine_Record $record) + { + $fields = $record->getTable()->getIdentifier(); + + // Check if its a composite PK + if(is_array($fields) === false) { + $fields = array($fields); + } + + $key = ''; + foreach($fields as $field) { + $value = $record->get($field); + $key = sprintf('%s|%s:%s', $key, $field, base64_encode($value)); + } + + return sha1($key); + } + /** * Obtains a lock on a {@link Doctrine_Record} * @@ -101,16 +132,11 @@ public function getLock(Doctrine_Record $record, $userIdent) { $objectType = $record->getTable()->getComponentName(); - $key = $record->getTable()->getIdentifier(); + $key = $this->getObjectKey($record); $gotLock = false; $time = time(); - if (is_array($key)) { - // Composite key - $key = implode('|', $key); - } - try { $dbh = $this->conn->getDbh(); $this->conn->beginTransaction(); @@ -170,12 +196,7 @@ public function releaseLock(Doctrine_Record $record, $userIdent) { $objectType = $record->getTable()->getComponentName(); - $key = $record->getTable()->getIdentifier(); - - if (is_array($key)) { - // Composite key - $key = implode('|', $key); - } + $key = $this->getObjectKey($record); try { $dbh = $this->conn->getDbh(); @@ -206,11 +227,6 @@ */ private function _getLockingUserIdent($objectType, $key) { - if (is_array($key)) { - // Composite key - $key = implode('|', $key); - } - try { $dbh = $this->conn->getDbh(); $stmt = $dbh->prepare('SELECT user_ident FROM ' . $this->_lockTable @@ -241,7 +257,7 @@ public function getLockOwner($lockedRecord) { $objectType = $lockedRecord->getTable()->getComponentName(); - $key = $lockedRecord->getTable()->getIdentifier(); + $key = $this->getObjectKey($lockedRecord); return $this->_getLockingUserIdent($objectType, $key); }