2018-04-25 17:42:14 +02:00
|
|
|
<?php
|
2021-03-05 15:02:35 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
2018-04-25 17:42:14 +02:00
|
|
|
/**
|
2024-05-24 19:43:47 +02:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-04-25 17:42:14 +02:00
|
|
|
*/
|
|
|
|
namespace OCA\AdminAudit\BackgroundJobs;
|
|
|
|
|
2022-12-05 10:13:34 +01:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
use OCP\BackgroundJob\TimedJob;
|
2021-03-05 14:57:07 +01:00
|
|
|
use OCP\IConfig;
|
2018-04-25 17:42:14 +02:00
|
|
|
use OCP\Log\RotationTrait;
|
|
|
|
|
|
|
|
class Rotate extends TimedJob {
|
|
|
|
use RotationTrait;
|
|
|
|
|
2023-05-10 16:10:51 +03:30
|
|
|
public function __construct(
|
|
|
|
ITimeFactory $time,
|
|
|
|
private IConfig $config,
|
|
|
|
) {
|
2022-12-05 10:13:34 +01:00
|
|
|
parent::__construct($time);
|
|
|
|
|
2020-10-05 15:12:57 +02:00
|
|
|
$this->setInterval(60 * 60 * 3);
|
2018-04-25 17:42:14 +02:00
|
|
|
}
|
|
|
|
|
2022-12-05 10:13:34 +01:00
|
|
|
protected function run($argument): void {
|
2021-03-05 14:57:07 +01:00
|
|
|
$default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
|
|
|
|
$this->filePath = $this->config->getAppValue('admin_audit', 'logfile', $default);
|
2018-04-25 17:42:14 +02:00
|
|
|
|
|
|
|
if ($this->filePath === '') {
|
|
|
|
// default log file, nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-05 14:57:07 +01:00
|
|
|
$this->maxSize = $this->config->getSystemValue('log_rotate_size', 100 * 1024 * 1024);
|
2018-04-25 17:42:14 +02:00
|
|
|
|
|
|
|
if ($this->shouldRotateBySize()) {
|
|
|
|
$this->rotate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|