Bristol SU Support Package
HasHistory.php
Go to the documentation of this file.
1 <?php
2 
4 
6 use Exception;
8 
9 trait HasHistory
10 {
11 
18 
24  private $eventFields;
25 
31  private $settings;
32 
38  public function setActionInstanceId(int $actionInstanceId): void
39  {
40  $this->actionInstanceId = $actionInstanceId;
41  }
42 
48  public function setEventFields(array $eventFields): void
49  {
50  $this->eventFields = $eventFields;
51  }
52 
58  public function setSettings(array $settings): void
59  {
60  $this->settings = $settings;
61  }
62 
69  public function saveHistory(ActionResponse $response): void
70  {
71  if ($this->actionInstanceId === null){
72  throw new Exception('The action instance ID must not be null');
73  }
74 
75  ActionHistory::create([
76  'action_instance_id' => $this->actionInstanceId,
77  'event_fields' => ($this->eventFields ?? []),
78  'settings' => ($this->settings ?? []),
79  'success' => $response->getSuccess(),
80  'message' => $response->getMessage()
81  ]);
82  }
83 
84 }
saveHistory(ActionResponse $response)
Definition: HasHistory.php:69
setActionInstanceId(int $actionInstanceId)
Definition: HasHistory.php:38