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