chg: [worflow-trigger:sighting_after_save] Change name to after-save and make it misp_core_format compatible

pull/9370/head
Sami Mokaddem 2023-10-25 15:32:39 +02:00
parent ceb43a345c
commit 4215c0f149
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 46 additions and 24 deletions

View File

@ -79,7 +79,7 @@ class Sighting extends AppModel
{
$pubToZmq = $this->pubToZmq('sighting');
$kafkaTopic = $this->kafkaTopic('sighting');
$isTriggerCallable = $this->isTriggerCallable('sighting-publish');
$isTriggerCallable = $this->isTriggerCallable('sighting-after-save');
if ($pubToZmq || $kafkaTopic || $isTriggerCallable) {
$sighting = $this->getSighting($this->id);
if ($pubToZmq) {
@ -95,11 +95,11 @@ class Sighting extends AppModel
$workflowErrors = [];
$logging = [
'model' => 'Sighting',
'action' => $action,
'action' => $created ? 'add' : 'edit',
'id' => $sighting['Sighting']['id'],
];
$triggerData = $sighting;
$this->executeTrigger('sighting-publish', $triggerData, $workflowErrors, $logging);
$this->executeTrigger('sighting-after-save', $triggerData, $workflowErrors, $logging);
}
}
return true;

View File

@ -0,0 +1,43 @@
<?php
include_once APP . 'Model/WorkflowModules/WorkflowBaseModule.php';
class Module_sighting_after_save extends WorkflowBaseTriggerModule
{
public $id = 'sighting-after-save';
public $scope = 'sighting';
public $name = 'Sighting After Save';
public $description = 'This trigger is called when a sighting has been saved';
public $icon = 'eye';
public $inputs = 0;
public $outputs = 1;
public $blocking = false;
public $misp_core_format = true;
public $trigger_overhead = self::OVERHEAD_MEDIUM;
public function __construct()
{
parent::__construct();
$this->trigger_overhead_message = __('This trigger is called each time a Sighting has been saved. This means that when a large quantity of Sightings are being saved (e.g. Feed pulling or synchronisation), the workflow will be run for as many time as there are Sightings.');
}
public function normalizeData(array $data)
{
$this->Event = ClassRegistry::init('Event');
$this->Attribute = ClassRegistry::init('Attribute');
// We are missing data such as tags or objects.
$event = $this->Event->quickFetchEvent($data['Sighting']['Event']['id']);
$attribute = $this->Attribute->fetchAttribute($data['Sighting']['Attribute']['id']);
if (!empty($attribute['Object'])) {
$event['Event']['Object'] = [$attribute['Object']];
$event['Event']['Object'][0]['Attribute'] = [$attribute['Attribute']];
} else {
$event['Event']['Attribute'] = [$attribute['Attribute']];
}
$event = parent::normalizeData($event);
return $event;
}
}

View File

@ -1,21 +0,0 @@
<?php
include_once APP . 'Model/WorkflowModules/WorkflowBaseModule.php';
class Module_sighting_publish extends WorkflowBaseTriggerModule
{
public $id = 'sighting-publish';
public $scope = 'sighting';
public $name = 'Sighting Publish';
public $description = 'This trigger is called when a sighting has been published';
public $icon = 'eye';
public $inputs = 0;
public $outputs = 1;
public $blocking = false;
public $misp_core_format = false;
public $trigger_overhead = self::OVERHEAD_HIGH;
public function __construct()
{
parent::__construct();
}
}