Move background job to DI

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2021-03-05 14:57:07 +01:00
parent 5ec2323f25
commit f5dc657e94
1 changed files with 10 additions and 5 deletions

View File

@ -25,26 +25,31 @@
namespace OCA\AdminAudit\BackgroundJobs;
use OC\BackgroundJob\TimedJob;
use OCP\IConfig;
use OCP\Log\RotationTrait;
class Rotate extends TimedJob {
use RotationTrait;
public function __construct() {
/** @var IConfig */
private $config;
public function __construct(IConfig $config) {
$this->config = $config;
$this->setInterval(60 * 60 * 3);
}
protected function run($argument) {
$config = \OC::$server->getConfig();
$default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
$this->filePath = $config->getAppValue('admin_audit', 'logfile', $default);
$default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
$this->filePath = $this->config->getAppValue('admin_audit', 'logfile', $default);
if ($this->filePath === '') {
// default log file, nothing to do
return;
}
$this->maxSize = $config->getSystemValue('log_rotate_size', 100 * 1024 * 1024);
$this->maxSize = $this->config->getSystemValue('log_rotate_size', 100 * 1024 * 1024);
if ($this->shouldRotateBySize()) {
$this->rotate();