[Pkg-owncloud-commits] [owncloud] 46/70: also appconfig shall not write to database if the value is unchanged

David Prévot taffit at moszumanska.debian.org
Mon Jul 14 17:38:07 UTC 2014


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

taffit pushed a commit to branch master
in repository owncloud.

commit 03c13021db9de73b5bb496056ba3ff82289f5e8d
Author: Arthur Schiwon <blizzz at owncloud.com>
Date:   Tue Jul 8 12:30:38 2014 +0200

    also appconfig shall not write to database if the value is unchanged
---
 lib/private/appconfig.php |  4 +++
 tests/lib/appconfig.php   | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)

diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php
index f20c4a0..1874d9f 100644
--- a/lib/private/appconfig.php
+++ b/lib/private/appconfig.php
@@ -183,6 +183,10 @@ class AppConfig implements \OCP\IAppConfig {
 			);
 			$this->conn->insert('*PREFIX*appconfig', $data);
 		} else {
+			$oldValue = $this->getValue($app, $key);
+			if($oldValue === strval($value)) {
+				return true;
+			}
 			$data = array(
 				'configvalue' => $value,
 			);
diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php
index 6ae790a..9257ae4 100644
--- a/tests/lib/appconfig.php
+++ b/tests/lib/appconfig.php
@@ -95,6 +95,72 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase {
 		$this->assertEquals('somevalue', $value['configvalue']);
 	}
 
+	public function testSetValueUnchanged() {
+		$statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false);
+		$statementMock->expects($this->once())
+			->method('fetch')
+			->will($this->returnValue(false));
+
+		$connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+		$connectionMock->expects($this->once())
+			->method('executeQuery')
+			->with($this->equalTo('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`'
+				.' WHERE `appid` = ?'), $this->equalTo(array('bar')))
+			->will($this->returnValue($statementMock));
+		$connectionMock->expects($this->once())
+			->method('insert')
+			->with($this->equalTo('*PREFIX*appconfig'),
+				$this->equalTo(
+					array(
+						'appid' => 'bar',
+						'configkey' => 'foo',
+						'configvalue' => 'v1',
+					)
+				));
+		$connectionMock->expects($this->never())
+			->method('update');
+
+		$appconfig = new OC\AppConfig($connectionMock);
+		$appconfig->setValue('bar', 'foo', 'v1');
+		$appconfig->setValue('bar', 'foo', 'v1');
+		$appconfig->setValue('bar', 'foo', 'v1');
+	}
+
+	public function testSetValueUnchanged2() {
+		$statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false);
+		$statementMock->expects($this->once())
+			->method('fetch')
+			->will($this->returnValue(false));
+
+		$connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+		$connectionMock->expects($this->once())
+			->method('executeQuery')
+			->with($this->equalTo('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`'
+				.' WHERE `appid` = ?'), $this->equalTo(array('bar')))
+			->will($this->returnValue($statementMock));
+		$connectionMock->expects($this->once())
+			->method('insert')
+			->with($this->equalTo('*PREFIX*appconfig'),
+				$this->equalTo(
+					array(
+						'appid' => 'bar',
+						'configkey' => 'foo',
+						'configvalue' => 'v1',
+					)
+				));
+		$connectionMock->expects($this->once())
+			->method('update')
+			->with($this->equalTo('*PREFIX*appconfig'),
+				$this->equalTo(array('configvalue' => 'v2')),
+				$this->equalTo(array('appid' => 'bar', 'configkey' => 'foo'))
+				);
+
+		$appconfig = new OC\AppConfig($connectionMock);
+		$appconfig->setValue('bar', 'foo', 'v1');
+		$appconfig->setValue('bar', 'foo', 'v2');
+		$appconfig->setValue('bar', 'foo', 'v2');
+	}
+
 	public function testDeleteKey() {
 		\OC_Appconfig::deleteKey('testapp', 'deletethis');
 		$query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');

-- 
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