aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_versions/lib/Expiration.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_versions/lib/Expiration.php')
-rw-r--r--apps/files_versions/lib/Expiration.php74
1 files changed, 36 insertions, 38 deletions
diff --git a/apps/files_versions/lib/Expiration.php b/apps/files_versions/lib/Expiration.php
index 12f34b07304..1e04d93379f 100644
--- a/apps/files_versions/lib/Expiration.php
+++ b/apps/files_versions/lib/Expiration.php
@@ -1,41 +1,21 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Victor Dubiniuk <dubiniuk@owncloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\Files_Versions;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
+use Psr\Log\LoggerInterface;
class Expiration {
// how long do we keep files a version if no other value is defined in the config file (unit: days)
public const NO_OBLIGATION = -1;
- /** @var ITimeFactory */
- private $timeFactory;
-
/** @var string */
private $retentionObligation;
@@ -48,8 +28,11 @@ class Expiration {
/** @var bool */
private $canPurgeToSaveSpace;
- public function __construct(IConfig $config,ITimeFactory $timeFactory) {
- $this->timeFactory = $timeFactory;
+ public function __construct(
+ IConfig $config,
+ private ITimeFactory $timeFactory,
+ private LoggerInterface $logger,
+ ) {
$this->retentionObligation = $config->getSystemValue('versions_retention_obligation', 'auto');
if ($this->retentionObligation !== 'disabled') {
@@ -61,14 +44,14 @@ class Expiration {
* Is versions expiration enabled
* @return bool
*/
- public function isEnabled() {
+ public function isEnabled(): bool {
return $this->retentionObligation !== 'disabled';
}
/**
* Is default expiration active
*/
- public function shouldAutoExpire() {
+ public function shouldAutoExpire(): bool {
return $this->minAge === self::NO_OBLIGATION
|| $this->maxAge === self::NO_OBLIGATION;
}
@@ -79,7 +62,7 @@ class Expiration {
* @param bool $quotaExceeded
* @return bool
*/
- public function isExpired($timestamp, $quotaExceeded = false) {
+ public function isExpired(int $timestamp, bool $quotaExceeded = false): bool {
// No expiration if disabled
if (!$this->isEnabled()) {
return false;
@@ -117,8 +100,23 @@ class Expiration {
}
/**
+ * Get minimal retention obligation as a timestamp
+ *
+ * @return int|false
+ */
+ public function getMinAgeAsTimestamp() {
+ $minAge = false;
+ if ($this->isEnabled() && $this->minAge !== self::NO_OBLIGATION) {
+ $time = $this->timeFactory->getTime();
+ $minAge = $time - ($this->minAge * 86400);
+ }
+ return $minAge;
+ }
+
+ /**
* Get maximal retention obligation as a timestamp
- * @return int
+ *
+ * @return int|false
*/
public function getMaxAgeAsTimestamp() {
$maxAge = false;
@@ -133,7 +131,7 @@ class Expiration {
* Read versions_retention_obligation, validate it
* and set private members accordingly
*/
- private function parseRetentionObligation() {
+ private function parseRetentionObligation(): void {
$splitValues = explode(',', $this->retentionObligation);
if (!isset($splitValues[0])) {
$minValue = 'auto';
@@ -151,17 +149,17 @@ class Expiration {
// Validate
if (!ctype_digit($minValue) && $minValue !== 'auto') {
$isValid = false;
- \OC::$server->getLogger()->warning(
- $minValue . ' is not a valid value for minimal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
- ['app' => 'files_versions']
+ $this->logger->warning(
+ $minValue . ' is not a valid value for minimal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
+ ['app' => 'files_versions']
);
}
if (!ctype_digit($maxValue) && $maxValue !== 'auto') {
$isValid = false;
- \OC::$server->getLogger()->warning(
- $maxValue . ' is not a valid value for maximal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
- ['app' => 'files_versions']
+ $this->logger->warning(
+ $maxValue . ' is not a valid value for maximal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
+ ['app' => 'files_versions']
);
}