N°2889 - Add triggers on file attributes / attachments downloads

This commit is contained in:
Molkobain
2022-12-21 23:22:34 +01:00
parent 0aa0229170
commit d649d48153
7 changed files with 128 additions and 0 deletions

View File

@@ -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);
}
}
}
}

View File

@@ -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
*/

View File

@@ -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',
));

View File

@@ -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+' => '',
));

View File

@@ -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
{

View File

@@ -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
//

View File

@@ -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
//