Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions apps/admin_audit/lib/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, scalar|null|\DateTimeInterface> $params
* @param list<string> $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'],
);
}
}
24 changes: 14 additions & 10 deletions apps/admin_audit/lib/Actions/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(),
Expand All @@ -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(
Expand Down
Loading