/** * delete the group * * @return bool */ public function delete() { $result = false; if ($this->emitter) { $this->emitter->emit('\\OC\\Group', 'preDelete', array($this)); } foreach ($this->backends as $backend) { if ($backend->implementsActions(OC_GROUP_BACKEND_DELETE_GROUP)) { $result = true; $backend->deleteGroup($this->gid); } } if ($result and $this->emitter) { $this->emitter->emit('\\OC\\Group', 'postDelete', array($this)); } return $result; }
/** * delete the group * * @return bool */ public function delete() { // Prevent users from deleting group admin if ($this->getGID() === 'admin') { return false; } $result = false; if ($this->emitter) { $this->emitter->emit('\\OC\\Group', 'preDelete', array($this)); } foreach ($this->backends as $backend) { if ($backend->implementsActions(\OC_Group_Backend::DELETE_GROUP)) { $result = true; $backend->deleteGroup($this->gid); } } if ($result and $this->emitter) { $this->emitter->emit('\\OC\\Group', 'postDelete', array($this)); } return $result; }
public function testDeleteHooks() { $hooksCalled = 0; $test = $this; /** * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend */ $backend = $this->getMock('\\Test\\Util\\User\\Dummy'); $backend->expects($this->once())->method('deleteUser'); /** * @param \OC\User\User $user */ $hook = function ($user) use($test, &$hooksCalled) { $hooksCalled++; $test->assertEquals('foo', $user->getUID()); }; $emitter = new PublicEmitter(); $emitter->listen('\\OC\\User', 'preDelete', $hook); $emitter->listen('\\OC\\User', 'postDelete', $hook); $user = new \OC\User\User('foo', $backend, $emitter); $this->assertTrue($user->delete()); $this->assertEquals(2, $hooksCalled); }
/** * @param string $scope * @param string $method * @param Node[] $arguments */ public function emit($scope, $method, $arguments = array()) { $this->emitter->emit($scope, $method, $arguments); }