Improvements
This commit is contained in:
parent
b95d1e6683
commit
c3e055549e
|
@ -27,7 +27,6 @@ use \OCP\AppFramework\Utility\ITimeFactory;
|
||||||
class Expiration {
|
class Expiration {
|
||||||
|
|
||||||
// how long do we keep files a version if no other value is defined in the config file (unit: days)
|
// how long do we keep files a version if no other value is defined in the config file (unit: days)
|
||||||
const DEFAULT_RETENTION_OBLIGATION = 30;
|
|
||||||
const NO_OBLIGATION = -1;
|
const NO_OBLIGATION = -1;
|
||||||
|
|
||||||
/** @var ITimeFactory */
|
/** @var ITimeFactory */
|
||||||
|
@ -116,22 +115,44 @@ class Expiration {
|
||||||
private function parseRetentionObligation(){
|
private function parseRetentionObligation(){
|
||||||
$splitValues = explode(',', $this->retentionObligation);
|
$splitValues = explode(',', $this->retentionObligation);
|
||||||
if (!isset($splitValues[0])) {
|
if (!isset($splitValues[0])) {
|
||||||
$minValue = self::DEFAULT_RETENTION_OBLIGATION;
|
$minValue = 'auto';
|
||||||
} else {
|
} else {
|
||||||
$minValue = trim($splitValues[0]);
|
$minValue = trim($splitValues[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($splitValues[1]) && $minValue === 'auto') {
|
if (!isset($splitValues[1])) {
|
||||||
$maxValue = 'auto';
|
$maxValue = self::NO_OBLIGATION;
|
||||||
} elseif (!isset($splitValues[1])) {
|
|
||||||
$maxValue = self::DEFAULT_RETENTION_OBLIGATION;
|
|
||||||
} else {
|
} else {
|
||||||
$maxValue = trim($splitValues[1]);
|
$maxValue = trim($splitValues[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$isValid = true;
|
||||||
|
// 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']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$isValid){
|
||||||
|
$minValue = 'auto';
|
||||||
|
$maxValue = 'auto';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($minValue === 'auto' && $maxValue === 'auto') {
|
if ($minValue === 'auto' && $maxValue === 'auto') {
|
||||||
// Default: Keep for 30 days but delete anytime if space needed
|
// Default: Delete anytime if space needed
|
||||||
$this->minAge = self::DEFAULT_RETENTION_OBLIGATION;
|
$this->minAge = self::NO_OBLIGATION;
|
||||||
$this->maxAge = self::NO_OBLIGATION;
|
$this->maxAge = self::NO_OBLIGATION;
|
||||||
$this->canPurgeToSaveSpace = true;
|
$this->canPurgeToSaveSpace = true;
|
||||||
} elseif ($minValue !== 'auto' && $maxValue === 'auto') {
|
} elseif ($minValue !== 'auto' && $maxValue === 'auto') {
|
||||||
|
|
|
@ -480,11 +480,11 @@ class Storage {
|
||||||
* get list of files we want to expire
|
* get list of files we want to expire
|
||||||
* @param array $versions list of versions
|
* @param array $versions list of versions
|
||||||
* @param integer $time
|
* @param integer $time
|
||||||
|
* @param bool $quotaExceeded is versions storage limit reached
|
||||||
* @return array containing the list of to deleted versions and the size of them
|
* @return array containing the list of to deleted versions and the size of them
|
||||||
*/
|
*/
|
||||||
protected static function getExpireList($time, $versions, $quotaExceeded = false) {
|
protected static function getExpireList($time, $versions, $quotaExceeded = false) {
|
||||||
$application = new Application();
|
$expiration = self::getExpiration();
|
||||||
$expiration = $application->getContainer()->query('Expiration');
|
|
||||||
|
|
||||||
if ($expiration->shouldAutoExpire()) {
|
if ($expiration->shouldAutoExpire()) {
|
||||||
list($toDelete, $size) = self::getAutoExpireList($time, $versions);
|
list($toDelete, $size) = self::getAutoExpireList($time, $versions);
|
||||||
|
@ -568,8 +568,7 @@ class Storage {
|
||||||
*/
|
*/
|
||||||
private static function scheduleExpire($uid, $fileName, $versionsSize = null, $neededSpace = 0) {
|
private static function scheduleExpire($uid, $fileName, $versionsSize = null, $neededSpace = 0) {
|
||||||
// let the admin disable auto expire
|
// let the admin disable auto expire
|
||||||
$application = new Application();
|
$expiration = self::getExpiration();
|
||||||
$expiration = $application->getContainer()->query('Expiration');
|
|
||||||
if ($expiration->isEnabled()) {
|
if ($expiration->isEnabled()) {
|
||||||
$command = new Expire($uid, $fileName, $versionsSize, $neededSpace);
|
$command = new Expire($uid, $fileName, $versionsSize, $neededSpace);
|
||||||
\OC::$server->getCommandBus()->push($command);
|
\OC::$server->getCommandBus()->push($command);
|
||||||
|
@ -586,8 +585,7 @@ class Storage {
|
||||||
*/
|
*/
|
||||||
public static function expire($filename, $versionsSize = null, $offset = 0) {
|
public static function expire($filename, $versionsSize = null, $offset = 0) {
|
||||||
$config = \OC::$server->getConfig();
|
$config = \OC::$server->getConfig();
|
||||||
$application = new Application();
|
$expiration = self::getExpiration();
|
||||||
$expiration = $application->getContainer()->query('Expiration');
|
|
||||||
|
|
||||||
if($config->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' && $expiration->isEnabled()) {
|
if($config->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' && $expiration->isEnabled()) {
|
||||||
list($uid, $filename) = self::getUidAndFilename($filename);
|
list($uid, $filename) = self::getUidAndFilename($filename);
|
||||||
|
@ -706,4 +704,13 @@ class Storage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static workaround
|
||||||
|
* @return Expiration
|
||||||
|
*/
|
||||||
|
protected static function getExpiration(){
|
||||||
|
$application = new Application();
|
||||||
|
return $application->getContainer()->query('Expiration');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,13 +111,15 @@ class Expiration_Test extends \PHPUnit_Framework_TestCase {
|
||||||
public function configData(){
|
public function configData(){
|
||||||
return [
|
return [
|
||||||
[ 'disabled', null, null, null],
|
[ 'disabled', null, null, null],
|
||||||
[ 'auto', Expiration::DEFAULT_RETENTION_OBLIGATION, Expiration::NO_OBLIGATION, true ],
|
[ 'auto', Expiration::NO_OBLIGATION, Expiration::NO_OBLIGATION, true ],
|
||||||
[ 'auto,auto', Expiration::DEFAULT_RETENTION_OBLIGATION, Expiration::NO_OBLIGATION, true ],
|
[ 'auto,auto', Expiration::NO_OBLIGATION, Expiration::NO_OBLIGATION, true ],
|
||||||
[ 'auto, auto', Expiration::DEFAULT_RETENTION_OBLIGATION, Expiration::NO_OBLIGATION, true ],
|
[ 'auto, auto', Expiration::NO_OBLIGATION, Expiration::NO_OBLIGATION, true ],
|
||||||
[ 'auto, 3', Expiration::NO_OBLIGATION, 3, true ],
|
[ 'auto, 3', Expiration::NO_OBLIGATION, 3, true ],
|
||||||
[ '5, auto', 5, Expiration::NO_OBLIGATION, true ],
|
[ '5, auto', 5, Expiration::NO_OBLIGATION, true ],
|
||||||
[ '3, 5', 3, 5, false ],
|
[ '3, 5', 3, 5, false ],
|
||||||
[ '10, 3', 10, 10, false ],
|
[ '10, 3', 10, 10, false ],
|
||||||
|
[ 'g,a,r,b,a,g,e', Expiration::NO_OBLIGATION, Expiration::NO_OBLIGATION, true ],
|
||||||
|
[ '-3,8', Expiration::NO_OBLIGATION, Expiration::NO_OBLIGATION, true ]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -451,7 +451,7 @@ $CONFIG = array(
|
||||||
* ``auto`` default setting. keeps versions for 30 days and automatically
|
* ``auto`` default setting. keeps versions for 30 days and automatically
|
||||||
* deletes anytime after that if space is needed (note: files
|
* deletes anytime after that if space is needed (note: files
|
||||||
* may not be deleted if space is not needed).
|
* may not be deleted if space is not needed).
|
||||||
* ``D, auto`` keeps versions for D+ days, delete anytime if space needed
|
* ``D, auto`` keep versions for D+ days, delete anytime if space needed
|
||||||
* (note: files may not be deleted
|
* (note: files may not be deleted
|
||||||
* if space is not needed)
|
* if space is not needed)
|
||||||
* * ``auto, D`` delete all versions that are older than D days automatically,
|
* * ``auto, D`` delete all versions that are older than D days automatically,
|
||||||
|
|
Loading…
Reference in New Issue