Skip to content

Commit a77765e

Browse files
committed
N°8019 - Enrich event with transition information
1 parent 64b4b03 commit a77765e

File tree

3 files changed

+42
-22
lines changed

3 files changed

+42
-22
lines changed

application/cmdbabstract.class.inc.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -5923,14 +5923,14 @@ public static function GetAttDefClassesToExcludeFromMarkupMetadataRawValue(){
59235923
*
59245924
* @since 3.1.0
59255925
*/
5926-
final protected function FireEventCheckToWrite(): void
5926+
final protected function FireEventCheckToWrite(?string $sStimulusBeingApplied): void
59275927
{
5928-
$this->FireEvent(EVENT_DB_CHECK_TO_WRITE, ['is_new' => $this->IsNew()]);
5928+
$this->FireEvent(EVENT_DB_CHECK_TO_WRITE, ['is_new' => $this->IsNew(), 'stimulus_applied' => $sStimulusBeingApplied]);
59295929
}
59305930

5931-
final protected function FireEventBeforeWrite()
5931+
final protected function FireEventBeforeWrite(?string $sStimulusBeingApplied)
59325932
{
5933-
$this->FireEvent(EVENT_DB_BEFORE_WRITE, ['is_new' => $this->IsNew()]);
5933+
$this->FireEvent(EVENT_DB_BEFORE_WRITE, ['is_new' => $this->IsNew(), 'stimulus_applied' => $sStimulusBeingApplied]);
59345934
}
59355935

59365936
/**
@@ -5942,11 +5942,11 @@ final protected function FireEventBeforeWrite()
59425942
* @throws \CoreException
59435943
* @since 3.1.0
59445944
*/
5945-
final protected function FireEventAfterWrite(array $aChanges, bool $bIsNew): void
5945+
final protected function FireEventAfterWrite(array $aChanges, bool $bIsNew, ?string $sStimulusBeingApplied): void
59465946
{
59475947
$this->NotifyAttachedObjectsOnLinkClassModification();
59485948
$this->RemoveObjectAwaitingEventDbLinksChanged(get_class($this), $this->GetKey());
5949-
$this->FireEvent(EVENT_DB_AFTER_WRITE, ['is_new' => $bIsNew, 'changes' => $aChanges]);
5949+
$this->FireEvent(EVENT_DB_AFTER_WRITE, ['is_new' => $bIsNew, 'changes' => $aChanges, 'stimulus_applied' => $sStimulusBeingApplied]);
59505950
}
59515951

59525952
//////////////
@@ -6179,9 +6179,9 @@ final public static function SetEventDBLinksChangedBlocked(bool $bBlockEventDBLi
61796179
* @inheritDoc
61806180
* @throws \CoreException
61816181
*/
6182-
final protected function FireEventComputeValues(): void
6182+
final protected function FireEventComputeValues(?string $sStimulusBeingApplied): void
61836183
{
6184-
$this->FireEvent(EVENT_DB_COMPUTE_VALUES);
6184+
$this->FireEvent(EVENT_DB_COMPUTE_VALUES, ['is_new' => $this->IsNew(), 'stimulus_applied' => $sStimulusBeingApplied]);
61856185
}
61866186

61876187
/**

application/datamodel.application.xml

+20
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ The object can be modified.]]></description>
238238
<description>Creation flag</description>
239239
<type>boolean</type>
240240
</event_datum>
241+
<event_datum id="stimulus_applied">
242+
<description>Life cycle stimulus applied (null if not within a transition)</description>
243+
<type>string</type>
244+
</event_datum>
241245
<event_datum id="debug_info">
242246
<description>Debug string</description>
243247
<type>string</type>
@@ -263,6 +267,10 @@ Call $this->AddCheckWarning($sWarningMessage) to display a warning.
263267
<description>Creation flag</description>
264268
<type>boolean</type>
265269
</event_datum>
270+
<event_datum id="stimulus_applied">
271+
<description>Life cycle stimulus applied (null if not within a transition)</description>
272+
<type>string</type>
273+
</event_datum>
266274
<event_datum id="debug_info">
267275
<description>Debug string</description>
268276
<type>string</type>
@@ -290,6 +298,10 @@ The modifications can be propagated to other objects.]]></description>
290298
<description><![CDATA[For updates, the list of changes done during this operation]]></description>
291299
<type>array</type>
292300
</event_datum>
301+
<event_datum id="stimulus_applied">
302+
<description>Life cycle stimulus applied (null if not within a transition)</description>
303+
<type>string</type>
304+
</event_datum>
293305
<event_datum id="debug_info">
294306
<description>Debug string</description>
295307
<type>string</type>
@@ -420,6 +432,14 @@ The only action allowed is to deny transitions with $this->DenyTransition($sTran
420432
<description>The object inserted</description>
421433
<type>DBObject</type>
422434
</event_datum>
435+
<event_datum id="is_new">
436+
<description>Creation flag</description>
437+
<type>boolean</type>
438+
</event_datum>
439+
<event_datum id="stimulus_applied">
440+
<description>Life cycle stimulus applied (null if not within a transition)</description>
441+
<type>string</type>
442+
</event_datum>
423443
<event_datum id="debug_info">
424444
<description>Debug string</description>
425445
<type>string</type>

core/dbobject.class.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ abstract class DBObject implements iDisplay
212212
private $aEventListeners = [];
213213
private array $aAllowedTransitions = [];
214214

215-
private bool $bStimulusBeingApplied = false;
215+
private ?string $sStimulusBeingApplied = null;
216216

217217
/**
218218
* DBObject constructor.
@@ -1208,7 +1208,7 @@ final public function DoComputeValues()
12081208
if ($aCallInfo["function"] != "ComputeValues") continue;
12091209
return; //skip!
12101210
}
1211-
$this->FireEventComputeValues();
1211+
$this->FireEventComputeValues($this->sStimulusBeingApplied);
12121212
$oKPI = new ExecutionKPI();
12131213
$this->ComputeValues();
12141214
$oKPI->ComputeStatsForExtension($this, 'ComputeValues');
@@ -2671,7 +2671,7 @@ final public function CheckToWrite($bDoComputeValues = true)
26712671

26722672
// Ultimate check - ensure DB integrity
26732673
$this->SetReadOnly('No modification allowed during CheckToCreate');
2674-
$this->FireEventCheckToWrite();
2674+
$this->FireEventCheckToWrite($this->sStimulusBeingApplied);
26752675
$this->SetReadWrite();
26762676

26772677
$oKPI = new ExecutionKPI();
@@ -3400,7 +3400,7 @@ public function DBInsertNoReload()
34003400
$this->OnInsert();
34013401
$oKPI->ComputeStatsForExtension($this, 'OnInsert');
34023402

3403-
$this->FireEventBeforeWrite();
3403+
$this->FireEventBeforeWrite(null);
34043404

34053405
// If not automatically computed, then check that the key is given by the caller
34063406
if (!MetaModel::IsAutoIncrementKey($sRootClass)) {
@@ -3535,7 +3535,7 @@ public function DBInsertNoReload()
35353535
*/
35363536
protected function PostInsertActions(): void
35373537
{
3538-
$this->FireEventAfterWrite([], true);
3538+
$this->FireEventAfterWrite([], true, null);
35393539
$oKPI = new ExecutionKPI();
35403540
$this->AfterInsert();
35413541
$oKPI->ComputeStatsForExtension($this, 'AfterInsert');
@@ -3643,7 +3643,7 @@ public function DBUpdate()
36433643
$this->OnUpdate();
36443644
$oKPI->ComputeStatsForExtension($this, 'OnUpdate');
36453645

3646-
$this->FireEventBeforeWrite();
3646+
$this->FireEventBeforeWrite($this->sStimulusBeingApplied);
36473647

36483648
// Freeze the changes at this point
36493649
$this->InitPreviousValuesForUpdatedAttributes();
@@ -3854,7 +3854,7 @@ public function DBUpdate()
38543854
*/
38553855
protected function PostUpdateActions(array $aChanges): void
38563856
{
3857-
$this->FireEventAfterWrite($aChanges, false);
3857+
$this->FireEventAfterWrite($aChanges, false, $this->sStimulusBeingApplied);
38583858
$oKPI = new ExecutionKPI();
38593859
$this->AfterUpdate();
38603860
$oKPI->ComputeStatsForExtension($this, 'AfterUpdate');
@@ -3866,9 +3866,9 @@ protected function PostUpdateActions(array $aChanges): void
38663866
$this->ActivateOnObjectUpdateTriggersForTargetObjects();
38673867

38683868
$sClass = get_class($this);
3869-
if ($this->bStimulusBeingApplied)
3869+
if (utils::IsNotNullOrEmptyString($this->sStimulusBeingApplied))
38703870
{
3871-
$this->bStimulusBeingApplied = false;
3871+
$this->sStimulusBeingApplied = null;
38723872
$sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
38733873
$sPreviousState = $this->m_aPreviousValuesForUpdatedAttributes[$sStateAttCode];
38743874
// Change state triggers...
@@ -4604,7 +4604,7 @@ public function ApplyStimulus($sStimulusCode, $bDoNotWrite = false)
46044604
}
46054605
if ($bSuccess)
46064606
{
4607-
$this->bStimulusBeingApplied = true;
4607+
$this->sStimulusBeingApplied = $sStimulusCode;
46084608
// Stop watches
46094609
foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
46104610
{
@@ -6619,15 +6619,15 @@ public function FireEvent(string $sEvent, array $aEventData = array()): void
66196619
* @return void
66206620
* @since 3.1.0
66216621
*/
6622-
protected function FireEventCheckToWrite(): void
6622+
protected function FireEventCheckToWrite(?string $sStimulusBeingApplied): void
66236623
{
66246624
}
66256625

66266626
/**
66276627
* @return void
66286628
* @since 3.1.0
66296629
*/
6630-
protected function FireEventBeforeWrite()
6630+
protected function FireEventBeforeWrite(?string $sStimulusBeingApplied)
66316631
{
66326632
}
66336633

@@ -6637,7 +6637,7 @@ protected function FireEventBeforeWrite()
66376637
* @return void
66386638
* @since 3.1.0
66396639
*/
6640-
protected function FireEventAfterWrite(array $aChanges, bool $bIsNew): void
6640+
protected function FireEventAfterWrite(array $aChanges, bool $bIsNew, ?string $sStimulusBeingApplied): void
66416641
{
66426642
}
66436643

@@ -6675,7 +6675,7 @@ protected function FireEventAboutToDelete(): void
66756675
* @return void
66766676
* @since 3.1.0
66776677
*/
6678-
protected function FireEventComputeValues(): void
6678+
protected function FireEventComputeValues(?string $sStimulusBeingApplied): void
66796679
{
66806680
}
66816681

0 commit comments

Comments
 (0)