new: [workflow-trigger:event-before-save] Added trigger

feature/workflow-trigger-before-save
Sami Mokaddem 2023-10-19 13:44:36 +02:00
parent edd937861a
commit 005609ecd4
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 40 additions and 0 deletions

View File

@ -499,6 +499,24 @@ class Event extends AppModel
$this->data['Event']['uuid'] = CakeText::uuid();
}
$this->__beforeSaveData = $this->data['Event'];
$trigger_id = 'event-before-save';
if ($this->isTriggerCallable($trigger_id)) {
$event = $this->data;
$workflowErrors = [];
$logging = [
'model' => 'Event',
'action' => 'add',
'id' => 0,
'message' => __('The workflow `%s` prevented the saving of event (%s)', $trigger_id, $event['Event']['uuid']),
];
$triggerData = $event;
$workflowSuccess = $this->executeTrigger($trigger_id, $triggerData, $workflowErrors, $logging);
if (!$workflowSuccess) {
return false;
}
}
return true;
}

View File

@ -0,0 +1,22 @@
<?php
include_once APP . 'Model/WorkflowModules/WorkflowBaseModule.php';
class Module_event_before_save extends WorkflowBaseTriggerModule
{
public $id = 'event-before-save';
public $scope = 'event';
public $name = 'Event Before Save';
public $description = 'This trigger is called before an Event or any of its elements is about to be saved in the database';
public $icon = 'envelope';
public $inputs = 0;
public $outputs = 1;
public $blocking = true;
public $misp_core_format = true;
public $trigger_overhead = self::OVERHEAD_HIGH;
public function __construct()
{
parent::__construct();
$this->trigger_overhead_message = __('This trigger is called each time an Event or Attribute is about to be saved. This means that when a large quantity of Attributes are being saved (e.g. Feed pulling or synchronisation), the workflow will be run for as many time as there are Attributes.');
}
}