N°2889 - Adapt triggers to the new event system

This commit is contained in:
Molkobain
2022-12-22 10:16:36 +01:00
parent d649d48153
commit 0c8717f1f6
23 changed files with 1319 additions and 56 deletions

View File

@@ -268,7 +268,9 @@ class ormDocument
$aEventData = array(
'debug_info' => $oDocument->GetFileName(),
'object' => $oObj,
'att_code' => $sAttCode,
'document' => $oDocument,
'content_disposition' => $sContentDisposition,
);
EventService::FireEvent(new EventData(EVENT_DOWNLOAD_DOCUMENT, $sClass, $aEventData));
$oPage->TrashUnexpectedOutput();
@@ -281,32 +283,6 @@ 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);
}
}
}
}