2016-06-08 15:25:44 +02:00
|
|
|
<?php
|
2019-12-03 19:57:53 +01:00
|
|
|
|
2018-03-10 19:40:19 +01:00
|
|
|
declare(strict_types=1);
|
2016-06-08 15:25:44 +02:00
|
|
|
/**
|
2024-05-24 19:43:47 +02:00
|
|
|
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2016-06-08 15:25:44 +02:00
|
|
|
*/
|
2017-07-01 11:28:03 +02:00
|
|
|
namespace OCA\AdminAudit\Actions;
|
2016-06-08 15:25:44 +02:00
|
|
|
|
2022-03-04 14:57:36 +01:00
|
|
|
use OCA\AdminAudit\IAuditLogger;
|
2016-06-08 15:25:44 +02:00
|
|
|
|
|
|
|
class Action {
|
|
|
|
|
2023-05-10 16:10:51 +03:30
|
|
|
public function __construct(
|
|
|
|
private IAuditLogger $logger,
|
|
|
|
) {
|
|
|
|
}
|
2016-06-08 15:25:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Log a single action with a log level of info
|
|
|
|
*
|
|
|
|
* @param string $text
|
|
|
|
* @param array $params
|
|
|
|
* @param array $elements
|
2016-11-24 13:58:03 +01:00
|
|
|
* @param bool $obfuscateParameters
|
2016-06-08 15:25:44 +02:00
|
|
|
*/
|
2018-03-10 19:40:19 +01:00
|
|
|
public function log(string $text,
|
2016-06-08 15:25:44 +02:00
|
|
|
array $params,
|
2016-11-24 13:58:03 +01:00
|
|
|
array $elements,
|
2021-03-05 15:02:35 +01:00
|
|
|
bool $obfuscateParameters = false): void {
|
2016-06-08 15:25:44 +02:00
|
|
|
foreach ($elements as $element) {
|
|
|
|
if (!isset($params[$element])) {
|
2016-11-24 13:58:03 +01:00
|
|
|
if ($obfuscateParameters) {
|
|
|
|
$this->logger->critical(
|
|
|
|
'$params["' . $element . '"] was missing.',
|
|
|
|
['app' => 'admin_audit']
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->logger->critical(
|
2025-02-17 12:12:02 +01:00
|
|
|
'$params["' . $element . '"] was missing. Transferred value: {params}',
|
|
|
|
['app' => 'admin_audit', 'params' => $params]
|
2016-11-24 13:58:03 +01:00
|
|
|
);
|
|
|
|
}
|
2016-06-08 15:25:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$replaceArray = [];
|
|
|
|
foreach ($elements as $element) {
|
|
|
|
if ($params[$element] instanceof \DateTime) {
|
|
|
|
$params[$element] = $params[$element]->format('Y-m-d H:i:s');
|
|
|
|
}
|
|
|
|
$replaceArray[] = $params[$element];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->logger->info(
|
|
|
|
vsprintf(
|
|
|
|
$text,
|
|
|
|
$replaceArray
|
|
|
|
),
|
|
|
|
[
|
|
|
|
'app' => 'admin_audit'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|