aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/Expiration.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_trashbin/lib/Expiration.php')
-rw-r--r--apps/files_trashbin/lib/Expiration.php77
1 files changed, 39 insertions, 38 deletions
diff --git a/apps/files_trashbin/lib/Expiration.php b/apps/files_trashbin/lib/Expiration.php
index 03f126fc415..0bbe39a9314 100644
--- a/apps/files_trashbin/lib/Expiration.php
+++ b/apps/files_trashbin/lib/Expiration.php
@@ -1,39 +1,20 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @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-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\Files_Trashbin;
-use \OCP\IConfig;
-use \OCP\AppFramework\Utility\ITimeFactory;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IConfig;
class Expiration {
// how long do we keep files in the trash bin if no other value is defined in the config file (unit: days)
- const DEFAULT_RETENTION_OBLIGATION = 30;
- const NO_OBLIGATION = -1;
-
- /** @var ITimeFactory */
- private $timeFactory;
+ public const DEFAULT_RETENTION_OBLIGATION = 30;
+ public const NO_OBLIGATION = -1;
/** @var string */
private $retentionObligation;
@@ -47,9 +28,15 @@ class Expiration {
/** @var bool */
private $canPurgeToSaveSpace;
- public function __construct(IConfig $config,ITimeFactory $timeFactory){
- $this->timeFactory = $timeFactory;
- $this->retentionObligation = $config->getSystemValue('trashbin_retention_obligation', 'auto');
+ public function __construct(
+ IConfig $config,
+ private ITimeFactory $timeFactory,
+ ) {
+ $this->setRetentionObligation($config->getSystemValue('trashbin_retention_obligation', 'auto'));
+ }
+
+ public function setRetentionObligation(string $obligation) {
+ $this->retentionObligation = $obligation;
if ($this->retentionObligation !== 'disabled') {
$this->parseRetentionObligation();
@@ -60,7 +47,7 @@ class Expiration {
* Is trashbin expiration enabled
* @return bool
*/
- public function isEnabled(){
+ public function isEnabled() {
return $this->retentionObligation !== 'disabled';
}
@@ -70,7 +57,7 @@ class Expiration {
* @param bool $quotaExceeded
* @return bool
*/
- public function isExpired($timestamp, $quotaExceeded = false){
+ public function isExpired($timestamp, $quotaExceeded = false) {
// No expiration if disabled
if (!$this->isEnabled()) {
return false;
@@ -84,7 +71,7 @@ class Expiration {
$time = $this->timeFactory->getTime();
// Never expire dates in future e.g. misconfiguration or negative time
// adjustment
- if ($time<$timestamp) {
+ if ($time < $timestamp) {
return false;
}
@@ -108,6 +95,20 @@ 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;
+ }
+
+ /**
* @return bool|int
*/
public function getMaxAgeAsTimestamp() {
@@ -119,7 +120,7 @@ class Expiration {
return $maxAge;
}
- private function parseRetentionObligation(){
+ private function parseRetentionObligation() {
$splitValues = explode(',', $this->retentionObligation);
if (!isset($splitValues[0])) {
$minValue = self::DEFAULT_RETENTION_OBLIGATION;
@@ -142,13 +143,13 @@ class Expiration {
$this->canPurgeToSaveSpace = true;
} elseif ($minValue !== 'auto' && $maxValue === 'auto') {
// Keep for X days but delete anytime if space needed
- $this->minAge = intval($minValue);
+ $this->minAge = (int)$minValue;
$this->maxAge = self::NO_OBLIGATION;
$this->canPurgeToSaveSpace = true;
} elseif ($minValue === 'auto' && $maxValue !== 'auto') {
// Delete anytime if space needed, Delete all older than max automatically
$this->minAge = self::NO_OBLIGATION;
- $this->maxAge = intval($maxValue);
+ $this->maxAge = (int)$maxValue;
$this->canPurgeToSaveSpace = true;
} elseif ($minValue !== 'auto' && $maxValue !== 'auto') {
// Delete all older than max OR older than min if space needed
@@ -158,8 +159,8 @@ class Expiration {
$maxValue = $minValue;
}
- $this->minAge = intval($minValue);
- $this->maxAge = intval($maxValue);
+ $this->minAge = (int)$minValue;
+ $this->maxAge = (int)$maxValue;
$this->canPurgeToSaveSpace = false;
}
}