Move OC_GROUP_BACKEND_* constants to OC_Group_Backend class

This commit is contained in:
Joas Schilling 2014-11-26 12:04:59 +01:00
parent a74822279c
commit 24511c6f00
4 changed files with 33 additions and 11 deletions

View File

@ -23,29 +23,51 @@
/** /**
* error code for functions not provided by the group backend * error code for functions not provided by the group backend
* @deprecated Use \OC_Group_Backend::NOT_IMPLEMENTED instead
*/ */
define('OC_GROUP_BACKEND_NOT_IMPLEMENTED', -501); define('OC_GROUP_BACKEND_NOT_IMPLEMENTED', -501);
/** /**
* actions that user backends can define * actions that user backends can define
*/ */
/** @deprecated Use \OC_Group_Backend::CREATE_GROUP instead */
define('OC_GROUP_BACKEND_CREATE_GROUP', 0x00000001); define('OC_GROUP_BACKEND_CREATE_GROUP', 0x00000001);
/** @deprecated Use \OC_Group_Backend::DELETE_GROUP instead */
define('OC_GROUP_BACKEND_DELETE_GROUP', 0x00000010); define('OC_GROUP_BACKEND_DELETE_GROUP', 0x00000010);
/** @deprecated Use \OC_Group_Backend::ADD_TO_GROUP instead */
define('OC_GROUP_BACKEND_ADD_TO_GROUP', 0x00000100); define('OC_GROUP_BACKEND_ADD_TO_GROUP', 0x00000100);
/** @deprecated Use \OC_Group_Backend::REMOVE_FROM_GOUP instead */
define('OC_GROUP_BACKEND_REMOVE_FROM_GOUP', 0x00001000); define('OC_GROUP_BACKEND_REMOVE_FROM_GOUP', 0x00001000);
/** @deprecated Obsolete */
define('OC_GROUP_BACKEND_GET_DISPLAYNAME', 0x00010000); //OBSOLETE define('OC_GROUP_BACKEND_GET_DISPLAYNAME', 0x00010000); //OBSOLETE
/** @deprecated Use \OC_Group_Backend::COUNT_USERS instead */
define('OC_GROUP_BACKEND_COUNT_USERS', 0x00100000); define('OC_GROUP_BACKEND_COUNT_USERS', 0x00100000);
/** /**
* Abstract base class for user management * Abstract base class for user management
*/ */
abstract class OC_Group_Backend implements OC_Group_Interface { abstract class OC_Group_Backend implements OC_Group_Interface {
/**
* error code for functions not provided by the group backend
*/
const NOT_IMPLEMENTED = -501;
/**
* actions that user backends can define
*/
const CREATE_GROUP = 0x00000001;
const DELETE_GROUP = 0x00000010;
const ADD_TO_GROUP = 0x00000100;
const REMOVE_FROM_GOUP = 0x00001000;
//OBSOLETE const GET_DISPLAYNAME = 0x00010000;
const COUNT_USERS = 0x00100000;
protected $possibleActions = array( protected $possibleActions = array(
OC_GROUP_BACKEND_CREATE_GROUP => 'createGroup', self::CREATE_GROUP => 'createGroup',
OC_GROUP_BACKEND_DELETE_GROUP => 'deleteGroup', self::DELETE_GROUP => 'deleteGroup',
OC_GROUP_BACKEND_ADD_TO_GROUP => 'addToGroup', self::ADD_TO_GROUP => 'addToGroup',
OC_GROUP_BACKEND_REMOVE_FROM_GOUP => 'removeFromGroup', self::REMOVE_FROM_GOUP => 'removeFromGroup',
OC_GROUP_BACKEND_COUNT_USERS => 'countUsersInGroup', self::COUNT_USERS => 'countUsersInGroup',
); );
/** /**

View File

@ -118,7 +118,7 @@ class Group implements IGroup {
$this->emitter->emit('\OC\Group', 'preAddUser', array($this, $user)); $this->emitter->emit('\OC\Group', 'preAddUser', array($this, $user));
} }
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
if ($backend->implementsActions(OC_GROUP_BACKEND_ADD_TO_GROUP)) { if ($backend->implementsActions(\OC_Group_Backend::ADD_TO_GROUP)) {
$backend->addToGroup($user->getUID(), $this->gid); $backend->addToGroup($user->getUID(), $this->gid);
if ($this->users) { if ($this->users) {
$this->users[$user->getUID()] = $user; $this->users[$user->getUID()] = $user;
@ -142,7 +142,7 @@ class Group implements IGroup {
$this->emitter->emit('\OC\Group', 'preRemoveUser', array($this, $user)); $this->emitter->emit('\OC\Group', 'preRemoveUser', array($this, $user));
} }
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
if ($backend->implementsActions(OC_GROUP_BACKEND_REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) { if ($backend->implementsActions(\OC_Group_Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) {
$backend->removeFromGroup($user->getUID(), $this->gid); $backend->removeFromGroup($user->getUID(), $this->gid);
$result = true; $result = true;
} }
@ -191,7 +191,7 @@ class Group implements IGroup {
public function count($search = '') { public function count($search = '') {
$users = false; $users = false;
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
if($backend->implementsActions(OC_GROUP_BACKEND_COUNT_USERS)) { if($backend->implementsActions(\OC_Group_Backend::COUNT_USERS)) {
if($users === false) { if($users === false) {
//we could directly add to a bool variable, but this would //we could directly add to a bool variable, but this would
//be ugly //be ugly
@ -234,7 +234,7 @@ class Group implements IGroup {
$this->emitter->emit('\OC\Group', 'preDelete', array($this)); $this->emitter->emit('\OC\Group', 'preDelete', array($this));
} }
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
if ($backend->implementsActions(OC_GROUP_BACKEND_DELETE_GROUP)) { if ($backend->implementsActions(\OC_Group_Backend::DELETE_GROUP)) {
$result = true; $result = true;
$backend->deleteGroup($this->gid); $backend->deleteGroup($this->gid);
} }

View File

@ -28,7 +28,7 @@ interface OC_Group_Interface {
* @return boolean * @return boolean
* *
* Returns the supported actions as int to be * Returns the supported actions as int to be
* compared with OC_GROUP_BACKEND_CREATE_GROUP etc. * compared with \OC_Group_Backend::CREATE_GROUP etc.
*/ */
public function implementsActions($actions); public function implementsActions($actions);

View File

@ -134,7 +134,7 @@ class Manager extends PublicEmitter implements IGroupManager {
} 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) {
if ($backend->implementsActions(OC_GROUP_BACKEND_CREATE_GROUP)) { if ($backend->implementsActions(\OC_Group_Backend::CREATE_GROUP)) {
$backend->createGroup($gid); $backend->createGroup($gid);
$group = $this->getGroupObject($gid); $group = $this->getGroupObject($gid);
$this->emit('\OC\Group', 'postCreate', array($group)); $this->emit('\OC\Group', 'postCreate', array($group));