Migrate settings

This commit is contained in:
Victor Dubiniuk 2015-08-05 01:00:42 +03:00
parent 4ef2615788
commit 33c29d3da7
3 changed files with 93 additions and 20 deletions

View file

@ -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');
}

View file

@ -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();

View file

@ -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;
}
}