diff options
author | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2015-08-05 01:00:42 +0300 |
---|---|---|
committer | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2015-08-10 23:54:44 +0300 |
commit | 33c29d3da75447da6a659239e8a2b60c72230588 (patch) | |
tree | 00fc25a66474e67b305f14c8f1d118c4c7a1f504 /apps/files_trashbin | |
parent | 4ef26157880f5cd5d5bd27abe0a6991d7c8a415a (diff) | |
download | nextcloud-server-33c29d3da75447da6a659239e8a2b60c72230588.tar.gz nextcloud-server-33c29d3da75447da6a659239e8a2b60c72230588.zip |
Migrate settings
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r-- | apps/files_trashbin/appinfo/update.php | 21 | ||||
-rw-r--r-- | apps/files_trashbin/lib/expiration.php | 5 | ||||
-rw-r--r-- | apps/files_trashbin/tests/expiration.php | 87 |
3 files changed, 93 insertions, 20 deletions
diff --git a/apps/files_trashbin/appinfo/update.php b/apps/files_trashbin/appinfo/update.php index e1a0cf95576..b77210ae4c0 100644 --- a/apps/files_trashbin/appinfo/update.php +++ b/apps/files_trashbin/appinfo/update.php @@ -20,10 +20,29 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ -$installedVersion=OCP\Config::getAppValue('files_trashbin', 'installed_version'); + +$config = \OC::$server->getConfig(); +$installedVersion = $config->getAppValue('files_trashbin', 'installed_version'); if (version_compare($installedVersion, '0.6', '<')) { //size of the trash bin could be incorrect, remove it for all users to //enforce a recalculation during next usage. \OC_DB::dropTable('files_trashsize'); } + +if (version_compare($installedVersion, '0.6.4', '<')) { + $isExpirationEnabled = $config->getSystemValue('trashbin_auto_expire', true); + $oldObligation = $config->getSystemValue('trashbin_retention_obligation', null); + + $newObligation = 'auto'; + if ($isExpirationEnabled) { + if (!is_null($oldObligation)) { + $newObligation = strval($oldObligation) . ', auto'; + } + } else { + $newObligation = 'disabled'; + } + + $config->setSystemValue('trashbin_retention_obligation', $newObligation); + $config->deleteSystemValue('trashbin_auto_expire'); +} diff --git a/apps/files_trashbin/lib/expiration.php b/apps/files_trashbin/lib/expiration.php index 3b57c067ae7..138540febf8 100644 --- a/apps/files_trashbin/lib/expiration.php +++ b/apps/files_trashbin/lib/expiration.php @@ -24,8 +24,7 @@ namespace OCA\Files_Trashbin; use \OCP\IConfig; use \OCP\AppFramework\Utility\ITimeFactory; -class Expiration -{ +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; @@ -48,7 +47,7 @@ class Expiration public function __construct(IConfig $config,ITimeFactory $timeFactory){ $this->timeFactory = $timeFactory; - $this->retentionObligation = $config->getValue('trashbin_retention_obligation', 'auto'); + $this->retentionObligation = $config->getSystemValue('trashbin_retention_obligation', 'auto'); if ($this->retentionObligation !== 'disabled') { $this->parseRetentionObligation(); diff --git a/apps/files_trashbin/tests/expiration.php b/apps/files_trashbin/tests/expiration.php index 68fd32c911b..7bd51dccddd 100644 --- a/apps/files_trashbin/tests/expiration.php +++ b/apps/files_trashbin/tests/expiration.php @@ -98,11 +98,78 @@ class Expiration_Test extends \PHPUnit_Framework_TestCase { * @param string $expectedResult */ public function testExpiration($retentionObligation, $timeNow, $timestamp, $quotaExceeded, $expectedResult){ + $mockedConfig = $this->getMockedConfig($retentionObligation); + $mockedTimeFactory = $this->getMockedTimeFactory($timeNow); + + $expiration = new Expiration($mockedConfig, $mockedTimeFactory); + $actualResult = $expiration->isExpired($timestamp, $quotaExceeded); + + $this->assertEquals($expectedResult, $actualResult); + } + + + public function configData(){ + return [ + [ 'disabled', null, null, null], + [ 'auto', Expiration::DEFAULT_RETENTION_OBLIGATION, Expiration::NO_OBLIGATION, true ], + [ 'auto,auto', Expiration::DEFAULT_RETENTION_OBLIGATION, Expiration::NO_OBLIGATION, true ], + [ 'auto, auto', Expiration::DEFAULT_RETENTION_OBLIGATION, Expiration::NO_OBLIGATION, true ], + [ 'auto, 3', Expiration::NO_OBLIGATION, 3, true ], + [ '5, auto', 5, Expiration::NO_OBLIGATION, true ], + [ '3, 5', 3, 5, false ], + [ '10, 3', 10, 10, false ], + ]; + } + + + /** + * @dataProvider configData + * + * @param string $configValue + * @param int $expectedMinAge + * @param int $expectedMaxAge + * @param bool $expectedCanPurgeToSaveSpace + */ + public function testParseRetentionObligation($configValue, $expectedMinAge, $expectedMaxAge, $expectedCanPurgeToSaveSpace){ + $mockedConfig = $this->getMockedConfig($configValue); + $mockedTimeFactory = $this->getMockedTimeFactory( + time() + ); + + $expiration = new Expiration($mockedConfig, $mockedTimeFactory); + $this->assertAttributeEquals($expectedMinAge, 'minAge', $expiration); + $this->assertAttributeEquals($expectedMaxAge, 'maxAge', $expiration); + $this->assertAttributeEquals($expectedCanPurgeToSaveSpace, 'canPurgeToSaveSpace', $expiration); + } + + /** + * + * @param int $time + * @return \OCP\AppFramework\Utility\ITimeFactory + */ + private function getMockedTimeFactory($time){ + $mockedTimeFactory = $this->getMockBuilder('\OCP\AppFramework\Utility\ITimeFactory') + ->disableOriginalConstructor() + ->setMethods(['getTime']) + ->getMock() + ; + $mockedTimeFactory->expects($this->any())->method('getTime')->will( + $this->returnValue($time) + ); + + return $mockedTimeFactory; + } + + /** + * + * @param string $returnValue + * @return \OCP\IConfig + */ + private function getMockedConfig($returnValue){ $mockedConfig = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor() ->setMethods( [ - 'getValue', 'setSystemValues', 'setSystemValue', 'getSystemValue', @@ -124,22 +191,10 @@ class Expiration_Test extends \PHPUnit_Framework_TestCase { ) ->getMock() ; - $mockedConfig->expects($this->any())->method('getValue')->will( - $this->returnValue($retentionObligation) + $mockedConfig->expects($this->any())->method('getSystemValue')->will( + $this->returnValue($returnValue) ); - $mockedTimeFactory = $this->getMockBuilder('\OCP\AppFramework\Utility\ITimeFactory') - ->disableOriginalConstructor() - ->setMethods(['getTime']) - ->getMock() - ; - $mockedTimeFactory->expects($this->any())->method('getTime')->will( - $this->returnValue($timeNow) - ); - - $expiration = new Expiration($mockedConfig, $mockedTimeFactory); - $actualResult = $expiration->isExpired($timestamp, $quotaExceeded); - - $this->assertEquals($expectedResult, $actualResult); + return $mockedConfig; } } |