mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
N°5906 - CRUD Event - Fix listener launched twice and refactor calls to Tickets::UpdateImpactedItems()
This commit is contained in:
@@ -4533,8 +4533,6 @@ HTML;
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (static::IsCrudStackEmpty()) {
|
if (static::IsCrudStackEmpty()) {
|
||||||
// Avoid signaling the current object that links were modified
|
|
||||||
static::RemoveObjectAwaitingEventDbLinksChanged(get_class($this), $this->GetKey());
|
|
||||||
static::FireEventDbLinksChangedForAllObjects();
|
static::FireEventDbLinksChangedForAllObjects();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5811,6 +5809,7 @@ JS
|
|||||||
final protected function FireEventCreateDone(): void
|
final protected function FireEventCreateDone(): void
|
||||||
{
|
{
|
||||||
$this->NotifyAttachedObjectsOnLinkClassModification();
|
$this->NotifyAttachedObjectsOnLinkClassModification();
|
||||||
|
$this->FireEventDbLinksChangedForCurrentObject();
|
||||||
$this->FireEvent(EVENT_DB_CREATE_DONE);
|
$this->FireEvent(EVENT_DB_CREATE_DONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5829,6 +5828,7 @@ JS
|
|||||||
final protected function FireEventUpdateDone(array $aChanges): void
|
final protected function FireEventUpdateDone(array $aChanges): void
|
||||||
{
|
{
|
||||||
$this->NotifyAttachedObjectsOnLinkClassModification();
|
$this->NotifyAttachedObjectsOnLinkClassModification();
|
||||||
|
$this->FireEventDbLinksChangedForCurrentObject();
|
||||||
$this->FireEvent(EVENT_DB_UPDATE_DONE, ['changes' => $aChanges]);
|
$this->FireEvent(EVENT_DB_UPDATE_DONE, ['changes' => $aChanges]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5857,6 +5857,7 @@ JS
|
|||||||
final protected function FireEventDeleteDone(): void
|
final protected function FireEventDeleteDone(): void
|
||||||
{
|
{
|
||||||
$this->NotifyAttachedObjectsOnLinkClassModification();
|
$this->NotifyAttachedObjectsOnLinkClassModification();
|
||||||
|
$this->FireEventDbLinksChangedForCurrentObject();
|
||||||
$this->FireEvent(EVENT_DB_DELETE_DONE);
|
$this->FireEvent(EVENT_DB_DELETE_DONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5955,11 +5956,24 @@ JS
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$oObject = MetaModel::GetObject($sClass, $sId);
|
// First we are disabling firing the event to avoid reentrance
|
||||||
|
// For example on a Ticket :
|
||||||
|
// - in the Ticket CRUD stack, DBWriteLinks will generate lnkApplicationSolutionToFunctionalCI instances
|
||||||
|
// - therefore the $aObjectsAwaitingEventDbLinksChanged attribute will contain our Ticket
|
||||||
|
// - we have a EVENT_DB_LINKS_CHANGED listener on Ticket that will update impacted items, so it will create new lnkApplicationSolutionToFunctionalCI
|
||||||
|
// We want to avoid launching the listener twice, first here, and secondly after saving the Ticket in the listener
|
||||||
|
// By disabling the event to be fired, we can remove the current object from the attribute !
|
||||||
|
/** @noinspection PhpRedundantOptionalArgumentInspection */
|
||||||
|
$oObject = MetaModel::GetObject($sClass, $sId, true);
|
||||||
|
self::SetEventDBLinksChangedBlocked(true);
|
||||||
|
MetaModel::StartReentranceProtection($oObject);
|
||||||
$oObject->FireEvent(EVENT_DB_LINKS_CHANGED);
|
$oObject->FireEvent(EVENT_DB_LINKS_CHANGED);
|
||||||
|
MetaModel::StopReentranceProtection($oObject);
|
||||||
// The event listeners might have generated new lnk instances pointing to this object, so removing object from stack to avoid reentrance
|
if ($oObject->IsModified()) {
|
||||||
|
$oObject->DBUpdate();
|
||||||
|
}
|
||||||
self::RemoveObjectAwaitingEventDbLinksChanged($sClass, $sId);
|
self::RemoveObjectAwaitingEventDbLinksChanged($sClass, $sId);
|
||||||
|
cmdbAbstractObject::SetEventDBLinksChangedBlocked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1022,8 +1022,7 @@
|
|||||||
<code><![CDATA[
|
<code><![CDATA[
|
||||||
protected function OnInsert()
|
protected function OnInsert()
|
||||||
{
|
{
|
||||||
parent::OnInsert();
|
parent::OnInsert();
|
||||||
$this->UpdateImpactedItems();
|
|
||||||
$this->SetIfNull('creation_date', time());
|
$this->SetIfNull('creation_date', time());
|
||||||
$this->SetIfNull('last_update', time());
|
$this->SetIfNull('last_update', time());
|
||||||
}]]></code>
|
}]]></code>
|
||||||
@@ -1036,11 +1035,6 @@
|
|||||||
protected function OnUpdate()
|
protected function OnUpdate()
|
||||||
{
|
{
|
||||||
parent::OnUpdate();
|
parent::OnUpdate();
|
||||||
$aChanges = $this->ListChanges();
|
|
||||||
if (array_key_exists('functionalcis_list', $aChanges))
|
|
||||||
{
|
|
||||||
$this->UpdateImpactedItems();
|
|
||||||
}
|
|
||||||
$this->Set('last_update', time());
|
$this->Set('last_update', time());
|
||||||
}]]></code>
|
}]]></code>
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
@@ -581,8 +581,7 @@
|
|||||||
<code><![CDATA[
|
<code><![CDATA[
|
||||||
protected function OnInsert()
|
protected function OnInsert()
|
||||||
{
|
{
|
||||||
parent::OnInsert();
|
parent::OnInsert();
|
||||||
$this->UpdateImpactedItems();
|
|
||||||
$this->SetIfNull('creation_date', time());
|
$this->SetIfNull('creation_date', time());
|
||||||
$this->SetIfNull('last_update', time());
|
$this->SetIfNull('last_update', time());
|
||||||
}]]></code>
|
}]]></code>
|
||||||
@@ -594,12 +593,7 @@
|
|||||||
<code><![CDATA[
|
<code><![CDATA[
|
||||||
protected function OnUpdate()
|
protected function OnUpdate()
|
||||||
{
|
{
|
||||||
parent::OnUpdate();
|
parent::OnUpdate();
|
||||||
$aChanges = $this->ListChanges();
|
|
||||||
if (array_key_exists('functionalcis_list', $aChanges))
|
|
||||||
{
|
|
||||||
$this->UpdateImpactedItems();
|
|
||||||
}
|
|
||||||
$this->Set('last_update', time());
|
$this->Set('last_update', time());
|
||||||
}]]></code>
|
}]]></code>
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
@@ -1496,12 +1496,7 @@
|
|||||||
<type>Overload-DBObject</type>
|
<type>Overload-DBObject</type>
|
||||||
<code><![CDATA[ protected function OnUpdate()
|
<code><![CDATA[ protected function OnUpdate()
|
||||||
{
|
{
|
||||||
parent::OnUpdate();
|
parent::OnUpdate();
|
||||||
$aChanges = $this->ListChanges();
|
|
||||||
if (array_key_exists('functionalcis_list', $aChanges))
|
|
||||||
{
|
|
||||||
$this->UpdateImpactedItems();
|
|
||||||
}
|
|
||||||
$this->Set('last_update', time());
|
$this->Set('last_update', time());
|
||||||
$this->UpdateChildRequestLog();
|
$this->UpdateChildRequestLog();
|
||||||
$this->UpdateChildIncidentLog();
|
$this->UpdateChildIncidentLog();
|
||||||
|
|||||||
@@ -1567,11 +1567,6 @@
|
|||||||
protected function OnUpdate()
|
protected function OnUpdate()
|
||||||
{
|
{
|
||||||
parent::OnUpdate();
|
parent::OnUpdate();
|
||||||
$aChanges = $this->ListChanges();
|
|
||||||
if (array_key_exists('functionalcis_list', $aChanges))
|
|
||||||
{
|
|
||||||
$this->UpdateImpactedItems();
|
|
||||||
}
|
|
||||||
$this->Set('last_update', time());
|
$this->Set('last_update', time());
|
||||||
$this->UpdateChildRequestLog();
|
$this->UpdateChildRequestLog();
|
||||||
}]]></code>
|
}]]></code>
|
||||||
|
|||||||
@@ -1610,12 +1610,7 @@
|
|||||||
<code><![CDATA[
|
<code><![CDATA[
|
||||||
protected function OnUpdate()
|
protected function OnUpdate()
|
||||||
{
|
{
|
||||||
parent::OnUpdate();
|
parent::OnUpdate();
|
||||||
$aChanges = $this->ListChanges();
|
|
||||||
if (array_key_exists('functionalcis_list', $aChanges))
|
|
||||||
{
|
|
||||||
$this->UpdateImpactedItems();
|
|
||||||
}
|
|
||||||
$this->Set('last_update', time());
|
$this->Set('last_update', time());
|
||||||
$this->UpdateChildRequestLog();
|
$this->UpdateChildRequestLog();
|
||||||
}]]></code>
|
}]]></code>
|
||||||
|
|||||||
@@ -223,23 +223,11 @@
|
|||||||
<event_listeners>
|
<event_listeners>
|
||||||
<listener id="UpdateImpactAnalysis">
|
<listener id="UpdateImpactAnalysis">
|
||||||
<event>EVENT_DB_LINKS_CHANGED</event>
|
<event>EVENT_DB_LINKS_CHANGED</event>
|
||||||
<callback>UpdateTicketImpactedItems</callback>
|
<callback>UpdateImpactedItems</callback>
|
||||||
<rank>0</rank>
|
<rank>0</rank>
|
||||||
</listener>
|
</listener>
|
||||||
</event_listeners>
|
</event_listeners>
|
||||||
<methods>
|
<methods>
|
||||||
<method id="UpdateTicketImpactedItems">
|
|
||||||
<comment/>
|
|
||||||
<static>false</static>
|
|
||||||
<access>public</access>
|
|
||||||
<type>EventListener</type>
|
|
||||||
<code><![CDATA[
|
|
||||||
public function UpdateTicketImpactedItems(Combodo\iTop\Service\Events\EventData $oEventData) {
|
|
||||||
$this->UpdateImpactedItems();
|
|
||||||
$this->DBUpdate();
|
|
||||||
}
|
|
||||||
]]></code>
|
|
||||||
</method>
|
|
||||||
<method id="DBInsertNoReload">
|
<method id="DBInsertNoReload">
|
||||||
<static>false</static>
|
<static>false</static>
|
||||||
<access>public</access>
|
<access>public</access>
|
||||||
|
|||||||
@@ -195,8 +195,8 @@ class cmdbAbstractObjectTest extends ItopDataTestCase {
|
|||||||
$oTeam->DBInsert();
|
$oTeam->DBInsert();
|
||||||
$this->assertIsObject($oTeam);
|
$this->assertIsObject($oTeam);
|
||||||
|
|
||||||
// 3 links added to person (the Team side is ignored)
|
// 3 links added to person + 1 for the Team
|
||||||
$this->assertEquals(3, self::$aEventCalls[EVENT_DB_LINKS_CHANGED]);
|
$this->assertEquals(4, self::$aEventCalls[EVENT_DB_LINKS_CHANGED]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user