Permalink
Browse files

PIMCORE-590 - consider race conditions (document/asset/object) fixed …

…problem when creating new elements

git-svn-id: http://www.pimcore.org/svn/pimcore/private/core/trunk@1955 1f8fe7d8-47f0-464c-8d0a-336f4953ab05
  • Loading branch information...
1 parent 4089367 commit bb98cf04c53381faa6d88f2c140dee7feccc1109 brusch committed Oct 12, 2012
View
@@ -369,7 +369,11 @@ public function loadData() {
*/
public function save() {
- Tool_Lock::acquire($this->getCacheTag());
+ if($this->getId()) {
+ // do not lock when creating a new asset, this will cause a dead-lock because the cache-tag is used as key
+ // and the cache tag is different when releasing the lock later, because the asset has then an id
+ Tool_Lock::acquire($this->getCacheTag());
+ }
if (!Pimcore_Tool::isValidKey($this->getKey())) {
throw new Exception("invalid filname '".$this->getKey()."' for asset with id [ " . $this->getId() . " ]");
@@ -320,7 +320,11 @@ public static function getList($config = array()) {
*/
public function save() {
- Tool_Lock::acquire($this->getCacheTag());
+ if($this->getId()) {
+ // do not lock when creating a new document, this will cause a dead-lock because the cache-tag is used as key
+ // and the cache tag is different when releasing the lock later, because the document has then an id
+ Tool_Lock::acquire($this->getCacheTag());
+ }
// check for a valid key, home has no key, so omit the check
if (!Pimcore_Tool::isValidKey($this->getKey()) && $this->getId() != 1) {
@@ -529,7 +529,11 @@ public function delete() {
*/
public function save() {
- Tool_Lock::acquire($this->getCacheTag());
+ if($this->getO_Id()) {
+ // do not lock when creating a new object, this will cause a dead-lock because the cache-tag is used as key
+ // and the cache tag is different when releasing the lock later, because the object has then an id
+ Tool_Lock::acquire($this->getCacheTag());
+ }
// be sure that unpublished objects in relations are saved also in frontend mode, eg. in importers, ...
$hideUnpublishedBackup = self::getHideUnpublished();
@@ -62,6 +62,15 @@ public static function release ($key) {
* @param string $key
* @return bool
*/
+ public static function lock ($key) {
+ $instance = self::getInstance();
+ return $instance->getResource()->lock($key);
+ }
+
+ /**
+ * @param string $key
+ * @return bool
+ */
public static function isLocked ($key) {
$instance = self::getInstance();
return $instance->getResource()->isLocked($key);
@@ -62,4 +62,18 @@ public function acquire ($key) {
public function release ($key) {
$this->db->delete("locks", "id = '" . $key . "'");
}
+
+ public function lock ($key) {
+
+ try {
+ $this->db->insert("locks", array(
+ "id" => $key,
+ "date" => time()
+ ));
+ } catch (Exception $e) {
+ $this->db->update("locks", array(
+ "date" => time()
+ ), "id = '" . $key . "'");
+ }
+ }
}

0 comments on commit bb98cf0

Please sign in to comment.