2018-04-25 18:42:14 +03:00
|
|
|
<?php
|
2021-03-05 17:02:35 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-04-25 18:42:14 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2018-04-25 18:42:14 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-04-25 18:42:14 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\AdminAudit\BackgroundJobs;
|
|
|
|
|
|
|
|
use OC\BackgroundJob\TimedJob;
|
2021-03-05 16:57:07 +03:00
|
|
|
use OCP\IConfig;
|
2018-04-25 18:42:14 +03:00
|
|
|
use OCP\Log\RotationTrait;
|
|
|
|
|
|
|
|
class Rotate extends TimedJob {
|
|
|
|
use RotationTrait;
|
|
|
|
|
2021-03-05 16:57:07 +03:00
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
public function __construct(IConfig $config) {
|
|
|
|
$this->config = $config;
|
|
|
|
|
2020-10-05 16:12:57 +03:00
|
|
|
$this->setInterval(60 * 60 * 3);
|
2018-04-25 18:42:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function run($argument) {
|
2021-03-05 16:57:07 +03:00
|
|
|
$default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
|
|
|
|
$this->filePath = $this->config->getAppValue('admin_audit', 'logfile', $default);
|
2018-04-25 18:42:14 +03:00
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($this->filePath === '') {
|
2018-04-25 18:42:14 +03:00
|
|
|
// default log file, nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-05 16:57:07 +03:00
|
|
|
$this->maxSize = $this->config->getSystemValue('log_rotate_size', 100 * 1024 * 1024);
|
2018-04-25 18:42:14 +03:00
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($this->shouldRotateBySize()) {
|
2018-04-25 18:42:14 +03:00
|
|
|
$this->rotate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|