diff --git a/core/ormdocument.class.inc.php b/core/ormdocument.class.inc.php index 11c010944f..7044d5b6f4 100644 --- a/core/ormdocument.class.inc.php +++ b/core/ormdocument.class.inc.php @@ -281,6 +281,32 @@ class ormDocument $oDocument->IncreaseDownloadsCount(); $oObj->Set($sAttCode, $oDocument); $oObj->DBUpdate(); + + // Activate any existing trigger + if ($sClass === 'Attachment') + { + $oHostObj = MetaModel::GetObject($oObj->Get('item_class'), $oObj->Get('item_id'), false /* false to avoid exception during trigger */, true); + $sTriggerClass = 'TriggerOnAttachmentDownload'; + $aTriggerContextArgs = array( + 'this->object()' => $oHostObj, + 'attachment->object()' => $oObj, + ); + $aTriggerParams = array('class_list' => MetaModel::EnumParentClasses($oObj->Get('item_class'), ENUM_PARENT_CLASSES_ALL)); + } + else + { + $sTriggerClass = 'TriggerOnDocumentAttributeDownload'; + $aTriggerContextArgs = array( + 'this->object()' => $oObj, + ); + $aTriggerParams = array('class_list' => MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL)); + } + $oTriggerSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT $sTriggerClass AS t WHERE t.target_class IN (:class_list)"), array(), $aTriggerParams); + while ($oTrigger = $oTriggerSet->Fetch()) + { + /** @var \Trigger $oTrigger */ + $oTrigger->DoActivate($aTriggerContextArgs); + } } } } diff --git a/core/trigger.class.inc.php b/core/trigger.class.inc.php index 0860b89cc9..469f0d2e47 100644 --- a/core/trigger.class.inc.php +++ b/core/trigger.class.inc.php @@ -666,6 +666,37 @@ class TriggerOnObjectMention extends TriggerOnObject } } +/** + * Class TriggerOnDocumentAttributeDownload + * + * @since 3.1.0 + */ +class TriggerOnDocumentAttributeDownload extends TriggerOnObject +{ + /** + * @inheritDoc + * @throws \CoreException + * @throws \Exception + */ + 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_ondocattdownload", + "db_key_field" => "id", + "db_finalclass_field" => "", + "display_template" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); + } +} + /** * Class lnkTriggerAction */ diff --git a/datamodels/2.x/itop-attachments/dictionaries/en.dict.itop-attachments.php b/datamodels/2.x/itop-attachments/dictionaries/en.dict.itop-attachments.php index 05949676c2..03424a16fd 100644 --- a/datamodels/2.x/itop-attachments/dictionaries/en.dict.itop-attachments.php +++ b/datamodels/2.x/itop-attachments/dictionaries/en.dict.itop-attachments.php @@ -83,3 +83,12 @@ Dict::Add('EN US', 'English', 'English', array( 'Class:Attachment/Attribute:contact_id' => 'Contact id', 'Class:Attachment/Attribute:contact_id+' => '', )); + +// +// Class: TriggerOnAttachmentDownload +// + +Dict::Add('EN US', 'English', 'English', array( + 'Class:TriggerOnAttachmentDownload' => 'Trigger (on object\'s attachment download)', + 'Class:TriggerOnAttachmentDownload+' => 'Trigger on object\'s attachment download of [a child class of] the given class', +)); diff --git a/datamodels/2.x/itop-attachments/dictionaries/fr.dict.itop-attachments.php b/datamodels/2.x/itop-attachments/dictionaries/fr.dict.itop-attachments.php index dde721987b..6fb604b413 100644 --- a/datamodels/2.x/itop-attachments/dictionaries/fr.dict.itop-attachments.php +++ b/datamodels/2.x/itop-attachments/dictionaries/fr.dict.itop-attachments.php @@ -82,3 +82,12 @@ Dict::Add('FR FR', 'French', 'Français', array( 'Class:Attachment/Attribute:contact_id' => 'Contact', 'Class:Attachment/Attribute:contact_id+' => '', )); + +// +// Class: TriggerOnAttachmentDownload +// + +Dict::Add('FR FR', 'French', 'Français', array( + 'Class:TriggerOnAttachmentDownload' => 'Déclencheur sur le téléchargement d\'une pièce jointe d\'un objet', + 'Class:TriggerOnAttachmentDownload+' => '', +)); diff --git a/datamodels/2.x/itop-attachments/main.itop-attachments.php b/datamodels/2.x/itop-attachments/main.itop-attachments.php index cfabeeac6f..15e699cd79 100644 --- a/datamodels/2.x/itop-attachments/main.itop-attachments.php +++ b/datamodels/2.x/itop-attachments/main.itop-attachments.php @@ -748,6 +748,37 @@ class CMDBChangeOpAttachmentRemoved extends CMDBChangeOp } } +/** + * Class TriggerOnAttachmentDownload + * + * @since 3.1.0 + */ +class TriggerOnAttachmentDownload extends TriggerOnDocumentAttributeDownload +{ + /** + * @inheritDoc + * @throws \CoreException + * @throws \Exception + */ + 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_onattdownload", + "db_key_field" => "id", + "db_finalclass_field" => "", + "display_template" => "", + ); + MetaModel::Init_Params($aParams); + MetaModel::Init_InheritAttributes(); + } +} + class AttachmentsHelper { diff --git a/dictionaries/en.dictionary.itop.core.php b/dictionaries/en.dictionary.itop.core.php index 646ac65d10..b0d3da7695 100644 --- a/dictionaries/en.dictionary.itop.core.php +++ b/dictionaries/en.dictionary.itop.core.php @@ -665,6 +665,17 @@ Dict::Add('EN US', 'English', 'English', array( 'Class:TriggerOnObjectMention/Attribute:mentioned_filter+' => 'Limit the list of mentioned objects which will activate the trigger. If empty, any mentioned object (of any class) will activate it.', )); +// +// Class: TriggerOnAttributeDocumentDownload +// + +Dict::Add('EN US', 'English', 'English', array( + 'Class:TriggerOnAttributeDocumentDownload' => 'Trigger (on object\'s document download)', + 'Class:TriggerOnAttributeDocumentDownload+' => 'Trigger on object\'s document field download of [a child class of] the given class', + 'Class:TriggerOnAttributeDocumentDownload/Attribute:target_attcodes' => 'Target fields', + 'Class:TriggerOnAttributeDocumentDownload/Attribute:target_attcodes+' => '', +)); + // // Class: TriggerOnThresholdReached // diff --git a/dictionaries/fr.dictionary.itop.core.php b/dictionaries/fr.dictionary.itop.core.php index d3e008c0a7..bcc143b205 100644 --- a/dictionaries/fr.dictionary.itop.core.php +++ b/dictionaries/fr.dictionary.itop.core.php @@ -662,6 +662,17 @@ Dict::Add('FR FR', 'French', 'Français', array( 'Class:TriggerOnObjectMention/Attribute:mentioned_filter+' => 'Permet de limiter la liste des objets mentionnés pour lesquels le déclencheur s\'activera. Si vide, n\'importe quel objet mentionné (de n\'importe quelle classe) l\'activera.', )); +// +// Class: TriggerOnAttributeDocumentDownload +// + +Dict::Add('FR FR', 'French', 'Français', array( + 'Class:TriggerOnAttributeDocumentDownload' => 'Déclencheur sur le téléchargement d\'un document d\'un objet', + 'Class:TriggerOnAttributeDocumentDownload+' => '', + 'Class:TriggerOnAttributeDocumentDownload/Attribute:target_attcodes' => 'Attributs cible', + 'Class:TriggerOnAttributeDocumentDownload/Attribute:target_attcodes+' => '', +)); + // // Class: TriggerOnThresholdReached //