Merge pull request #17989 from owncloud/enc_only_update_file_cache_once
only update database on the first run
This commit is contained in:
commit
4105d17133
|
@ -37,9 +37,10 @@ class Migration {
|
||||||
private $connection;
|
private $connection;
|
||||||
/** @var IConfig */
|
/** @var IConfig */
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
/** @var ILogger */
|
/** @var ILogger */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
/** @var string*/
|
||||||
|
protected $installedVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IConfig $config
|
* @param IConfig $config
|
||||||
|
@ -54,6 +55,7 @@ class Migration {
|
||||||
$this->moduleId = \OCA\Encryption\Crypto\Encryption::ID;
|
$this->moduleId = \OCA\Encryption\Crypto\Encryption::ID;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
$this->installedVersion = $this->config->getAppValue('files_encryption', 'installed_version', '-1');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function finalCleanUp() {
|
public function finalCleanUp() {
|
||||||
|
@ -66,12 +68,16 @@ class Migration {
|
||||||
* update file cache, copy unencrypted_size to the 'size' column
|
* update file cache, copy unencrypted_size to the 'size' column
|
||||||
*/
|
*/
|
||||||
private function updateFileCache() {
|
private function updateFileCache() {
|
||||||
$query = $this->connection->getQueryBuilder();
|
// make sure that we don't update the file cache multiple times
|
||||||
$query->update('*PREFIX*filecache')
|
// only update during the first run
|
||||||
->set('size', 'unencrypted_size')
|
if ($this->installedVersion !== '-1') {
|
||||||
->where($query->expr()->eq('encrypted', $query->createParameter('encrypted')))
|
$query = $this->connection->getQueryBuilder();
|
||||||
->setParameter('encrypted', 1);
|
$query->update('*PREFIX*filecache')
|
||||||
$query->execute();
|
->set('size', 'unencrypted_size')
|
||||||
|
->where($query->expr()->eq('encrypted', $query->createParameter('encrypted')))
|
||||||
|
->setParameter('encrypted', 1);
|
||||||
|
$query->execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,6 +150,12 @@ class Migration {
|
||||||
*/
|
*/
|
||||||
public function updateDB() {
|
public function updateDB() {
|
||||||
|
|
||||||
|
// make sure that we don't update the file cache multiple times
|
||||||
|
// only update during the first run
|
||||||
|
if ($this->installedVersion === '-1') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// delete left-over from old encryption which is no longer needed
|
// delete left-over from old encryption which is no longer needed
|
||||||
$this->config->deleteAppValue('files_encryption', 'ocsid');
|
$this->config->deleteAppValue('files_encryption', 'ocsid');
|
||||||
$this->config->deleteAppValue('files_encryption', 'types');
|
$this->config->deleteAppValue('files_encryption', 'types');
|
||||||
|
|
|
@ -306,6 +306,7 @@ class MigrationTest extends \Test\TestCase {
|
||||||
$this->prepareDB();
|
$this->prepareDB();
|
||||||
|
|
||||||
$m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger);
|
$m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger);
|
||||||
|
$this->invokePrivate($m, 'installedVersion', ['0.7']);
|
||||||
$m->updateDB();
|
$m->updateDB();
|
||||||
|
|
||||||
$this->verifyDB('*PREFIX*appconfig', 'files_encryption', 0);
|
$this->verifyDB('*PREFIX*appconfig', 'files_encryption', 0);
|
||||||
|
@ -325,6 +326,7 @@ class MigrationTest extends \Test\TestCase {
|
||||||
$config->setUserValue(self::TEST_ENCRYPTION_MIGRATION_USER1, 'encryption', 'recoverKeyEnabled', '9');
|
$config->setUserValue(self::TEST_ENCRYPTION_MIGRATION_USER1, 'encryption', 'recoverKeyEnabled', '9');
|
||||||
|
|
||||||
$m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger);
|
$m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger);
|
||||||
|
$this->invokePrivate($m, 'installedVersion', ['0.7']);
|
||||||
$m->updateDB();
|
$m->updateDB();
|
||||||
|
|
||||||
$this->verifyDB('*PREFIX*appconfig', 'files_encryption', 0);
|
$this->verifyDB('*PREFIX*appconfig', 'files_encryption', 0);
|
||||||
|
@ -388,6 +390,7 @@ class MigrationTest extends \Test\TestCase {
|
||||||
public function testUpdateFileCache() {
|
public function testUpdateFileCache() {
|
||||||
$this->prepareFileCache();
|
$this->prepareFileCache();
|
||||||
$m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger);
|
$m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger);
|
||||||
|
$this->invokePrivate($m, 'installedVersion', ['0.7']);
|
||||||
self::invokePrivate($m, 'updateFileCache');
|
self::invokePrivate($m, 'updateFileCache');
|
||||||
|
|
||||||
// check results
|
// check results
|
||||||
|
|
Loading…
Reference in New Issue