From 8cf325d263fb3715529a8c5978e4c7d2cb5f8e08 Mon Sep 17 00:00:00 2001 From: iglocska Date: Tue, 17 May 2022 09:06:16 +0200 Subject: [PATCH] fix: [audit logs] monkey fix for the missing fields when coming from a CLI query --- src/Model/Table/AuditLogsTable.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Model/Table/AuditLogsTable.php b/src/Model/Table/AuditLogsTable.php index e6f6f95..acfef9f 100644 --- a/src/Model/Table/AuditLogsTable.php +++ b/src/Model/Table/AuditLogsTable.php @@ -58,7 +58,12 @@ class AuditLogsTable extends AppTable $data['request_ip'] = '127.0.0.1'; } } - foreach (['user_id', 'request_type', 'authkey_id'] as $field) { + $defaults = [ + 'user_id' => 0, + 'request_type' => 'CLI', + 'authkey_id' => 0 + ]; + foreach (array_keys($defaults) as $field) { if (!isset($data[$field])) { if (!isset($userInfo)) { $userInfo = $this->userInfo(); @@ -92,6 +97,11 @@ class AuditLogsTable extends AppTable } $data['changed'] = $changed; } + foreach ($defaults as $field => $default_value) { + if (!isset($data[$field])) { + $data[$field] = $default_value; + } + } } public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options) @@ -157,7 +167,7 @@ class AuditLogsTable extends AppTable if ($this->user !== null) { return $this->user; } - + $this->user = ['id' => 0, /*'org_id' => 0, */'authkey_id' => 0, 'request_type' => self::REQUEST_TYPE_DEFAULT, 'name' => '']; $isShell = (php_sapi_name() === 'cli');