diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index e0e61db48920..bb16cdcfc930 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -39,15 +39,15 @@ * Class to combine all the configuration options ownCloud offers */ class AllConfig implements IConfig { - /** @var SystemConfig */ private $systemConfig; /** @var IDBConnection */ private $connection; - /** @var EventDispatcher */ + /** @var EventDispatcher */ private $eventDispatcher; + /** * 3 dimensional array with the following structure: * [ $userId => @@ -306,7 +306,7 @@ public function deleteUserValue($userId, $appName, $key) { $this->eventDispatcher->dispatch('userpreferences.beforeDeleteValue', new GenericEvent(null, $arguments)); - $sql = 'DELETE FROM `*PREFIX*preferences` '. + $sql = 'DELETE FROM `*PREFIX*preferences` '. 'WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'; $this->connection->executeUpdate($sql, [$userId, $appName, $key]); @@ -332,7 +332,7 @@ public function deleteAllUserValues($userId) { $arguments = ['uid' => $userId]; $this->eventDispatcher->dispatch('userpreferences.beforeDeleteUser', new GenericEvent(null, $arguments)); - $sql = 'DELETE FROM `*PREFIX*preferences` '. + $sql = 'DELETE FROM `*PREFIX*preferences` '. 'WHERE `userid` = ?'; $this->connection->executeUpdate($sql, [$userId]); @@ -356,7 +356,7 @@ public function deleteAppFromAllUsers($appName) { $arguments = ['app' => $appName]; $this->eventDispatcher->dispatch('userpreferences.beforeDeleteApp', new GenericEvent(null, $arguments)); - $sql = 'DELETE FROM `*PREFIX*preferences` '. + $sql = 'DELETE FROM `*PREFIX*preferences` '. 'WHERE `appid` = ?'; $this->connection->executeUpdate($sql, [$appName]); @@ -426,10 +426,10 @@ public function getUserValueForUsers($appName, $key, $userIds) { $placeholders = (\sizeof($chunk) === 50) ? $placeholders50 : \implode(',', \array_fill(0, \sizeof($chunk), '?')); - $query = 'SELECT `userid`, `configvalue` ' . - 'FROM `*PREFIX*preferences` ' . - 'WHERE `appid` = ? AND `configkey` = ? ' . - 'AND `userid` IN (' . $placeholders . ')'; + $query = 'SELECT `userid`, `configvalue` ' . + 'FROM `*PREFIX*preferences` ' . + 'WHERE `appid` = ? AND `configkey` = ? ' . + 'AND `userid` IN (' . $placeholders . ')'; $result = $this->connection->executeQuery($query, $queryParams); while ($row = $result->fetch()) { diff --git a/tests/lib/AllConfigTest.php b/tests/lib/AllConfigTest.php index 24757be0f145..2fc0d4ff90ed 100644 --- a/tests/lib/AllConfigTest.php +++ b/tests/lib/AllConfigTest.php @@ -22,6 +22,7 @@ class AllConfigTest extends \Test\TestCase { /** @var \OCP\IDBConnection */ protected $connection; + /** @var EventDispatcher */ protected $eventDispatcher; protected function getConfig($systemConfig = null, $connection = null) { @@ -54,9 +55,9 @@ public function testDeleteUserValue() { $config->deleteUserValue('userDelete', 'appDelete', 'keyDelete'); $result = $this->connection->executeQuery( - 'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences` WHERE `userid` = ?', - ['userDelete'] - )->fetch(); + 'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences` WHERE `userid` = ?', + ['userDelete'] + )->fetch(); $actualCount = $result['count']; $this->assertEquals(0, $actualCount, 'There was one value in the database and after the tests there should be no entry left.'); @@ -66,14 +67,16 @@ public function testSetUserValue() { $selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?'; $config = $this->getConfig(); - $event = new GenericEvent(null, [ - 'uid' => 'userSet', 'key' => 'keySet', 'value' => 'valueSet', - 'app' => 'appSet', 'precondition' => null - ]); - $event2 = new GenericEvent(null, [ - 'uid' => 'userSet', 'key' => 'keySet', 'value' => 'valueSet2', - 'app' => 'appSet', 'precondition' => null - ]); + $event = new GenericEvent(null, + [ + 'uid' => 'userSet', 'key' => 'keySet', 'value' => 'valueSet', + 'app' => 'appSet', 'precondition' => null + ]); + $event2 = new GenericEvent(null, + [ + 'uid' => 'userSet', 'key' => 'keySet', 'value' => 'valueSet2', + 'app' => 'appSet', 'precondition' => null + ]); $event3 = new GenericEvent(null, [ 'uid' => 'userSet', 'key' => 'keySet', 'app' => 'appSet' ]); @@ -88,6 +91,7 @@ public function testSetUserValue() { [$this->equalTo('userpreferences.beforeDeleteValue'), $this->equalTo($event3)], [$this->equalTo('userpreferences.afterDeleteValue'), $this->equalTo($event3)] ); + $config->setUserValue('userSet', 'appSet', 'keySet', 'valueSet'); $result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAll(); @@ -221,7 +225,7 @@ public function testSetUserValueUnchanged() { $connectionMock->expects($this->once()) ->method('executeQuery') ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*preferences` '. - 'WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'), + 'WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'), $this->equalTo(['userSetUnchanged', 'appSetUnchanged', 'keySetUnchanged'])) ->will($this->returnValue($resultMock)); $connectionMock->expects($this->never()) @@ -333,10 +337,10 @@ public function testGetUserValueForUsers() { $value = $config->getUserValueForUsers('appFetch2', 'keyFetch1', ['userFetch1', 'userFetch2', 'userFetch3', 'userFetch5']); $this->assertEquals([ - 'userFetch1' => 'value1', - 'userFetch2' => 'value2', - 'userFetch3' => 3, - 'userFetch5' => 'value5' + 'userFetch1' => 'value1', + 'userFetch2' => 'value2', + 'userFetch3' => 3, + 'userFetch5' => 'value5' ], $value); $value = $config->getUserValueForUsers('appFetch2', 'keyFetch1', @@ -378,6 +382,7 @@ public function testDeleteAllUserValues() { [$this->equalTo('userpreferences.beforeDeleteUser'), $this->equalTo($event)], [$this->equalTo('userpreferences.afterDeleteUser'), $this->equalTo($event)] ); + $config->deleteAllUserValues('userFetch3'); $result = $this->connection->executeQuery( @@ -420,6 +425,7 @@ public function testDeleteAppFromAllUsers() { [$this->equalTo('userpreferences.beforeDeleteApp'), $this->equalTo(new GenericEvent(null, ['app' => 'appFetch2']))], [$this->equalTo('userpreferences.afterDeleteApp'), $this->equalTo(new GenericEvent(null, ['app' => 'appFetch2']))] ); + $config->deleteAppFromAllUsers('appFetch1'); $result = $this->connection->executeQuery(