From f718b4173d0b06fe3a30e693d4595231e6daab05 Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Mon, 2 Dec 2024 17:28:15 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B07206=20-=20TriggerOnStateEnter=20not=20c?= =?UTF-8?q?alled=20when=20using=20reassign=20transition=20(after=20review)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/dbobject.class.php | 62 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 4128263f9..b4f8c1c2a 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -212,7 +212,7 @@ abstract class DBObject implements iDisplay private $aEventListeners = []; private array $aAllowedTransitions = []; - private bool $bStimulusApplied = false; + private bool $bStimulusBeingApplied = false; /** * DBObject constructor. @@ -3866,40 +3866,38 @@ abstract class DBObject implements iDisplay $this->ActivateOnObjectUpdateTriggersForTargetObjects(); $sClass = get_class($this); - if (MetaModel::HasLifecycle($sClass)) + if ($this->bStimulusBeingApplied) { + $this->bStimulusBeingApplied = false; $sStateAttCode = MetaModel::GetStateAttributeCode($sClass); - if ($this->bStimulusApplied || isset($this->m_aPreviousValuesForUpdatedAttributes[$sStateAttCode])) { - $this->bStimulusApplied = false; - $sPreviousState = $this->m_aPreviousValuesForUpdatedAttributes[$sStateAttCode]; - // Change state triggers... - $aParams = array( - 'class_list' => MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL), - 'previous_state' => $sPreviousState, - 'new_state' => $this->Get($sStateAttCode), - ); - $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT TriggerOnStateLeave AS t WHERE t.target_class IN (:class_list) AND t.state=:previous_state'), array(), $aParams); - while ($oTrigger = $oSet->Fetch()) { - /** @var \TriggerOnStateLeave $oTrigger */ - try { - $oTrigger->DoActivate($this->ToArgs('this')); - } - catch (Exception $e) { - $oTrigger->LogException($e, $this); - utils::EnrichRaisedException($oTrigger, $e); - } + $sPreviousState = $this->m_aPreviousValuesForUpdatedAttributes[$sStateAttCode]; + // Change state triggers... + $aParams = array( + 'class_list' => MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL), + 'previous_state' => $sPreviousState, + 'new_state' => $this->Get($sStateAttCode), + ); + $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT TriggerOnStateLeave AS t WHERE t.target_class IN (:class_list) AND t.state=:previous_state'), array(), $aParams); + while ($oTrigger = $oSet->Fetch()) { + /** @var \TriggerOnStateLeave $oTrigger */ + try { + $oTrigger->DoActivate($this->ToArgs('this')); } + catch (Exception $e) { + $oTrigger->LogException($e, $this); + utils::EnrichRaisedException($oTrigger, $e); + } + } - $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT TriggerOnStateEnter AS t WHERE t.target_class IN (:class_list) AND t.state=:new_state'), array(), $aParams); - while ($oTrigger = $oSet->Fetch()) { - /** @var \TriggerOnStateEnter $oTrigger */ - try { - $oTrigger->DoActivate($this->ToArgs('this')); - } - catch (Exception $e) { - $oTrigger->LogException($e, $this); - utils::EnrichRaisedException($oTrigger, $e); - } + $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT TriggerOnStateEnter AS t WHERE t.target_class IN (:class_list) AND t.state=:new_state'), array(), $aParams); + while ($oTrigger = $oSet->Fetch()) { + /** @var \TriggerOnStateEnter $oTrigger */ + try { + $oTrigger->DoActivate($this->ToArgs('this')); + } + catch (Exception $e) { + $oTrigger->LogException($e, $this); + utils::EnrichRaisedException($oTrigger, $e); } } } @@ -4606,7 +4604,7 @@ abstract class DBObject implements iDisplay } if ($bSuccess) { - $this->bStimulusApplied = true; + $this->bStimulusBeingApplied = true; // Stop watches foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {