Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
73.91% covered (warning)
73.91%
17 / 23
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
EventLog
73.91% covered (warning)
73.91%
17 / 23
75.00% covered (warning)
75.00%
3 / 4
14.56
0.00% covered (danger)
0.00%
0 / 1
 getDefaults
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 addData
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
5
 jsonSerialize
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
30
 setSecondsToLive
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
5 **/
6
7declare(strict_types=1);
8
9namespace BO\Zmsentities;
10
11use BO\Zmsentities\Helper\DateTime;
12use DateTimeInterface;
13
14/**
15 * @property int id
16 * @property string name
17 * @property string origin
18 * @property string referenceType
19 * @property string|null reference
20 * @property string|null sessionid
21 * @property array context
22 * @property DateTimeInterface creationDateTime
23 * @property DateTimeInterface expirationDateTime
24 */
25class EventLog extends Schema\Entity
26{
27    public const PRIMARY = 'id';
28
29    public static $schema = "eventlog.json";
30
31    public const LIVETIME_LONGER  = 315360000; // 10 years
32    public const LIVETIME_LONG    = 94608000; // 3 years
33    public const LIVETIME_YEAR    = 31536000; // one year (365 days)
34    public const LIVETIME_DEFAULT = 15552000; // half a year (180 days)
35    public const LIVETIME_MONTH   = 2592000; // one month (30 days)
36    public const LIVETIME_WEEK    = 604800; // one week
37    public const LIVETIME_DAY     = 86400; // one day
38    public const LIVETIME_HOUR    = 3600; // one hour
39
40    /***************  Event Names ****************/
41    public const CLIENT_PROCESSLIST_REQUEST = 'CLIENT_PROCESSLIST_REQUEST';
42    public const CLIENT_PROCESSLIST_SEND = 'CLIENT_PROCESSLIST_REQUEST';
43    // examples for future use below
44    public const QUEUE_PROCESS_SCHEDULE = 'CLIENT_PROCESSLIST_REQUEST';
45    public const QUEUE_PROCESS_DELETE = 'CLIENT_PROCESSLIST_REQUEST';
46    public const WORKSTATION_PROCESS_CALL = 'CLIENT_PROCESSLIST_REQUEST';
47    public const WORKSTATION_PROCESS_START = 'CLIENT_PROCESSLIST_REQUEST';
48    public const WORKSTATION_PROCESS_FINISH = 'CLIENT_PROCESSLIST_REQUEST';
49
50    #[\Override]
51    public function getDefaults(): array
52    {
53        return [
54            'id' => 0,
55            'name' => '',
56            'origin' => '',
57            'referenceType' => 'none',
58            'reference' => null,
59            'sessionid' => null,
60            'context' => [],
61            'creationDateTime' => new DateTime(),
62            'expirationDateTime' => new DateTime('9999-12-31 00:00:00'),
63        ];
64    }
65
66    /**
67     * {@inheritDoc}
68     */
69    #[\Override]
70    public function addData($mergeData): Schema\Entity
71    {
72        if (isset($mergeData['creationDateTime']) && is_string($mergeData['creationDateTime'])) {
73            $mergeData['creationDateTime'] = new DateTime($mergeData['creationDateTime']);
74        }
75        if (isset($mergeData['expirationDateTime']) && is_string($mergeData['expirationDateTime'])) {
76            $mergeData['expirationDateTime'] = new DateTime($mergeData['expirationDateTime']);
77        }
78
79        return parent::addData($mergeData);
80    }
81
82    #[\Override]
83    public function jsonSerialize(): mixed
84    {
85        $clone = clone $this;
86        if (isset($clone['creationDateTime']) && $clone['creationDateTime'] instanceof DateTimeInterface) {
87            $clone['creationDateTime'] = $clone['creationDateTime']->format(DATE_ATOM);
88        }
89        if (isset($clone['expirationDateTime']) && $clone['expirationDateTime'] instanceof DateTimeInterface) {
90            $clone['expirationDateTime'] = $clone['expirationDateTime']->format(DATE_ATOM);
91        }
92
93        return $clone->jsonSerialize();
94    }
95
96    /**
97     * sets the expiration time by adding the desired seconds to live to the current time
98     *
99     * @param int $secondsToLive
100     * @return void
101     */
102    public function setSecondsToLive(int $secondsToLive): void
103    {
104        $this['expirationDateTime'] = new DateTime('+' . $secondsToLive . ' seconds');
105    }
106}