refactor Event Listeners

This commit is contained in:
Eric Espie
2022-06-01 14:29:43 +02:00
parent 35e1f080b8
commit e77f21a0b5
9 changed files with 136 additions and 119 deletions

View File

@@ -976,14 +976,14 @@
</states>
</lifecycle>
<event_listeners>
<listener id="OnInsertRequested">
<listener id="OnChangeInsertRequested">
<event>EVENT_SERVICE_DB_INSERT_REQUESTED</event>
<callback>OnInsertRequested</callback>
<callback>OnChangeInsertRequested</callback>
<priority>0</priority>
</listener>
<listener id="OnUpdateRequested">
<listener id="OnChangeUpdateRequested">
<event>EVENT_SERVICE_DB_UPDATE_REQUESTED</event>
<callback>OnUpdateRequested</callback>
<callback>OnChangeUpdateRequested</callback>
<priority>0</priority>
</listener>
</event_listeners>
@@ -1027,12 +1027,12 @@
return true;
}]]></code>
</method>
<method id="OnInsertRequested">
<method id="OnChangeInsertRequested">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<type>Overload-ExNihilo</type>
<code><![CDATA[
public function OnInsertRequested(Combodo\iTop\Service\EventData $oEventData)
public function OnChangeInsertRequested(Combodo\iTop\Service\EventData $oEventData)
{
$this->UpdateImpactedItems();
$this->SetIfNull('creation_date', time());
@@ -1040,12 +1040,12 @@
}]]>
</code>
</method>
<method id="OnUpdateRequested">
<method id="OnChangeUpdateRequested">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<type>Overload-ExNihilo</type>
<code><![CDATA[
public function OnUpdateRequested(Combodo\iTop\Service\EventData $oEventData)
public function OnChangeUpdateRequested(Combodo\iTop\Service\EventData $oEventData)
{
$aChanges = $this->ListChanges();
if (array_key_exists('functionalcis_list', $aChanges))

View File

@@ -513,14 +513,14 @@
</states>
</lifecycle>
<event_listeners>
<listener id="OnInsertRequested">
<listener id="OnChangeInsertRequested">
<event>EVENT_SERVICE_DB_INSERT_REQUESTED</event>
<callback>OnInsertRequested</callback>
<callback>OnChangeInsertRequested</callback>
<priority>0</priority>
</listener>
<listener id="OnUpdateRequested">
<listener id="OnChangeUpdateRequested">
<event>EVENT_SERVICE_DB_UPDATE_REQUESTED</event>
<callback>OnUpdateRequested</callback>
<callback>OnChangeUpdateRequested</callback>
<priority>0</priority>
</listener>
</event_listeners>
@@ -578,24 +578,24 @@
return true;
}]]></code>
</method>
<method id="OnInsertRequested">
<method id="OnChangeInsertRequested">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<type>Overload-ExNihilo</type>
<code><![CDATA[
public function OnInsertRequested(Combodo\iTop\Service\EventData $oEventData)
public function OnChangeInsertRequested(Combodo\iTop\Service\EventData $oEventData)
{
$this->UpdateImpactedItems();
$this->SetIfNull('creation_date', time());
$this->SetIfNull('last_update', time());
}]]></code>
</method>
<method id="OnUpdateRequested">
<method id="OnChangeUpdateRequested">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<type>Overload-ExNihilo</type>
<code><![CDATA[
public function OnUpdateRequested(Combodo\iTop\Service\EventData $oEventData)
public function OnChangeUpdateRequested(Combodo\iTop\Service\EventData $oEventData)
{
$aChanges = $this->ListChanges();
if (array_key_exists('functionalcis_list', $aChanges))

View File

@@ -1053,24 +1053,24 @@
</states>
</lifecycle>
<event_listeners>
<listener id="OnInsertRequested">
<listener id="OnIncidentInsertRequested">
<event>EVENT_SERVICE_DB_INSERT_REQUESTED</event>
<callback>OnInsertRequested</callback>
<callback>OnIncidentInsertRequested</callback>
<priority>0</priority>
</listener>
<listener id="OnUpdateRequested">
<listener id="OnIncidentUpdateRequested">
<event>EVENT_SERVICE_DB_UPDATE_REQUESTED</event>
<callback>OnUpdateRequested</callback>
<callback>OnIncidentUpdateRequested</callback>
<priority>0</priority>
</listener>
<listener id="OnComputeValues">
<listener id="OnIncidentComputeValues">
<event>EVENT_SERVICE_DB_COMPUTE_VALUES</event>
<callback>OnComputeValues</callback>
<callback>OnIncidentComputeValues</callback>
<priority>0</priority>
</listener>
<listener id="OnCheckToWrite">
<listener id="OnIncidentCheckToWrite">
<event>EVENT_SERVICE_DB_CHECK_TO_WRITE</event>
<callback>OnCheckToWrite</callback>
<callback>OnIncidentCheckToWrite</callback>
<priority>0</priority>
</listener>
</event_listeners>
@@ -1144,11 +1144,11 @@
return true;
}]]></code>
</method>
<method id="OnCheckToWrite">
<method id="OnIncidentCheckToWrite">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[public function OnCheckToWrite(Combodo\iTop\Service\EventData $oEventData)
<type>Overload-ExNihilo</type>
<code><![CDATA[public function OnIncidentCheckToWrite(Combodo\iTop\Service\EventData $oEventData)
{
if (!$this->IsNew() && ($this->Get('parent_incident_id') == $this->GetKey()))
{
@@ -1198,11 +1198,11 @@
return $iPriority;
}]]></code>
</method>
<method id="OnComputeValues">
<method id="OnIncidentComputeValues">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[ public function OnComputeValues(Combodo\iTop\Service\EventData $oEventData)
<type>Overload-ExNihilo</type>
<code><![CDATA[ public function OnIncidentComputeValues(Combodo\iTop\Service\EventData $oEventData)
{
// Compute the priority of the ticket
@@ -1484,11 +1484,11 @@
$this->UpdateImpactedItems();
}]]></code>
</method>
<method id="OnInsertRequested">
<method id="OnIncidentInsertRequested">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[ public function OnInsertRequested(Combodo\iTop\Service\EventData $oEventData)
<type>Overload-ExNihilo</type>
<code><![CDATA[ public function OnIncidentInsertRequested(Combodo\iTop\Service\EventData $oEventData)
{
$this->ComputeImpactedItems();
@@ -1496,11 +1496,11 @@
$this->SetIfNull('start_date', time());
}]]></code>
</method>
<method id="OnUpdateRequested">
<method id="OnIncidentUpdateRequested">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[ public function OnUpdateRequested(Combodo\iTop\Service\EventData $oEventData)
<type>Overload-ExNihilo</type>
<code><![CDATA[ public function OnIncidentUpdateRequested(Combodo\iTop\Service\EventData $oEventData)
{
$aChanges = $this->ListChanges();
if (array_key_exists('functionalcis_list', $aChanges))

View File

@@ -424,19 +424,19 @@
</states>
</lifecycle>
<event_listeners>
<listener id="OnInsertRequested">
<listener id="OnProblemInsertRequested">
<event>EVENT_SERVICE_DB_INSERT_REQUESTED</event>
<callback>OnInsertRequested</callback>
<callback>OnProblemInsertRequested</callback>
<priority>0</priority>
</listener>
<listener id="OnUpdateRequested">
<listener id="OnProblemUpdateRequested">
<event>EVENT_SERVICE_DB_UPDATE_REQUESTED</event>
<callback>OnUpdateRequested</callback>
<callback>OnProblemUpdateRequested</callback>
<priority>0</priority>
</listener>
<listener id="OnComputeValues">
<listener id="OnProblemComputeValues">
<event>EVENT_SERVICE_DB_COMPUTE_VALUES</event>
<callback>OnComputeValues</callback>
<callback>OnProblemComputeValues</callback>
<priority>0</priority>
</listener>
</event_listeners>
@@ -537,31 +537,31 @@
return $iPriority;
}]]></code>
</method>
<method id="OnComputeValues">
<method id="OnProblemComputeValues">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[ public function OnComputeValues(Combodo\iTop\Service\EventData $oEventData)
<type>Overload-ExNihilo</type>
<code><![CDATA[ public function OnProblemComputeValues(Combodo\iTop\Service\EventData $oEventData)
{
// Compute the priority of the ticket
$this->Set('priority', $this->ComputePriority());
}]]></code>
</method>
<method id="OnInsertRequested">
<method id="OnProblemInsertRequested">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[ public function OnInsertRequested(Combodo\iTop\Service\EventData $oEventData)
<type>Overload-ExNihilo</type>
<code><![CDATA[ public function OnProblemInsertRequested(Combodo\iTop\Service\EventData $oEventData)
{
$this->SetIfNull('start_date', time());
$this->SetIfNull('last_update', time());
}]]></code>
</method>
<method id="OnUpdateRequested">
<method id="OnProblemUpdateRequested">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[ public function OnUpdateRequested(Combodo\iTop\Service\EventData $oEventData)
<type>Overload-ExNihilo</type>
<code><![CDATA[ public function OnProblemUpdateRequested(Combodo\iTop\Service\EventData $oEventData)
{
$this->Set('last_update', time());
}]]></code>

View File

@@ -1199,24 +1199,24 @@
</states>
</lifecycle>
<event_listeners>
<listener id="OnInsertRequested">
<listener id="OnUserRequestInsertRequested">
<event>EVENT_SERVICE_DB_INSERT_REQUESTED</event>
<callback>OnInsertRequested</callback>
<callback>OnUserRequestInsertRequested</callback>
<priority>0</priority>
</listener>
<listener id="OnUpdateRequested">
<listener id="OnUserRequestUpdateRequested">
<event>EVENT_SERVICE_DB_UPDATE_REQUESTED</event>
<callback>OnUpdateRequested</callback>
<callback>OnUserRequestUpdateRequested</callback>
<priority>0</priority>
</listener>
<listener id="OnComputeValues">
<listener id="OnUserRequestComputeValues">
<event>EVENT_SERVICE_DB_COMPUTE_VALUES</event>
<callback>OnComputeValues</callback>
<callback>OnUserRequestComputeValues</callback>
<priority>0</priority>
</listener>
<listener id="OnCheckToWrite">
<listener id="OnUserRequestCheckToWrite">
<event>EVENT_SERVICE_DB_CHECK_TO_WRITE</event>
<callback>OnCheckToWrite</callback>
<callback>OnUserRequestCheckToWrite</callback>
<priority>0</priority>
</listener>
</event_listeners>
@@ -1304,11 +1304,11 @@
return true;
}]]></code>
</method>
<method id="OnCheckToWrite">
<method id="OnUserRequestCheckToWrite">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[public function OnCheckToWrite(Combodo\iTop\Service\EventData $oEventData)
<type>Overload-ExNihilo</type>
<code><![CDATA[public function OnUserRequestCheckToWrite(Combodo\iTop\Service\EventData $oEventData)
{
if (!$this->IsNew() && ($this->Get('parent_request_id') == $this->GetKey()))
{
@@ -1358,11 +1358,11 @@
return $iPriority;
}]]></code>
</method>
<method id="OnComputeValues">
<method id="OnUserRequestComputeValues">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[ public function OnComputeValues(Combodo\iTop\Service\EventData $oEventData)
<type>Overload-ExNihilo</type>
<code><![CDATA[ public function OnUserRequestComputeValues(Combodo\iTop\Service\EventData $oEventData)
{
// Compute the priority of the ticket
$this->Set('priority', $this->ComputePriority());
@@ -1555,24 +1555,24 @@
$this->UpdateImpactedItems();
}]]></code>
</method>
<method id="OnInsertRequested">
<method id="OnUserRequestInsertRequested">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<type>Overload-ExNihilo</type>
<code><![CDATA[
public function OnInsertRequested(Combodo\iTop\Service\EventData $oEventData)
public function OnUserRequestInsertRequested(Combodo\iTop\Service\EventData $oEventData)
{
$this->ComputeImpactedItems();
$this->SetIfNull('last_update', time());
$this->SetIfNull('start_date', time());
}]]></code>
</method>
<method id="OnUpdateRequested">
<method id="OnUserRequestUpdateRequested">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<type>Overload-ExNihilo</type>
<code><![CDATA[
public function OnUpdateRequested(Combodo\iTop\Service\EventData $oEventData)
public function OnUserRequestUpdateRequested(Combodo\iTop\Service\EventData $oEventData)
{
$aChanges = $this->ListChanges();
if (array_key_exists('functionalcis_list', $aChanges))

View File

@@ -1232,24 +1232,24 @@
</states>
</lifecycle>
<event_listeners>
<listener id="OnInsertRequested">
<listener id="OnUserRequestInsertRequested">
<event>EVENT_SERVICE_DB_INSERT_REQUESTED</event>
<callback>OnInsertRequested</callback>
<callback>OnUserRequestInsertRequested</callback>
<priority>0</priority>
</listener>
<listener id="OnUpdateRequested">
<listener id="OnUserRequestUpdateRequested">
<event>EVENT_SERVICE_DB_UPDATE_REQUESTED</event>
<callback>OnUpdateRequested</callback>
<callback>OnUserRequestUpdateRequested</callback>
<priority>0</priority>
</listener>
<listener id="OnComputeValues">
<listener id="OnUserRequestComputeValues">
<event>EVENT_SERVICE_DB_COMPUTE_VALUES</event>
<callback>OnComputeValues</callback>
<callback>OnUserRequestComputeValues</callback>
<priority>0</priority>
</listener>
<listener id="OnCheckToWrite">
<listener id="OnUserRequestCheckToWrite">
<event>EVENT_SERVICE_DB_CHECK_TO_WRITE</event>
<callback>OnCheckToWrite</callback>
<callback>OnUserRequestCheckToWrite</callback>
<priority>0</priority>
</listener>
</event_listeners>
@@ -1337,11 +1337,11 @@
return true;
}]]></code>
</method>
<method id="OnCheckToWrite">
<method id="OnUserRequestCheckToWrite">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[public function OnCheckToWrite(Combodo\iTop\Service\EventData $oEventData)
<type>Overload-ExNihilo</type>
<code><![CDATA[public function OnUserRequestCheckToWrite(Combodo\iTop\Service\EventData $oEventData)
{
if (!$this->IsNew() && ($this->Get('parent_request_id') == $this->GetKey()))
{
@@ -1392,11 +1392,11 @@
return $iPriority;
}]]></code>
</method>
<method id="OnComputeValues">
<method id="OnUserRequestComputeValues">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[ public function OnComputeValues(Combodo\iTop\Service\EventData $oEventData)
<type>Overload-ExNihilo</type>
<code><![CDATA[ public function OnUserRequestComputeValues(Combodo\iTop\Service\EventData $oEventData)
{
// Compute the priority of the ticket
$this->Set('priority', $this->ComputePriority());
@@ -1601,12 +1601,12 @@
$this->UpdateImpactedItems();
}]]></code>
</method>
<method id="OnInsertRequested">
<method id="OnUserRequestInsertRequested">
<static>false</static>
<access>public</access>
<type>Internal</type>
<type>Overload-ExNihilo</type>
<code><![CDATA[
public function OnInsertRequested(Combodo\iTop\Service\EventData $oEventData)
public function OnUserRequestInsertRequested(Combodo\iTop\Service\EventData $oEventData)
{
$this->ComputeImpactedItems();
@@ -1614,12 +1614,12 @@
$this->SetIfNull('start_date', time());
}]]></code>
</method>
<method id="OnUpdateRequested">
<method id="OnUserRequestUpdateRequested">
<static>false</static>
<access>public</access>
<type>Internal</type>
<type>Overload-ExNihilo</type>
<code><![CDATA[
public function OnUpdateRequested(Combodo\iTop\Service\EventData $oEventData)
public function OnUserRequestUpdateRequested(Combodo\iTop\Service\EventData $oEventData)
{
$aChanges = $this->ListChanges();
if (array_key_exists('functionalcis_list', $aChanges))

View File

@@ -1588,18 +1588,18 @@ public function PrefillSearchForm(&$aContextParam)
</field>
</fields>
<event_listeners>
<listener id="OnCheckToWrite">
<listener id="OnSLACheckToWrite">
<event>EVENT_SERVICE_DB_CHECK_TO_WRITE</event>
<callback>OnCheckToWrite</callback>
<callback>OnSLACheckToWrite</callback>
<priority>0</priority>
</listener>
</event_listeners>
<methods>
<method id="OnCheckToWrite">
<method id="OnSLACheckToWrite">
<static>false</static>
<access>public</access>
<code><![CDATA[
public function OnCheckToWrite(Combodo\iTop\Service\EventData $oEventData)
public function OnSLACheckToWrite(Combodo\iTop\Service\EventData $oEventData)
{
$aCustomerContracts = $this->Get("customercontracts_list");
foreach ($aCustomerContracts as $sAttCode => $oCustomerContracts)

View File

@@ -214,19 +214,24 @@
<count_max>0</count_max>
</field>
</fields>
<methods>
<method id="DBInsertNoReload">
<event_listeners>
<listener id="OnTicketInsertRequested">
<event>EVENT_SERVICE_DB_INSERT_REQUESTED</event>
<callback>OnTicketInsertRequested</callback>
<priority>-10</priority>
</listener>
</event_listeners>
<methods>
<method id="OnTicketInsertRequested">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<type>Overload-ExNihilo</type>
<code><![CDATA[
public function DBInsertNoReload()
public function OnTicketInsertRequested(Combodo\iTop\Service\EventData $oEventData)
{
$iNextId = ItopCounter::IncClass(get_class($this));
$sRef = $this->MakeTicketRef($iNextId);
$this->SetIfNull('ref', $sRef);
$iKey = parent::DBInsertNoReload();
return $iKey;
}
]]></code>
</method>

View File

@@ -283,22 +283,24 @@ function DisplayEvents(WebPage $oPage, $sClass)
$oTable = DataTableUIBlockFactory::MakeForStaticData(Dict::S('UI:Schema:Events:Defined'), $aColumns, $aRows);
$oPage->AddSubBlock($oTable);
$aClasses = [];
foreach (MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL) as $sChildClass) {
if (MetaModel::IsAbstract($sChildClass)) {
continue;
}
$aClasses[] = $sChildClass;
}
$aSources = [];
foreach ($aClasses as $sChildClass) {
$oObject = MetaModel::NewObject($sChildClass);
$aSources[] = $oObject->GetObjectUniqId();
foreach (MetaModel::EnumParentClasses($sChildClass, ENUM_PARENT_CLASSES_ALL, false) as $sParentClass) {
if (!in_array($sParentClass, $aSources)) {
$aSources[] = $sParentClass;
if (MetaModel::IsAbstract($sClass)) {
foreach (MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL) as $sChildClass) {
if (!MetaModel::IsAbstract($sChildClass)) {
$oObject = MetaModel::NewObject($sChildClass);
$aSources[] = $oObject->GetObjectUniqId();
break;
}
}
foreach (MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL, false) as $sParentClass) {
$aSources[] = $sParentClass;
}
} else {
$oObject = MetaModel::NewObject($sClass);
$aSources[] = $oObject->GetObjectUniqId();
foreach (MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL, false) as $sParentClass) {
$aSources[] = $sParentClass;
}
}
$aListeners = [];
foreach (array_keys($aEvents) as $sEvent) {
@@ -321,9 +323,19 @@ function DisplayEvents(WebPage $oPage, $sClass)
'module' => ['label' => 'Module'],
];
$aRows = [];
$oReflectionClass = new ReflectionClass($sClass);
foreach ($aListeners as $aListener) {
if (is_object($aListener['callback'][0])) {
$sListener = get_class($aListener['callback'][0]).'->'.$aListener['callback'][1].'(Combodo\iTop\Service\EventData $oEventData)';
$sListenerClass = $sClass;
if ($aListener['callback'][0] != $sClass) {
$oListenerReflectionClass = new ReflectionClass(get_class($aListener['callback'][0]));
if (!$oListenerReflectionClass->isSubclassOf($sClass)) {
$sListenerClass = get_class($aListener['callback'][0]);
} elseif (!$oReflectionClass->hasMethod($aListener['callback'][1])) {
continue;
}
}
$sListener = $sListenerClass.'->'.$aListener['callback'][1].'(Combodo\iTop\Service\EventData $oEventData)';
} else {
$sListener = $aListener['callback'][0].'::'.$aListener['callback'][1].'(Combodo\iTop\Service\EventData $oEventData)';
}