fix: [audit logs] monkey fix for the missing fields when coming from a CLI query

pull/101/head
iglocska 2022-05-17 09:06:16 +02:00
parent b90e563aec
commit 8cf325d263
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 12 additions and 2 deletions

View File

@ -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');