Lines
75.00%
18 / 24
Functions and Methods
75.00%
3 / 4
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| EventLog | 75.00% | 18 / 24 | 75.00% | 3 / 4 | 14.25 | 0.00% | 0 / 1 | |||
| getDefaults | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 1 | |||||
| addData | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 5 | |||||
| jsonSerialize | 0.00% | 0 / 6 | 0.00% | 0 / 1 | 30 | |||||
| setSecondsToLive | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 5 | **/ | |
| 6 | ||
| 7 | declare(strict_types=1); | |
| 8 | ||
| 9 | namespace BO\Zmsentities; | |
| 10 | ||
| 11 | use BO\Zmsentities\Helper\DateTime; | |
| 12 | use 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 | */ | |
| 25 | class EventLog extends Schema\Entity | |
| 26 | { | |
| 27 | public const string PRIMARY = 'id'; | |
| 28 | ||
| 29 | public static $schema = "eventlog.json"; | |
| 30 | ||
| 31 | public const int LIVETIME_LONGER = 315360000; // 10 years | |
| 32 | public const int LIVETIME_LONG = 94608000; // 3 years | |
| 33 | public const int LIVETIME_YEAR = 31536000; // one year (365 days) | |
| 34 | public const int LIVETIME_DEFAULT = 15552000; // half a year (180 days) | |
| 35 | public const int LIVETIME_MONTH = 2592000; // one month (30 days) | |
| 36 | public const int LIVETIME_WEEK = 604800; // one week | |
| 37 | public const int LIVETIME_DAY = 86400; // one day | |
| 38 | public const int LIVETIME_HOUR = 3600; // one hour | |
| 39 | ||
| 40 | /*************** Event Names ****************/ | |
| 41 | public const string CLIENT_PROCESSLIST_REQUEST = 'CLIENT_PROCESSLIST_REQUEST'; | |
| 42 | public const string CLIENT_PROCESSLIST_SEND = 'CLIENT_PROCESSLIST_REQUEST'; | |
| 43 | // examples for future use below | |
| 44 | public const string QUEUE_PROCESS_SCHEDULE = 'CLIENT_PROCESSLIST_REQUEST'; | |
| 45 | public const string QUEUE_PROCESS_DELETE = 'CLIENT_PROCESSLIST_REQUEST'; | |
| 46 | public const string WORKSTATION_PROCESS_CALL = 'CLIENT_PROCESSLIST_REQUEST'; | |
| 47 | public const string WORKSTATION_PROCESS_START = 'CLIENT_PROCESSLIST_REQUEST'; | |
| 48 | public const string 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(mixed $mergeData): static | |
| 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 | parent::addData($mergeData); | |
| 80 | return $this; | |
| 81 | } | |
| 82 | ||
| 83 | #[\Override] | |
| 84 | public function jsonSerialize(): mixed | |
| 85 | { | |
| 86 | $clone = clone $this; | |
| 87 | if (isset($clone['creationDateTime']) && $clone['creationDateTime'] instanceof DateTimeInterface) { | |
| 88 | $clone['creationDateTime'] = $clone['creationDateTime']->format(DATE_ATOM); | |
| 89 | } | |
| 90 | if (isset($clone['expirationDateTime']) && $clone['expirationDateTime'] instanceof DateTimeInterface) { | |
| 91 | $clone['expirationDateTime'] = $clone['expirationDateTime']->format(DATE_ATOM); | |
| 92 | } | |
| 93 | ||
| 94 | return $clone->jsonSerialize(); | |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * sets the expiration time by adding the desired seconds to live to the current time | |
| 99 | * | |
| 100 | * @param int $secondsToLive | |
| 101 | * @return void | |
| 102 | */ | |
| 103 | public function setSecondsToLive(int $secondsToLive): void | |
| 104 | { | |
| 105 | $this['expirationDateTime'] = new DateTime('+' . $secondsToLive . ' seconds'); | |
| 106 | } | |
| 107 | } |