Merge pull request #24259 from owncloud/stable9-mount-unique

[stable9] don't get the config for the same mount multiple times
This commit is contained in:
Thomas Müller 2016-04-26 14:35:12 +02:00
commit 1087385cae
2 changed files with 22 additions and 2 deletions

View File

@ -322,10 +322,19 @@ class DBConfigService {
private function getMountsFromQuery(IQueryBuilder $query) {
$result = $query->execute();
$mounts = $result->fetchAll();
$uniqueMounts = [];
foreach ($mounts as $mount) {
$id = $mount['mount_id'];
if (!isset($uniqueMounts[$id])) {
$uniqueMounts[$id] = $mount;
}
}
$uniqueMounts = array_values($uniqueMounts);
$mountIds = array_map(function ($mount) {
return $mount['mount_id'];
}, $mounts);
}, $uniqueMounts);
$mountIds = array_values(array_unique($mountIds));
$applicable = $this->getApplicableForMounts($mountIds);
$config = $this->getConfigForMounts($mountIds);
@ -338,7 +347,7 @@ class DBConfigService {
$mount['config'] = $config;
$mount['options'] = $options;
return $mount;
}, $mounts, $applicable, $config, $options);
}, $uniqueMounts, $applicable, $config, $options);
}
/**

View File

@ -271,4 +271,15 @@ class DBConfigServiceTest extends TestCase {
$mount = $this->dbConfig->getMountById($id2);
$this->assertEquals('bar', $mount['auth_backend']);
}
public function testGetMountsForDuplicateByGroup() {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GROUP, 'group1');
$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GROUP, 'group2');
$mounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, ['group1', 'group2']);
$this->assertCount(1, $mounts);
$this->assertEquals($id1, $mounts[0]['mount_id']);
}
}