diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 09c6be54e..0b3761b10 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -2241,6 +2241,17 @@ abstract class DBObject implements iDisplay if (!MetaModel::DBIsReadOnly()) { $this->OnDelete(); + + // Activate any existing trigger + $sClass = get_class($this); + $sClassList = implode("', '", MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL)); + $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnObjectDelete AS t WHERE t.target_class IN ('$sClassList')")); + while ($oTrigger = $oSet->Fetch()) + { + /** @var \Trigger $oTrigger */ + $oTrigger->DoActivate($this->ToArgs('this')); + } + $this->RecordObjDeletion($this->m_iKey); // May cause a reload for storing history information foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode => $oAttDef) diff --git a/core/trigger.class.inc.php b/core/trigger.class.inc.php index 974e01ee4..93eca6d8e 100644 --- a/core/trigger.class.inc.php +++ b/core/trigger.class.inc.php @@ -402,6 +402,40 @@ class TriggerOnObjectCreate extends TriggerOnObject } } +/** + * Class TriggerOnObjectCreate + */ +class TriggerOnObjectDelete extends TriggerOnObject +{ + /** + * @throws \CoreException + */ + public static function Init() + { + $aParams = array + ( + "category" => "grant_by_profile,core/cmdb,application", + "key_type" => "autoincrement", + "name_attcode" => "description", + "state_attcode" => "", + "reconc_keys" => array('description'), + "db_table" => "priv_trigger_onobjdelete", + "db_key_field" => "id", + "db_finalclass_field" => "", + "display_template" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); + + // Display lists + MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'filter', 'action_list')); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class')); // Attributes to be displayed for a list + // Search criteria + MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class')); // Criteria of the std search form + // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form + } +} + /** * Class TriggerOnObjectCreate */ diff --git a/dictionaries/en.dictionary.itop.core.php b/dictionaries/en.dictionary.itop.core.php index 67b2184d1..0d2cba08d 100644 --- a/dictionaries/en.dictionary.itop.core.php +++ b/dictionaries/en.dictionary.itop.core.php @@ -588,6 +588,15 @@ Dict::Add('EN US', 'English', 'English', array( 'Class:TriggerOnObjectCreate+' => 'Trigger on object creation of [a child class of] the given class', )); +// +// Class: TriggerOnObjectDelete +// + +Dict::Add('EN US', 'English', 'English', array( + 'Class:TriggerOnObjectDelete' => 'Trigger (on object deletion)', + 'Class:TriggerOnObjectDelete+' => 'Trigger on object deletion of [a child class of] the given class', +)); + // // Class: TriggerOnObjectUpdate // diff --git a/dictionaries/fr.dictionary.itop.core.php b/dictionaries/fr.dictionary.itop.core.php index dfd8c0bce..762cd07a9 100644 --- a/dictionaries/fr.dictionary.itop.core.php +++ b/dictionaries/fr.dictionary.itop.core.php @@ -61,6 +61,8 @@ Dict::Add('FR FR', 'French', 'Français', array( 'Class:TriggerOnStateLeave+' => '', 'Class:TriggerOnObjectCreate' => 'Déclencheur sur la création d\'un objet', 'Class:TriggerOnObjectCreate+' => '', + 'Class:TriggerOnObjectDelete' => 'Déclencheur sur la suppression d\'un objet', + 'Class:TriggerOnObjectDelete+' => '', 'Class:TriggerOnObjectUpdate' => 'Déclencheur sur la modification d\'un objet', 'Class:TriggerOnObjectUpdate+' => '', 'Class:TriggerOnObjectUpdate/Attribute:target_attcodes' => 'Attributs cible',