Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Sync code for 'add events for user preference changes' 31266 and 31307 #34820

Merged
merged 1 commit into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down Expand Up @@ -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]);

Expand All @@ -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]);

Expand All @@ -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]);

Expand Down Expand Up @@ -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()) {
Expand Down
38 changes: 22 additions & 16 deletions tests/lib/AllConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.');
Expand All @@ -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'
]);
Expand All @@ -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();
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down