Skip to content

Commit 5d01ea8

Browse files
joshtrichardsCarlSchwan
authored andcommitted
chore: migrate AuditLogger to IAppConfig
Signed-off-by: Josh <josh.t.richards@gmail.com> Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent 0302d60 commit 5d01ea8

4 files changed

Lines changed: 11 additions & 18 deletions

File tree

apps/admin_audit/lib/AppInfo/Application.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@
5353
use OCP\Group\Events\GroupDeletedEvent;
5454
use OCP\Group\Events\UserAddedEvent;
5555
use OCP\Group\Events\UserRemovedEvent;
56-
use OCP\IConfig;
5756
use OCP\Log\Audit\CriticalActionPerformedEvent;
58-
use OCP\Log\ILogFactory;
5957
use OCP\Preview\BeforePreviewFetchedEvent;
6058
use OCP\Share;
6159
use OCP\Share\Events\ShareCreatedEvent;
@@ -81,9 +79,7 @@ public function __construct() {
8179

8280
#[\Override]
8381
public function register(IRegistrationContext $context): void {
84-
$context->registerService(IAuditLogger::class, function (ContainerInterface $c) {
85-
return new AuditLogger($c->get(ILogFactory::class), $c->get(IConfig::class));
86-
});
82+
$context->registerServiceAlias(IAuditLogger::class, AuditLogger::class);
8783

8884
$context->registerEventListener(CriticalActionPerformedEvent::class, CriticalActionPerformedEventListener::class);
8985

apps/admin_audit/lib/AuditLogger.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace OCA\AdminAudit;
1111

12+
use OCP\AppFramework\Services\IAppConfig;
1213
use OCP\IConfig;
1314
use OCP\Log\ILogFactory;
1415
use Psr\Log\LoggerInterface;
@@ -20,7 +21,11 @@ class AuditLogger implements IAuditLogger {
2021

2122
private LoggerInterface $parentLogger;
2223

23-
public function __construct(ILogFactory $logFactory, IConfig $config) {
24+
public function __construct(
25+
ILogFactory $logFactory,
26+
IAppConfig $appConfig,
27+
IConfig $config,
28+
) {
2429
$auditType = $config->getSystemValueString('log_type_audit', 'file');
2530
$defaultTag = $config->getSystemValueString('syslog_tag', 'Nextcloud');
2631
$auditTag = $config->getSystemValueString('syslog_tag_audit', $defaultTag);
@@ -29,7 +34,7 @@ public function __construct(ILogFactory $logFactory, IConfig $config) {
2934
if ($auditType === 'file' && !$logFile) {
3035
$default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
3136
// Legacy way was appconfig, now it's paralleled with the normal log config
32-
$logFile = $config->getAppValue('admin_audit', 'logfile', $default);
37+
$logFile = $appConfig->getAppValueString('logfile', $default);
3338
}
3439

3540
$this->parentLogger = $logFactory->getCustomPsrLogger($logFile, $auditType, $auditTag);

apps/admin_audit/lib/BackgroundJobs/Rotate.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace OCA\AdminAudit\BackgroundJobs;
1010

11+
use OCP\AppFramework\Services\IAppConfig;
1112
use OCP\AppFramework\Utility\ITimeFactory;
1213
use OCP\BackgroundJob\TimedJob;
1314
use OCP\IConfig;
@@ -18,6 +19,7 @@ class Rotate extends TimedJob {
1819

1920
public function __construct(
2021
ITimeFactory $time,
22+
private IAppConfig $appConfig,
2123
private IConfig $config,
2224
) {
2325
parent::__construct($time);
@@ -28,7 +30,7 @@ public function __construct(
2830
#[\Override]
2931
protected function run($argument): void {
3032
$default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
31-
$this->filePath = $this->config->getAppValue('admin_audit', 'logfile', $default);
33+
$this->filePath = $this->appConfig->getAppValueString('logfile', $default);
3234

3335
if ($this->filePath === '') {
3436
// default log file, nothing to do

build/psalm-baseline.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@
2020
<code><![CDATA[Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed')]]></code>
2121
</DeprecatedMethod>
2222
</file>
23-
<file src="apps/admin_audit/lib/AuditLogger.php">
24-
<DeprecatedMethod>
25-
<code><![CDATA[getAppValue]]></code>
26-
</DeprecatedMethod>
27-
</file>
28-
<file src="apps/admin_audit/lib/BackgroundJobs/Rotate.php">
29-
<DeprecatedMethod>
30-
<code><![CDATA[getAppValue]]></code>
31-
</DeprecatedMethod>
32-
</file>
3323
<file src="apps/cloud_federation_api/lib/Controller/RequestHandlerController.php">
3424
<DeprecatedMethod>
3525
<code><![CDATA[Util::emitHook(

0 commit comments

Comments
 (0)