diff --git a/apps/admin_audit/lib/Actions/Action.php b/apps/admin_audit/lib/Actions/Action.php index d44b9ca179b05..29988b44c5441 100644 --- a/apps/admin_audit/lib/Actions/Action.php +++ b/apps/admin_audit/lib/Actions/Action.php @@ -21,47 +21,43 @@ public function __construct( * Log a single action with a log level of info * * @param string $text - * @param array $params - * @param array $elements + * @param array $params + * @param list $elements * @param bool $obfuscateParameters */ - public function log(string $text, + public function log( + string $text, array $params, array $elements, - bool $obfuscateParameters = false): void { + bool $obfuscateParameters = false, + ): void { foreach ($elements as $element) { - if (!isset($params[$element])) { - if ($obfuscateParameters) { - $this->logger->critical( - '$params["' . $element . '"] was missing.', - ['app' => 'admin_audit'] - ); - } else { - $this->logger->critical( - '$params["' . $element . '"] was missing. Transferred value: {params}', - ['app' => 'admin_audit', 'params' => $params] - ); + if (!array_key_exists($element, $params)) { + $message = '$params["' . $element . '"] was missing.'; + $context = ['app' => 'admin_audit']; + + if (!$obfuscateParameters) { + $message .= ' Transferred value: {params}'; + $context['params'] = $params; } + + $this->logger->critical($message, $context); return; } } $replaceArray = []; foreach ($elements as $element) { - if ($params[$element] instanceof \DateTime) { - $params[$element] = $params[$element]->format('Y-m-d H:i:s'); + $value = $params[$element]; + if ($value instanceof \DateTimeInterface) { + $value = $value->format('Y-m-d H:i:s'); } - $replaceArray[] = $params[$element]; + $replaceArray[] = $value; } $this->logger->info( - vsprintf( - $text, - $replaceArray - ), - [ - 'app' => 'admin_audit' - ] + vsprintf($text, $replaceArray), + ['app' => 'admin_audit'], ); } } diff --git a/apps/admin_audit/lib/Actions/Files.php b/apps/admin_audit/lib/Actions/Files.php index 4ba96b8d70ab4..71048345f8f76 100644 --- a/apps/admin_audit/lib/Actions/Files.php +++ b/apps/admin_audit/lib/Actions/Files.php @@ -33,7 +33,7 @@ public function read(BeforeNodeReadEvent $event): void { try { $node = $event->getNode(); $params = [ - 'id' => $node instanceof NonExistingFile ? null : $node->getId(), + 'id' => $node instanceof NonExistingFile ? 'not-yet-assigned' : $node->getId(), 'path' => $node->getPath(), ]; } catch (InvalidPathException|NotFoundException $e) { @@ -80,9 +80,10 @@ public function afterRename(NodeRenamedEvent $event): void { */ public function create(NodeCreatedEvent $event): void { try { + $node = $event->getNode(); $params = [ - 'id' => $event->getNode()->getId(), - 'path' => $event->getNode()->getPath(), + 'id' => $node->getId(), + 'path' => $node->getPath(), ]; } catch (InvalidPathException|NotFoundException $e) { Server::get(LoggerInterface::class)->error( @@ -105,11 +106,13 @@ public function create(NodeCreatedEvent $event): void { */ public function copy(NodeCopiedEvent $event): void { try { + $source = $event->getSource(); + $target = $event->getTarget(); $params = [ - 'oldid' => $event->getSource()->getId(), - 'newid' => $event->getTarget()->getId(), - 'oldpath' => $event->getSource()->getPath(), - 'newpath' => $event->getTarget()->getPath(), + 'oldid' => $source->getId(), + 'newid' => $target->getId(), + 'oldpath' => $source->getPath(), + 'newpath' => $target->getPath(), ]; } catch (InvalidPathException|NotFoundException $e) { Server::get(LoggerInterface::class)->error( @@ -128,8 +131,8 @@ public function copy(NodeCopiedEvent $event): void { * Logs writing of files */ public function write(NodeWrittenEvent $event): void { - $node = $event->getNode(); try { + $node = $event->getNode(); $params = [ 'id' => $node->getId(), 'path' => $node->getPath(), @@ -156,9 +159,10 @@ public function write(NodeWrittenEvent $event): void { */ public function delete(BeforeNodeDeletedEvent $event): void { try { + $node = $event->getNode(); $params = [ - 'id' => $event->getNode()->getId(), - 'path' => $event->getNode()->getPath(), + 'id' => $node->getId(), + 'path' => $node->getPath(), ]; } catch (InvalidPathException|NotFoundException $e) { Server::get(LoggerInterface::class)->error(