Rotate.php 1002 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\AdminAudit\BackgroundJobs;
  8. use OCP\AppFramework\Utility\ITimeFactory;
  9. use OCP\BackgroundJob\TimedJob;
  10. use OCP\IConfig;
  11. use OCP\Log\RotationTrait;
  12. class Rotate extends TimedJob {
  13. use RotationTrait;
  14. public function __construct(
  15. ITimeFactory $time,
  16. private IConfig $config,
  17. ) {
  18. parent::__construct($time);
  19. $this->setInterval(60 * 60 * 3);
  20. }
  21. protected function run($argument): void {
  22. $default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
  23. $this->filePath = $this->config->getAppValue('admin_audit', 'logfile', $default);
  24. if ($this->filePath === '') {
  25. // default log file, nothing to do
  26. return;
  27. }
  28. $this->maxSize = $this->config->getSystemValue('log_rotate_size', 100 * 1024 * 1024);
  29. if ($this->shouldRotateBySize()) {
  30. $this->rotate();
  31. }
  32. }
  33. }