diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php
index dcf8c8abf..cc6122a11 100644
--- a/application/cmdbabstract.class.inc.php
+++ b/application/cmdbabstract.class.inc.php
@@ -5923,14 +5923,14 @@ JS
*
* @since 3.1.0
*/
- final protected function FireEventCheckToWrite(): void
+ final protected function FireEventCheckToWrite(?string $sStimulusBeingApplied): void
{
- $this->FireEvent(EVENT_DB_CHECK_TO_WRITE, ['is_new' => $this->IsNew()]);
+ $this->FireEvent(EVENT_DB_CHECK_TO_WRITE, ['is_new' => $this->IsNew(), 'stimulus_applied' => $sStimulusBeingApplied]);
}
- final protected function FireEventBeforeWrite()
+ final protected function FireEventBeforeWrite(?string $sStimulusBeingApplied)
{
- $this->FireEvent(EVENT_DB_BEFORE_WRITE, ['is_new' => $this->IsNew()]);
+ $this->FireEvent(EVENT_DB_BEFORE_WRITE, ['is_new' => $this->IsNew(), 'stimulus_applied' => $sStimulusBeingApplied]);
}
/**
@@ -5942,11 +5942,11 @@ JS
* @throws \CoreException
* @since 3.1.0
*/
- final protected function FireEventAfterWrite(array $aChanges, bool $bIsNew): void
+ final protected function FireEventAfterWrite(array $aChanges, bool $bIsNew, ?string $sStimulusBeingApplied): void
{
$this->NotifyAttachedObjectsOnLinkClassModification();
$this->RemoveObjectAwaitingEventDbLinksChanged(get_class($this), $this->GetKey());
- $this->FireEvent(EVENT_DB_AFTER_WRITE, ['is_new' => $bIsNew, 'changes' => $aChanges]);
+ $this->FireEvent(EVENT_DB_AFTER_WRITE, ['is_new' => $bIsNew, 'changes' => $aChanges, 'stimulus_applied' => $sStimulusBeingApplied]);
}
//////////////
@@ -6179,9 +6179,9 @@ JS
* @inheritDoc
* @throws \CoreException
*/
- final protected function FireEventComputeValues(): void
+ final protected function FireEventComputeValues(?string $sStimulusBeingApplied): void
{
- $this->FireEvent(EVENT_DB_COMPUTE_VALUES);
+ $this->FireEvent(EVENT_DB_COMPUTE_VALUES, ['is_new' => $this->IsNew(), 'stimulus_applied' => $sStimulusBeingApplied]);
}
/**
diff --git a/application/datamodel.application.xml b/application/datamodel.application.xml
index 0fbc21741..0030af252 100644
--- a/application/datamodel.application.xml
+++ b/application/datamodel.application.xml
@@ -238,6 +238,10 @@ The object can be modified.]]>
Creation flag
boolean
+
+ Life cycle stimulus applied (null if not within a transition)
+ string
+
Debug string
string
@@ -263,6 +267,10 @@ Call $this->AddCheckWarning($sWarningMessage) to display a warning.
Creation flag
boolean
+
+ Life cycle stimulus applied (null if not within a transition)
+ string
+
Debug string
string
@@ -290,6 +298,10 @@ The modifications can be propagated to other objects.]]>
array
+
+ Life cycle stimulus applied (null if not within a transition)
+ string
+
Debug string
string
@@ -420,6 +432,14 @@ The only action allowed is to deny transitions with $this->DenyTransition($sTran
The object inserted
DBObject
+
+ Creation flag
+ boolean
+
+
+ Life cycle stimulus applied (null if not within a transition)
+ string
+
Debug string
string
diff --git a/core/dbobject.class.php b/core/dbobject.class.php
index b4f8c1c2a..971bfa3bb 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 $bStimulusBeingApplied = false;
+ private ?string $sStimulusBeingApplied = null;
/**
* DBObject constructor.
@@ -1208,7 +1208,7 @@ abstract class DBObject implements iDisplay
if ($aCallInfo["function"] != "ComputeValues") continue;
return; //skip!
}
- $this->FireEventComputeValues();
+ $this->FireEventComputeValues($this->sStimulusBeingApplied);
$oKPI = new ExecutionKPI();
$this->ComputeValues();
$oKPI->ComputeStatsForExtension($this, 'ComputeValues');
@@ -2671,7 +2671,7 @@ abstract class DBObject implements iDisplay
// Ultimate check - ensure DB integrity
$this->SetReadOnly('No modification allowed during CheckToCreate');
- $this->FireEventCheckToWrite();
+ $this->FireEventCheckToWrite($this->sStimulusBeingApplied);
$this->SetReadWrite();
$oKPI = new ExecutionKPI();
@@ -3400,7 +3400,7 @@ abstract class DBObject implements iDisplay
$this->OnInsert();
$oKPI->ComputeStatsForExtension($this, 'OnInsert');
- $this->FireEventBeforeWrite();
+ $this->FireEventBeforeWrite(null);
// If not automatically computed, then check that the key is given by the caller
if (!MetaModel::IsAutoIncrementKey($sRootClass)) {
@@ -3535,7 +3535,7 @@ abstract class DBObject implements iDisplay
*/
protected function PostInsertActions(): void
{
- $this->FireEventAfterWrite([], true);
+ $this->FireEventAfterWrite([], true, null);
$oKPI = new ExecutionKPI();
$this->AfterInsert();
$oKPI->ComputeStatsForExtension($this, 'AfterInsert');
@@ -3643,7 +3643,7 @@ abstract class DBObject implements iDisplay
$this->OnUpdate();
$oKPI->ComputeStatsForExtension($this, 'OnUpdate');
- $this->FireEventBeforeWrite();
+ $this->FireEventBeforeWrite($this->sStimulusBeingApplied);
// Freeze the changes at this point
$this->InitPreviousValuesForUpdatedAttributes();
@@ -3854,7 +3854,7 @@ abstract class DBObject implements iDisplay
*/
protected function PostUpdateActions(array $aChanges): void
{
- $this->FireEventAfterWrite($aChanges, false);
+ $this->FireEventAfterWrite($aChanges, false, $this->sStimulusBeingApplied);
$oKPI = new ExecutionKPI();
$this->AfterUpdate();
$oKPI->ComputeStatsForExtension($this, 'AfterUpdate');
@@ -3866,9 +3866,9 @@ abstract class DBObject implements iDisplay
$this->ActivateOnObjectUpdateTriggersForTargetObjects();
$sClass = get_class($this);
- if ($this->bStimulusBeingApplied)
+ if (utils::IsNotNullOrEmptyString($this->sStimulusBeingApplied))
{
- $this->bStimulusBeingApplied = false;
+ $this->sStimulusBeingApplied = null;
$sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
$sPreviousState = $this->m_aPreviousValuesForUpdatedAttributes[$sStateAttCode];
// Change state triggers...
@@ -4604,7 +4604,7 @@ abstract class DBObject implements iDisplay
}
if ($bSuccess)
{
- $this->bStimulusBeingApplied = true;
+ $this->sStimulusBeingApplied = $sStimulusCode;
// Stop watches
foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
{
@@ -6619,7 +6619,7 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
- protected function FireEventCheckToWrite(): void
+ protected function FireEventCheckToWrite(?string $sStimulusBeingApplied): void
{
}
@@ -6627,7 +6627,7 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
- protected function FireEventBeforeWrite()
+ protected function FireEventBeforeWrite(?string $sStimulusBeingApplied)
{
}
@@ -6637,7 +6637,7 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
- protected function FireEventAfterWrite(array $aChanges, bool $bIsNew): void
+ protected function FireEventAfterWrite(array $aChanges, bool $bIsNew, ?string $sStimulusBeingApplied): void
{
}
@@ -6675,7 +6675,7 @@ abstract class DBObject implements iDisplay
* @return void
* @since 3.1.0
*/
- protected function FireEventComputeValues(): void
+ protected function FireEventComputeValues(?string $sStimulusBeingApplied): void
{
}
diff --git a/tests/php-unit-tests/unitary-tests/core/OQLParserTest.php b/tests/php-unit-tests/unitary-tests/core/OQLParserTest.php
index 0c29c7b1a..97b5e049f 100644
--- a/tests/php-unit-tests/unitary-tests/core/OQLParserTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/OQLParserTest.php
@@ -21,8 +21,6 @@ use UserRights;
class OQLParserTest extends ItopDataTestCase
{
- const USE_TRANSACTION = false;
- const CREATE_TEST_ORG = true;
/**
* @group iTopChangeMgt
@@ -46,7 +44,8 @@ class OQLParserTest extends ItopDataTestCase
public function testUnknownClassOqlException()
{
- $sLogin = $this->GivenUserRestrictedToAnOrganizationInDB($this->getTestOrgId(), self::$aURP_Profiles['Portal user']);
+ $oOrgId = $this->GivenObjectInDB('Organization', ['name' => 'TestOrg']);
+ $sLogin = $this->GivenUserRestrictedToAnOrganizationInDB($oOrgId, self::$aURP_Profiles['Portal user']);
UserRights::Login($sLogin);
try {