[Pkg-owncloud-commits] [owncloud] 124/131: only update database on the first run (first run = we have a version number from the old encryption app)

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 15:58:45 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag v8.1.1
in repository owncloud.

commit a79a15e6c56a41229d450249e4aae6ec1e180c12
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Thu Jul 30 15:43:15 2015 +0200

    only update database on the first run (first run = we have a version number from the old encryption app)
---
 apps/encryption/lib/migration.php           | 26 +++++++++++++++++++-------
 apps/encryption/tests/lib/MigrationTest.php |  3 +++
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/apps/encryption/lib/migration.php b/apps/encryption/lib/migration.php
index e6887e8..ba4791f 100644
--- a/apps/encryption/lib/migration.php
+++ b/apps/encryption/lib/migration.php
@@ -37,9 +37,10 @@ class Migration {
 	private $connection;
 	/** @var IConfig */
 	private $config;
-
 	/** @var  ILogger */
 	private $logger;
+	/** @var string*/
+	protected $installedVersion;
 
 	/**
 	 * @param IConfig $config
@@ -54,6 +55,7 @@ class Migration {
 		$this->moduleId = \OCA\Encryption\Crypto\Encryption::ID;
 		$this->config = $config;
 		$this->logger = $logger;
+		$this->installedVersion = $this->config->getAppValue('files_encryption', 'installed_version', '-1');
 	}
 
 	public function finalCleanUp() {
@@ -66,12 +68,16 @@ class Migration {
 	 * update file cache, copy unencrypted_size to the 'size' column
 	 */
 	private function updateFileCache() {
-		$query = $this->connection->createQueryBuilder();
-		$query->update('`*PREFIX*filecache`')
-			->set('`size`', '`unencrypted_size`')
-			->where($query->expr()->eq('`encrypted`', ':encrypted'))
-			->setParameter('encrypted', 1);
-		$query->execute();
+		// make sure that we don't update the file cache multiple times
+		// only update during the first run
+		if ($this->installedVersion !== '-1') {
+			$query = $this->connection->createQueryBuilder();
+			$query->update('`*PREFIX*filecache`')
+				->set('`size`', '`unencrypted_size`')
+				->where($query->expr()->eq('`encrypted`', ':encrypted'))
+				->setParameter('encrypted', 1);
+			$query->execute();
+		}
 	}
 
 	/**
@@ -144,6 +150,12 @@ class Migration {
 	 */
 	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
 		$this->config->deleteAppValue('files_encryption', 'ocsid');
 		$this->config->deleteAppValue('files_encryption', 'types');
diff --git a/apps/encryption/tests/lib/MigrationTest.php b/apps/encryption/tests/lib/MigrationTest.php
index 6742de5..607a973 100644
--- a/apps/encryption/tests/lib/MigrationTest.php
+++ b/apps/encryption/tests/lib/MigrationTest.php
@@ -306,6 +306,7 @@ class MigrationTest extends \Test\TestCase {
 		$this->prepareDB();
 
 		$m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger);
+		$this->invokePrivate($m, 'installedVersion', ['0.7']);
 		$m->updateDB();
 
 		$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');
 
 		$m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger);
+		$this->invokePrivate($m, 'installedVersion', ['0.7']);
 		$m->updateDB();
 
 		$this->verifyDB('`*PREFIX*appconfig`', 'files_encryption', 0);
@@ -388,6 +390,7 @@ class MigrationTest extends \Test\TestCase {
 	public function testUpdateFileCache() {
 		$this->prepareFileCache();
 		$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');
 
 		// check results

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list