mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-21 00:02:17 +02:00
Event Service
This commit is contained in:
@@ -254,5 +254,237 @@
|
||||
</fields>
|
||||
</class>
|
||||
</classes>
|
||||
<events _delta="define">
|
||||
<event id="ObjectDetails">
|
||||
<description>An object details is about to be displayed to a user</description>
|
||||
<available_filters>Class hierarchy of the displayed object</available_filters>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object displayed</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="BeforeInsert">
|
||||
<description>An object is about to be inserted in the database</description>
|
||||
<replaces>DBObject::OnInsert</replaces>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object inserted</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="DBObjectKeyReady">
|
||||
<description>A key (id) has been generated for an object inserted into the database (use GetKey() to read the new key)</description>
|
||||
<replaces>DBObject::OnObjectKeyReady</replaces>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object inserted</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="AfterInsert">
|
||||
<description>An object has been inserted into the database</description>
|
||||
<replaces>DBObject::AfterInsert</replaces>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object inserted</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="BeforeUpdate">
|
||||
<description>An object is about to be updated in the database</description>
|
||||
<replaces>DBObject::OnUpdate</replaces>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object updated</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="AfterUpdate">
|
||||
<description>An object has been updated into the database</description>
|
||||
<replaces>DBObject::AfterUpdate</replaces>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object updated</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="BeforeDelete">
|
||||
<description>An object is about to be deleted in the database</description>
|
||||
<replaces>DBObject::OnDelete</replaces>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object deleted</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="AfterDelete">
|
||||
<description>An object has been deleted into the database</description>
|
||||
<replaces>DBObject::AfterDelete</replaces>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object deleted</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="BeforeApplyStimulus">
|
||||
<description>A stimulus is about to be applied to an object</description>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object where the stimulus is to be applied</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="AfterApplyStimulus">
|
||||
<description>A stimulus has been applied to an object</description>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object where the stimulus has been applied</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="DBObjectLoaded">
|
||||
<description>An object has been loaded from the database</description>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object loaded</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="DBObjectNew">
|
||||
<description>An object has been created in memory</description>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object created</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="DBObjectReload">
|
||||
<description>An object has been re-loaded from the database</description>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object re-loaded</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="OnCheckToWrite">
|
||||
<description>Check an object before it is written into the database</description>
|
||||
<replaces>cmdbAbstractObject::DoCheckToWrite</replaces>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object to check</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="error_messages">
|
||||
<description>Array of strings where all the errors found during the object checking are added</description>
|
||||
<type>array</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="DoCheckToDelete">
|
||||
<description>Check an object before it is deleted from the database</description>
|
||||
<replaces>cmdbAbstractObject::DoCheckToDelete</replaces>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object to check</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="error_messages">
|
||||
<description>Array of strings where all the errors found during the object checking are added</description>
|
||||
<type>array</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
<event id="DownloadDocument">
|
||||
<description>A document has been downloaded from the GUI</description>
|
||||
<arguments>
|
||||
<argument id="object">
|
||||
<description>The object containing the document</description>
|
||||
<type>DBObject</type>
|
||||
</argument>
|
||||
<argument id="document">
|
||||
<description>The document downloaded</description>
|
||||
<type>ormDocument</type>
|
||||
</argument>
|
||||
<argument id="debug_info">
|
||||
<description>Debug string</description>
|
||||
<type>string</type>
|
||||
</argument>
|
||||
</arguments>
|
||||
</event>
|
||||
</events>
|
||||
</meta>
|
||||
</itop_design>
|
||||
</itop_design>
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
use Combodo\iTop\Service\Event;
|
||||
use Combodo\iTop\Service\EventName;
|
||||
|
||||
/**
|
||||
* All objects to be displayed in the application (either as a list or as details)
|
||||
@@ -153,9 +155,14 @@ abstract class DBObject implements iDisplay
|
||||
protected $m_aSynchroData = null;
|
||||
protected $m_sHighlightCode = null;
|
||||
protected $m_aCallbacks = array();
|
||||
/**
|
||||
* @var string local events suffix
|
||||
*/
|
||||
protected $m_sEventUniqId = '';
|
||||
protected static $m_iEventUniqCounter = 0;
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* DBObject constructor.
|
||||
*
|
||||
* You should preferably use MetaModel::NewObject() instead of this constructor.
|
||||
@@ -179,6 +186,9 @@ abstract class DBObject implements iDisplay
|
||||
$this->m_bFullyLoaded = $this->IsFullyLoaded();
|
||||
$this->m_aTouchedAtt = array();
|
||||
$this->m_aModifiedAtt = array();
|
||||
$this->m_sEventUniqId = 'DataModel_'.self::$m_iEventUniqCounter++;
|
||||
$this->RegisterEvents();
|
||||
$this->FireEvent(EventName::DB_OBJECT_LOADED);
|
||||
return;
|
||||
}
|
||||
// Creation of a brand new object
|
||||
@@ -205,6 +215,14 @@ abstract class DBObject implements iDisplay
|
||||
}
|
||||
|
||||
$this->UpdateMetaAttributes();
|
||||
|
||||
$this->m_sEventUniqId = 'DataModel_'.self::$m_iEventUniqCounter++;
|
||||
$this->RegisterEvents();
|
||||
$this->FireEvent(EventName::DB_OBJECT_NEW);
|
||||
}
|
||||
|
||||
protected function RegisterEvents()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,6 +369,7 @@ abstract class DBObject implements iDisplay
|
||||
public function Reload($bAllowAllData = false)
|
||||
{
|
||||
assert($this->m_bIsInDB);
|
||||
$this->FireEvent(EventName::DB_OBJECT_RELOAD);
|
||||
$aRow = MetaModel::MakeSingleRow(get_class($this), $this->m_iKey, false /* must be found */, true /* AllowAllData */);
|
||||
if (empty($aRow))
|
||||
{
|
||||
@@ -2687,6 +2706,7 @@ abstract class DBObject implements iDisplay
|
||||
// Ensure the update of the values (we are accessing the data directly)
|
||||
$this->DoComputeValues();
|
||||
$this->OnInsert();
|
||||
$this->FireEvent(EventName::BEFORE_INSERT);
|
||||
|
||||
if ($this->m_iKey < 0)
|
||||
{
|
||||
@@ -2759,6 +2779,7 @@ abstract class DBObject implements iDisplay
|
||||
}
|
||||
|
||||
$this->OnObjectKeyReady();
|
||||
$this->FireEvent(EventName::DB_OBJECT_KEY_READY);
|
||||
|
||||
$this->DBWriteLinks();
|
||||
$this->WriteExternalAttributes();
|
||||
@@ -2789,6 +2810,7 @@ abstract class DBObject implements iDisplay
|
||||
}
|
||||
|
||||
$this->AfterInsert();
|
||||
$this->FireEvent(EventName::AFTER_INSERT);
|
||||
|
||||
// Activate any existing trigger
|
||||
$sClass = get_class($this);
|
||||
@@ -3037,6 +3059,8 @@ abstract class DBObject implements iDisplay
|
||||
}
|
||||
}
|
||||
$this->OnUpdate();
|
||||
$this->FireEvent(EventName::BEFORE_UPDATE);
|
||||
|
||||
|
||||
$aChanges = $this->ListChanges();
|
||||
if (count($aChanges) == 0)
|
||||
@@ -3239,6 +3263,7 @@ abstract class DBObject implements iDisplay
|
||||
try
|
||||
{
|
||||
$this->AfterUpdate();
|
||||
$this->FireEvent(EventName::AFTER_UPDATE);
|
||||
|
||||
// Reload to get the external attributes
|
||||
if ($bHasANewExternalKeyValue)
|
||||
@@ -3357,6 +3382,7 @@ abstract class DBObject implements iDisplay
|
||||
}
|
||||
|
||||
$this->OnDelete();
|
||||
$this->FireEvent(EventName::BEFORE_DELETE);
|
||||
|
||||
// Activate any existing trigger
|
||||
$sClass = get_class($this);
|
||||
@@ -3458,6 +3484,8 @@ abstract class DBObject implements iDisplay
|
||||
}
|
||||
|
||||
$this->AfterDelete();
|
||||
$this->FireEvent(EventName::AFTER_DELETE);
|
||||
|
||||
|
||||
$this->m_bIsInDB = false;
|
||||
// Fix for N°926: do NOT reset m_iKey as it can be used to have it for reporting purposes (see the REST service to delete
|
||||
@@ -3643,6 +3671,8 @@ abstract class DBObject implements iDisplay
|
||||
|
||||
$aTransitionDef = $aStateTransitions[$sStimulusCode];
|
||||
|
||||
$this->FireEvent(EventName::BEFORE_APPLY_STIMULUS);
|
||||
|
||||
// Change the state before proceeding to the actions, this is necessary because an action might
|
||||
// trigger another stimuli (alternative: push the stimuli into a queue)
|
||||
$sPreviousState = $this->Get($sStateAttCode);
|
||||
@@ -3754,6 +3784,8 @@ abstract class DBObject implements iDisplay
|
||||
/** @var \Trigger $oTrigger */
|
||||
$oTrigger->DoActivate($this->ToArgs('this'));
|
||||
}
|
||||
|
||||
$this->FireEvent(EventName::AFTER_APPLY_STIMULUS);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -5384,5 +5416,23 @@ abstract class DBObject implements iDisplay
|
||||
}
|
||||
return $oExpression->Evaluate($aArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sEvent
|
||||
* @param array $aEventData
|
||||
*
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function FireEvent($sEvent, $aEventData = array())
|
||||
{
|
||||
$aEventData['debug_info'] = 'from: '.get_class($this).':'.$this->GetKey();
|
||||
$aEventData['object'] = $this;
|
||||
$aEventSources = array($this->m_sEventUniqId);
|
||||
foreach (MetaModel::EnumParentClasses(get_class($this), ENUM_PARENT_CLASSES_ALL, false) as $sClass)
|
||||
{
|
||||
$aEventSources[] = $sClass;
|
||||
}
|
||||
Event::FireEvent($sEvent, $aEventSources, $aEventData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -603,16 +603,24 @@ abstract class LogAPI
|
||||
}
|
||||
|
||||
public static function Log($sLevel, $sMessage, $sChannel = null, $aContext = array())
|
||||
{
|
||||
if (self::CanLog($sLevel, $sChannel))
|
||||
{
|
||||
static::$m_oFileLog->$sLevel($sMessage, $sChannel, $aContext);
|
||||
}
|
||||
}
|
||||
|
||||
public static function CanLog($sLevel, $sChannel = null)
|
||||
{
|
||||
if (! static::$m_oFileLog)
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! isset(self::$aLevelsPriority[$sLevel]))
|
||||
{
|
||||
IssueLog::Error("invalid log level '{$sLevel}'");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null($sChannel))
|
||||
@@ -621,25 +629,21 @@ abstract class LogAPI
|
||||
}
|
||||
|
||||
$sMinLogLevel = self::GetMinLogLevel($sChannel);
|
||||
|
||||
if ($sMinLogLevel === false || $sMinLogLevel === 'false')
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (is_string($sMinLogLevel))
|
||||
if (! isset(self::$aLevelsPriority[$sMinLogLevel]))
|
||||
{
|
||||
if (! isset(self::$aLevelsPriority[$sMinLogLevel]))
|
||||
{
|
||||
throw new Exception("invalid configuration for log_level '{$sMinLogLevel}' is not within the list: ".implode(',', array_keys(self::$aLevelsPriority)));
|
||||
}
|
||||
elseif (self::$aLevelsPriority[$sLevel] < self::$aLevelsPriority[$sMinLogLevel])
|
||||
{
|
||||
//priority too low regarding the conf, do not log this
|
||||
return;
|
||||
}
|
||||
throw new Exception("invalid configuration for log_level '{$sMinLogLevel}' is not within the list: ".implode(',', array_keys(self::$aLevelsPriority)));
|
||||
}
|
||||
elseif (self::$aLevelsPriority[$sLevel] < self::$aLevelsPriority[$sMinLogLevel])
|
||||
{
|
||||
//priority too low regarding the conf, do not log this
|
||||
return false;
|
||||
}
|
||||
|
||||
static::$m_oFileLog->$sLevel($sMessage, $sChannel, $aContext);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -830,4 +834,4 @@ class LogFileRotationProcess implements iScheduledProcess
|
||||
|
||||
throw new ProcessException(self::class.' : The configured filename builder is invalid (log_filename_builder_impl="'.$sLogFileNameBuilder.'")');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\Event;
|
||||
|
||||
|
||||
/**
|
||||
* ormDocument
|
||||
@@ -188,7 +191,6 @@ class ormDocument
|
||||
* @param string $sContentDisposition Either 'inline' or 'attachment'
|
||||
* @param string $sSecretField The attcode of the field containing a "secret" to be provided in order to retrieve the file
|
||||
* @param string $sSecretValue The value of the secret to be compared with the value of the attribute $sSecretField
|
||||
* @return none
|
||||
*/
|
||||
public static function DownloadDocument(WebPage $oPage, $sClass, $id, $sAttCode, $sContentDisposition = 'attachment', $sSecretField = null, $sSecretValue = null)
|
||||
{
|
||||
@@ -207,6 +209,12 @@ class ormDocument
|
||||
$oDocument = $oObj->Get($sAttCode);
|
||||
if (is_object($oDocument))
|
||||
{
|
||||
$aEventData = array(
|
||||
'debug_info' => $oDocument->GetFileName(),
|
||||
'object' => $oObj,
|
||||
'document' => $oDocument,
|
||||
);
|
||||
Event::FireEvent(EventName::DOWNLOAD_DOCUMENT, $sClass, $aEventData);
|
||||
$oPage->TrashUnexpectedOutput();
|
||||
$oPage->SetContentType($oDocument->GetMimeType());
|
||||
$oPage->SetContentDisposition($sContentDisposition,$oDocument->GetFileName());
|
||||
|
||||
Reference in New Issue
Block a user