From 3e47c9a8d68d5a82a974487dc7c10b408cb9c455 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Wed, 17 Jul 2024 16:26:46 +0200 Subject: [PATCH] Fixed saving PreorderHistory only once --- application/Preorder/Preorder.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php index 24323462c..1e12c17d8 100644 --- a/application/Preorder/Preorder.php +++ b/application/Preorder/Preorder.php @@ -38,14 +38,26 @@ class Preorder extends mfBaseModel { $this->ordered_services = null; $this->creator = null; $this->editor = null; - + + $nesting_level = mfValuecache::singleton()->get("preorder-save-nesting-level-".$this->id); + if(!$nesting_level) { + $nesting_level = 1; + } else { + $nesting_level++; + } + mfValuecache::singleton()->set("preorder-save-nesting-level-".$this->id, $nesting_level); + + if($nesting_level > 1) { + return true; + } + // prevent potential infinite loop - if($this->in_after_save) return true; - $this->in_after_save++; + //if($this->in_after_save) return true; + //$this->in_after_save++; // update preorder OAID if it's different from the unit OAID // but only if the unit OAID is of the same origin as the campaign $old_oaid = $this->oaid; - + $this->setOrCreateOaid(); if($this->oaid != $old_oaid) { $this->save(); @@ -54,6 +66,7 @@ class Preorder extends mfBaseModel { //TODO: history start if($this->status_id != $this->_old_data->status_id) { $this->createHistoryEntry(); + $this->_old_data->status_id = $this->status_id; } // run triggers based on new status @@ -62,8 +75,7 @@ class Preorder extends mfBaseModel { $this->cascadeStatus(); // Cascade status changes down all active preorders with the same hausnummer $this->cascadeStatusToPreorders(); - - $this->in_after_save--; + } public function createHistoryEntry() {