Merge pull request #7204 from owncloud/groupexists-duplicate
Remove duplicate call to groupExists
This commit is contained in:
commit
41f0ad2d13
|
@ -76,13 +76,8 @@ class Manager extends PublicEmitter {
|
||||||
if (isset($this->cachedGroups[$gid])) {
|
if (isset($this->cachedGroups[$gid])) {
|
||||||
return $this->cachedGroups[$gid];
|
return $this->cachedGroups[$gid];
|
||||||
}
|
}
|
||||||
foreach ($this->backends as $backend) {
|
|
||||||
if ($backend->groupExists($gid)) {
|
|
||||||
return $this->getGroupObject($gid);
|
return $this->getGroupObject($gid);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getGroupObject($gid) {
|
protected function getGroupObject($gid) {
|
||||||
$backends = array();
|
$backends = array();
|
||||||
|
@ -91,6 +86,9 @@ class Manager extends PublicEmitter {
|
||||||
$backends[] = $backend;
|
$backends[] = $backend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (count($backends) === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
$this->cachedGroups[$gid] = new Group($gid, $backends, $this->userManager, $this);
|
$this->cachedGroups[$gid] = new Group($gid, $backends, $this->userManager, $this);
|
||||||
return $this->cachedGroups[$gid];
|
return $this->cachedGroups[$gid];
|
||||||
}
|
}
|
||||||
|
@ -110,8 +108,8 @@ class Manager extends PublicEmitter {
|
||||||
public function createGroup($gid) {
|
public function createGroup($gid) {
|
||||||
if (!$gid) {
|
if (!$gid) {
|
||||||
return false;
|
return false;
|
||||||
} else if ($this->groupExists($gid)) {
|
} else if ($group = $this->get($gid)) {
|
||||||
return $this->get($gid);
|
return $group;
|
||||||
} else {
|
} else {
|
||||||
$this->emit('\OC\Group', 'preCreate', array($gid));
|
$this->emit('\OC\Group', 'preCreate', array($gid));
|
||||||
foreach ($this->backends as $backend) {
|
foreach ($this->backends as $backend) {
|
||||||
|
|
|
@ -116,16 +116,22 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend
|
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend
|
||||||
*/
|
*/
|
||||||
|
$backendGroupCreated = false;
|
||||||
$backend = $this->getMock('\OC_Group_Database');
|
$backend = $this->getMock('\OC_Group_Database');
|
||||||
$backend->expects($this->any())
|
$backend->expects($this->any())
|
||||||
->method('groupExists')
|
->method('groupExists')
|
||||||
->with('group1')
|
->with('group1')
|
||||||
->will($this->returnValue(false));
|
->will($this->returnCallback(function () use (&$backendGroupCreated) {
|
||||||
|
return $backendGroupCreated;
|
||||||
|
}));
|
||||||
$backend->expects($this->once())
|
$backend->expects($this->once())
|
||||||
->method('implementsActions')
|
->method('implementsActions')
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
$backend->expects($this->once())
|
$backend->expects($this->once())
|
||||||
->method('createGroup');
|
->method('createGroup')
|
||||||
|
->will($this->returnCallback(function () use (&$backendGroupCreated) {
|
||||||
|
$backendGroupCreated = true;
|
||||||
|
}));;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\User\Manager $userManager
|
* @var \OC\User\Manager $userManager
|
||||||
|
@ -170,6 +176,10 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getGroups')
|
->method('getGroups')
|
||||||
->with('1')
|
->with('1')
|
||||||
->will($this->returnValue(array('group1')));
|
->will($this->returnValue(array('group1')));
|
||||||
|
$backend->expects($this->once())
|
||||||
|
->method('groupExists')
|
||||||
|
->with('group1')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\User\Manager $userManager
|
* @var \OC\User\Manager $userManager
|
||||||
|
@ -193,6 +203,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getGroups')
|
->method('getGroups')
|
||||||
->with('1')
|
->with('1')
|
||||||
->will($this->returnValue(array('group1')));
|
->will($this->returnValue(array('group1')));
|
||||||
|
$backend1->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
|
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
|
||||||
|
@ -202,6 +215,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getGroups')
|
->method('getGroups')
|
||||||
->with('1')
|
->with('1')
|
||||||
->will($this->returnValue(array('group12', 'group1')));
|
->will($this->returnValue(array('group12', 'group1')));
|
||||||
|
$backend2->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\User\Manager $userManager
|
* @var \OC\User\Manager $userManager
|
||||||
|
@ -228,6 +244,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getGroups')
|
->method('getGroups')
|
||||||
->with('1', 2, 1)
|
->with('1', 2, 1)
|
||||||
->will($this->returnValue(array('group1')));
|
->will($this->returnValue(array('group1')));
|
||||||
|
$backend1->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
|
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
|
||||||
|
@ -237,6 +256,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getGroups')
|
->method('getGroups')
|
||||||
->with('1', 1, 0)
|
->with('1', 1, 0)
|
||||||
->will($this->returnValue(array('group12')));
|
->will($this->returnValue(array('group12')));
|
||||||
|
$backend2->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\User\Manager $userManager
|
* @var \OC\User\Manager $userManager
|
||||||
|
@ -263,6 +285,10 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getUserGroups')
|
->method('getUserGroups')
|
||||||
->with('user1')
|
->with('user1')
|
||||||
->will($this->returnValue(array('group1')));
|
->will($this->returnValue(array('group1')));
|
||||||
|
$backend->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->with('group1')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\User\Manager $userManager
|
* @var \OC\User\Manager $userManager
|
||||||
|
@ -286,6 +312,10 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getUserGroups')
|
->method('getUserGroups')
|
||||||
->with('user1')
|
->with('user1')
|
||||||
->will($this->returnValue(array('group1')));
|
->will($this->returnValue(array('group1')));
|
||||||
|
$backend1->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
|
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
|
||||||
*/
|
*/
|
||||||
|
@ -294,6 +324,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getUserGroups')
|
->method('getUserGroups')
|
||||||
->with('user1')
|
->with('user1')
|
||||||
->will($this->returnValue(array('group1', 'group2')));
|
->will($this->returnValue(array('group1', 'group2')));
|
||||||
|
$backend1->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\User\Manager $userManager
|
* @var \OC\User\Manager $userManager
|
||||||
|
|
Loading…
Reference in New Issue