2013-01-08 22:07:12 -06:00
< ? php
/**
*
2014-05-27 20:18:06 +02:00
* This file is part of the phpBB Forum Software package .
*
* @ copyright ( c ) phpBB Limited < https :// www . phpbb . com >
* @ license GNU General Public License , version 2 ( GPL - 2.0 )
*
* For full copyright and license information , please see
* the docs / CREDITS . txt file .
2013-01-08 22:07:12 -06:00
*
*/
2013-09-10 14:01:09 +02:00
namespace phpbb\db\migration\tool ;
2013-01-09 14:27:01 -06:00
/**
* Migration permission management tool
*/
2013-09-10 14:01:09 +02:00
class permission implements \phpbb\db\migration\tool\tool_interface
2013-01-08 22:07:12 -06:00
{
2013-09-10 14:01:09 +02:00
/** @var \phpbb\auth\auth */
2013-01-09 14:27:01 -06:00
protected $auth ;
2013-01-08 22:07:26 -06:00
2013-09-10 14:01:09 +02:00
/** @var \phpbb\cache\service */
2013-01-09 14:27:01 -06:00
protected $cache ;
2013-01-08 22:07:26 -06:00
2014-03-17 13:29:35 +01:00
/** @var \phpbb\db\driver\driver_interface */
2013-01-09 14:27:01 -06:00
protected $db ;
2013-01-08 22:07:26 -06:00
/** @var string */
2013-01-09 14:27:01 -06:00
protected $phpbb_root_path ;
2013-01-08 22:07:26 -06:00
/** @var string */
2013-01-09 14:27:01 -06:00
protected $php_ext ;
2013-01-08 22:07:26 -06:00
2013-01-09 14:27:01 -06:00
/**
* Constructor
*
2014-03-17 13:29:35 +01:00
* @ param \phpbb\db\driver\driver_interface $db
2014-03-13 16:38:10 -07:00
* @ param \phpbb\cache\service $cache
2013-09-10 14:01:09 +02:00
* @ param \phpbb\auth\auth $auth
2013-01-09 14:27:01 -06:00
* @ param string $phpbb_root_path
* @ param string $php_ext
*/
2014-03-17 13:29:35 +01:00
public function __construct ( \phpbb\db\driver\driver_interface $db , \phpbb\cache\service $cache , \phpbb\auth\auth $auth , $phpbb_root_path , $php_ext )
2013-01-08 22:07:26 -06:00
{
$this -> db = $db ;
$this -> cache = $cache ;
$this -> auth = $auth ;
$this -> phpbb_root_path = $phpbb_root_path ;
$this -> php_ext = $php_ext ;
}
2013-01-08 22:09:14 -06:00
/**
* { @ inheritdoc }
*/
public function get_name ()
{
return 'permission' ;
}
2013-01-08 22:07:12 -06:00
/**
* Permission Exists
*
* Check if a permission ( auth ) setting exists
*
* @ param string $auth_option The name of the permission ( auth ) option
2013-02-04 13:46:23 -06:00
* @ param bool $global True for checking a global permission setting ,
* False for a local permission setting
2013-01-08 22:07:12 -06:00
* @ return bool true if it exists , false if not
*/
public function exists ( $auth_option , $global = true )
{
if ( $global )
{
$type_sql = ' AND is_global = 1' ;
}
else
{
$type_sql = ' AND is_local = 1' ;
}
$sql = ' SELECT auth_option_id
FROM ' . ACL_OPTIONS_TABLE . "
WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "' "
. $type_sql ;
$result = $this -> db -> sql_query ( $sql );
$row = $this -> db -> sql_fetchrow ( $result );
$this -> db -> sql_freeresult ( $result );
if ( $row )
{
return true ;
}
return false ;
}
/**
* Permission Add
*
* Add a permission ( auth ) option
*
* @ param string $auth_option The name of the permission ( auth ) option
2013-02-04 13:46:23 -06:00
* @ param bool $global True for checking a global permission setting ,
* False for a local permission setting
2013-01-09 14:27:01 -06:00
* @ return null
2013-01-08 22:07:12 -06:00
*/
2013-01-08 22:09:14 -06:00
public function add ( $auth_option , $global = true , $copy_from = false )
2013-01-08 22:07:12 -06:00
{
if ( $this -> exists ( $auth_option , $global ))
{
2013-03-03 20:25:31 -06:00
return ;
2013-01-08 22:07:12 -06:00
}
// We've added permissions, so set to true to notify the user.
$this -> permissions_added = true ;
if ( ! class_exists ( 'auth_admin' ))
{
2013-01-08 22:07:26 -06:00
include ( $this -> phpbb_root_path . 'includes/acp/auth.' . $this -> php_ext );
2013-01-08 22:07:12 -06:00
}
2013-09-10 14:01:09 +02:00
$auth_admin = new \auth_admin ();
2013-01-08 22:07:12 -06:00
// We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here.
if ( $this -> exists ( $auth_option , ! $global ))
{
$sql_ary = array (
'is_global' => 1 ,
'is_local' => 1 ,
);
$sql = 'UPDATE ' . ACL_OPTIONS_TABLE . '
2013-01-08 22:09:14 -06:00
SET ' . $this->db->sql_build_array(' UPDATE ' , $sql_ary ) . "
WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "' " ;
2013-01-08 22:07:12 -06:00
$this -> db -> sql_query ( $sql );
}
else
{
if ( $global )
{
$auth_admin -> acl_add_option ( array ( 'global' => array ( $auth_option )));
}
else
{
$auth_admin -> acl_add_option ( array ( 'local' => array ( $auth_option )));
}
}
2013-01-08 22:09:14 -06:00
// The permission has been added, now we can copy it if needed
if ( $copy_from && isset ( $auth_admin -> acl_options [ 'id' ][ $copy_from ]))
{
$old_id = $auth_admin -> acl_options [ 'id' ][ $copy_from ];
$new_id = $auth_admin -> acl_options [ 'id' ][ $auth_option ];
$tables = array ( ACL_GROUPS_TABLE , ACL_ROLES_DATA_TABLE , ACL_USERS_TABLE );
foreach ( $tables as $table )
{
$sql = ' SELECT *
FROM ' . $table . '
WHERE auth_option_id = ' . $old_id ;
$result = $this -> db -> sql_query ( $sql );
$sql_ary = array ();
while ( $row = $this -> db -> sql_fetchrow ( $result ))
{
$row [ 'auth_option_id' ] = $new_id ;
$sql_ary [] = $row ;
}
$this -> db -> sql_freeresult ( $result );
2013-01-09 14:27:01 -06:00
if ( ! empty ( $sql_ary ))
2013-01-08 22:09:14 -06:00
{
$this -> db -> sql_multi_insert ( $table , $sql_ary );
}
}
$auth_admin -> acl_clear_prefetch ();
}
2013-01-08 22:07:12 -06:00
}
/**
* Permission Remove
*
* Remove a permission ( auth ) option
*
* @ param string $auth_option The name of the permission ( auth ) option
2013-02-04 13:46:23 -06:00
* @ param bool $global True for checking a global permission setting ,
* False for a local permission setting
2013-01-09 14:27:01 -06:00
* @ return null
2013-01-08 22:07:12 -06:00
*/
public function remove ( $auth_option , $global = true )
{
if ( ! $this -> exists ( $auth_option , $global ))
{
2013-03-03 20:25:31 -06:00
return ;
2013-01-08 22:07:12 -06:00
}
if ( $global )
{
$type_sql = ' AND is_global = 1' ;
}
else
{
$type_sql = ' AND is_local = 1' ;
}
2013-01-08 22:09:14 -06:00
$sql = ' SELECT auth_option_id , is_global , is_local
FROM ' . ACL_OPTIONS_TABLE . "
2013-01-08 22:07:12 -06:00
WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "' " .
$type_sql ;
$result = $this -> db -> sql_query ( $sql );
$row = $this -> db -> sql_fetchrow ( $result );
$this -> db -> sql_freeresult ( $result );
2013-01-09 14:27:01 -06:00
$id = ( int ) $row [ 'auth_option_id' ];
2013-01-08 22:07:12 -06:00
// If it is a local and global permission, do not remove the row! :P
if ( $row [ 'is_global' ] && $row [ 'is_local' ])
{
$sql = 'UPDATE ' . ACL_OPTIONS_TABLE . '
SET ' . (($global) ? ' is_global = 0 ' : ' is_local = 0 ') . '
WHERE auth_option_id = ' . $id ;
$this -> db -> sql_query ( $sql );
}
else
{
// Delete time
2013-01-09 14:27:01 -06:00
$tables = array ( ACL_GROUPS_TABLE , ACL_ROLES_DATA_TABLE , ACL_USERS_TABLE , ACL_OPTIONS_TABLE );
foreach ( $tables as $table )
{
$this -> db -> sql_query ( 'DELETE FROM ' . $table . '
WHERE auth_option_id = ' . $id );
}
2013-01-08 22:07:12 -06:00
}
// Purge the auth cache
$this -> cache -> destroy ( '_acl_options' );
$this -> auth -> acl_clear_prefetch ();
}
/**
2013-09-16 04:45:58 +02:00
* Add a new permission role
2013-01-08 22:07:12 -06:00
*
2013-09-16 05:20:27 +02:00
* @ param string $role_name The new role name
2013-01-08 22:07:12 -06:00
* @ param sting $role_type The type ( u_ , m_ , a_ )
2013-01-09 14:27:01 -06:00
* @ return null
2013-01-08 22:07:12 -06:00
*/
2013-02-04 13:46:23 -06:00
public function role_add ( $role_name , $role_type , $role_description = '' )
2013-01-08 22:07:12 -06:00
{
2013-01-08 22:09:14 -06:00
$sql = ' SELECT role_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_name = '" . $this->db->sql_escape($role_name) . "' " ;
2013-01-08 22:07:12 -06:00
$this -> db -> sql_query ( $sql );
2013-01-09 14:27:01 -06:00
$role_id = ( int ) $this -> db -> sql_fetchfield ( 'role_id' );
2013-01-08 22:07:12 -06:00
if ( $role_id )
{
2013-02-09 20:56:42 -06:00
return ;
2013-01-08 22:07:12 -06:00
}
2013-01-09 14:27:01 -06:00
$sql = ' SELECT MAX ( role_order ) AS max_role_order
2013-01-08 22:09:14 -06:00
FROM ' . ACL_ROLES_TABLE . "
WHERE role_type = '" . $this->db->sql_escape($role_type) . "' " ;
2013-01-08 22:07:12 -06:00
$this -> db -> sql_query ( $sql );
2013-01-09 14:27:01 -06:00
$role_order = ( int ) $this -> db -> sql_fetchfield ( 'max_role_order' );
2013-01-08 22:07:12 -06:00
$role_order = ( ! $role_order ) ? 1 : $role_order + 1 ;
$sql_ary = array (
'role_name' => $role_name ,
'role_description' => $role_description ,
'role_type' => $role_type ,
'role_order' => $role_order ,
);
$sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this -> db -> sql_build_array ( 'INSERT' , $sql_ary );
$this -> db -> sql_query ( $sql );
}
/**
* Update the name on a permission role
*
* @ param string $old_role_name The old role name
2013-09-16 05:20:27 +02:00
* @ param string $new_role_name The new role name
2013-01-09 14:27:01 -06:00
* @ return null
2013-01-08 22:07:12 -06:00
*/
2013-02-04 13:46:23 -06:00
public function role_update ( $old_role_name , $new_role_name )
2013-01-08 22:07:12 -06:00
{
2013-01-08 22:09:14 -06:00
$sql = ' SELECT role_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_name = '" . $this->db->sql_escape($old_role_name) . "' " ;
2013-01-08 22:07:12 -06:00
$this -> db -> sql_query ( $sql );
2013-01-09 14:27:01 -06:00
$role_id = ( int ) $this -> db -> sql_fetchfield ( 'role_id' );
2013-01-08 22:07:12 -06:00
if ( ! $role_id )
{
2013-09-10 14:01:09 +02:00
throw new \phpbb\db\migration\exception ( 'ROLE_NOT_EXIST' , $old_role_name );
2013-01-08 22:07:12 -06:00
}
2013-01-08 22:09:14 -06:00
$sql = 'UPDATE ' . ACL_ROLES_TABLE . "
SET role_name = '" . $this->db->sql_escape($new_role_name) . "'
WHERE role_name = '" . $this->db->sql_escape($old_role_name) . "' " ;
2013-01-08 22:07:12 -06:00
$this -> db -> sql_query ( $sql );
}
/**
* Remove a permission role
*
* @ param string $role_name The role name to remove
2013-01-09 14:27:01 -06:00
* @ return null
2013-01-08 22:07:12 -06:00
*/
public function role_remove ( $role_name )
{
2013-01-08 22:09:14 -06:00
$sql = ' SELECT role_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_name = '" . $this->db->sql_escape($role_name) . "' " ;
2013-01-08 22:07:12 -06:00
$this -> db -> sql_query ( $sql );
2013-01-09 14:27:01 -06:00
$role_id = ( int ) $this -> db -> sql_fetchfield ( 'role_id' );
2013-01-08 22:07:12 -06:00
if ( ! $role_id )
{
2013-03-03 20:25:31 -06:00
return ;
2013-01-08 22:07:12 -06:00
}
$sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '
WHERE role_id = ' . $role_id ;
$this -> db -> sql_query ( $sql );
$sql = 'DELETE FROM ' . ACL_ROLES_TABLE . '
WHERE role_id = ' . $role_id ;
$this -> db -> sql_query ( $sql );
$this -> auth -> acl_clear_prefetch ();
}
/**
* Permission Set
*
* Allows you to set permissions for a certain group / role
*
* @ param string $name The name of the role / group
2013-02-04 13:46:23 -06:00
* @ param string | array $auth_option The auth_option or array of
* auth_options you would like to set
2013-01-08 22:07:12 -06:00
* @ param string $type The type ( role | group )
2013-02-04 13:46:23 -06:00
* @ param bool $has_permission True if you want to give them permission ,
* false if you want to deny them permission
2013-01-09 14:27:01 -06:00
* @ return null
2013-01-08 22:07:12 -06:00
*/
2013-02-04 13:46:23 -06:00
public function permission_set ( $name , $auth_option , $type = 'role' , $has_permission = true )
2013-01-08 22:07:12 -06:00
{
if ( ! is_array ( $auth_option ))
{
$auth_option = array ( $auth_option );
}
$new_auth = array ();
2013-01-08 22:09:14 -06:00
$sql = ' SELECT auth_option_id
FROM ' . ACL_OPTIONS_TABLE . '
2013-01-08 22:07:12 -06:00
WHERE ' . $this->db->sql_in_set(' auth_option ' , $auth_option );
$result = $this -> db -> sql_query ( $sql );
while ( $row = $this -> db -> sql_fetchrow ( $result ))
{
2013-01-09 14:27:01 -06:00
$new_auth [] = ( int ) $row [ 'auth_option_id' ];
2013-01-08 22:07:12 -06:00
}
$this -> db -> sql_freeresult ( $result );
2013-01-09 14:27:01 -06:00
if ( empty ( $new_auth ))
2013-01-08 22:07:12 -06:00
{
2013-01-09 14:27:01 -06:00
return ;
2013-01-08 22:07:12 -06:00
}
$current_auth = array ();
$type = ( string ) $type ; // Prevent PHP bug.
switch ( $type )
{
2013-01-09 15:41:04 -06:00
case 'role' :
2013-01-08 22:09:14 -06:00
$sql = ' SELECT role_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_name = '" . $this->db->sql_escape($name) . "' " ;
2013-01-08 22:07:12 -06:00
$this -> db -> sql_query ( $sql );
2013-01-09 14:27:01 -06:00
$role_id = ( int ) $this -> db -> sql_fetchfield ( 'role_id' );
2013-01-08 22:07:12 -06:00
if ( ! $role_id )
{
2013-09-10 14:01:09 +02:00
throw new \phpbb\db\migration\exception ( 'ROLE_NOT_EXIST' , $name );
2013-01-08 22:07:12 -06:00
}
2013-01-08 22:09:14 -06:00
$sql = ' SELECT auth_option_id , auth_setting
FROM ' . ACL_ROLES_DATA_TABLE . '
2013-01-08 22:07:12 -06:00
WHERE role_id = ' . $role_id ;
$result = $this -> db -> sql_query ( $sql );
while ( $row = $this -> db -> sql_fetchrow ( $result ))
{
$current_auth [ $row [ 'auth_option_id' ]] = $row [ 'auth_setting' ];
}
$this -> db -> sql_freeresult ( $result );
break ;
2013-01-09 15:41:04 -06:00
case 'group' :
2013-01-08 22:09:14 -06:00
$sql = ' SELECT group_id
FROM ' . GROUPS_TABLE . "
WHERE group_name = '" . $this->db->sql_escape($name) . "' " ;
2013-01-08 22:07:12 -06:00
$this -> db -> sql_query ( $sql );
2013-01-09 14:27:01 -06:00
$group_id = ( int ) $this -> db -> sql_fetchfield ( 'group_id' );
2013-01-08 22:07:12 -06:00
if ( ! $group_id )
{
2013-09-10 14:01:09 +02:00
throw new \phpbb\db\migration\exception ( 'GROUP_NOT_EXIST' , $name );
2013-01-08 22:07:12 -06:00
}
// If the group has a role set for them we will add the requested permissions to that role.
2013-01-08 22:09:14 -06:00
$sql = ' SELECT auth_role_id
FROM ' . ACL_GROUPS_TABLE . '
2013-01-08 22:07:12 -06:00
WHERE group_id = ' . $group_id . '
AND auth_role_id <> 0
AND forum_id = 0 ' ;
$this -> db -> sql_query ( $sql );
2013-01-09 14:27:01 -06:00
$role_id = ( int ) $this -> db -> sql_fetchfield ( 'auth_role_id' );
2013-01-08 22:07:12 -06:00
if ( $role_id )
{
2013-01-08 22:09:14 -06:00
$sql = ' SELECT role_name
FROM ' . ACL_ROLES_TABLE . '
2013-01-08 22:07:12 -06:00
WHERE role_id = ' . $role_id ;
$this -> db -> sql_query ( $sql );
$role_name = $this -> db -> sql_fetchfield ( 'role_name' );
2013-03-05 01:06:22 +01:00
return $this -> permission_set ( $role_name , $auth_option , 'role' , $has_permission );
2013-01-08 22:07:12 -06:00
}
2013-01-08 22:09:14 -06:00
$sql = ' SELECT auth_option_id , auth_setting
FROM ' . ACL_GROUPS_TABLE . '
2013-01-08 22:07:12 -06:00
WHERE group_id = ' . $group_id ;
$result = $this -> db -> sql_query ( $sql );
while ( $row = $this -> db -> sql_fetchrow ( $result ))
{
$current_auth [ $row [ 'auth_option_id' ]] = $row [ 'auth_setting' ];
}
$this -> db -> sql_freeresult ( $result );
break ;
}
$sql_ary = array ();
switch ( $type )
{
2013-01-09 15:41:04 -06:00
case 'role' :
2013-01-08 22:07:12 -06:00
foreach ( $new_auth as $auth_option_id )
{
if ( ! isset ( $current_auth [ $auth_option_id ]))
{
$sql_ary [] = array (
'role_id' => $role_id ,
'auth_option_id' => $auth_option_id ,
'auth_setting' => $has_permission ,
2013-01-09 14:27:01 -06:00
);
2013-01-08 22:07:12 -06:00
}
}
$this -> db -> sql_multi_insert ( ACL_ROLES_DATA_TABLE , $sql_ary );
break ;
2013-01-09 15:41:04 -06:00
case 'group' :
2013-01-08 22:07:12 -06:00
foreach ( $new_auth as $auth_option_id )
{
if ( ! isset ( $current_auth [ $auth_option_id ]))
{
$sql_ary [] = array (
'group_id' => $group_id ,
'auth_option_id' => $auth_option_id ,
'auth_setting' => $has_permission ,
2013-01-09 14:27:01 -06:00
);
2013-01-08 22:07:12 -06:00
}
}
$this -> db -> sql_multi_insert ( ACL_GROUPS_TABLE , $sql_ary );
break ;
}
$this -> auth -> acl_clear_prefetch ();
}
/**
* Permission Unset
*
* Allows you to unset ( remove ) permissions for a certain group / role
*
* @ param string $name The name of the role / group
2013-02-04 13:46:23 -06:00
* @ param string | array $auth_option The auth_option or array of
* auth_options you would like to set
2013-01-08 22:07:12 -06:00
* @ param string $type The type ( role | group )
2013-01-09 14:27:01 -06:00
* @ return null
2013-01-08 22:07:12 -06:00
*/
2013-02-04 13:46:23 -06:00
public function permission_unset ( $name , $auth_option , $type = 'role' )
2013-01-08 22:07:12 -06:00
{
if ( ! is_array ( $auth_option ))
{
$auth_option = array ( $auth_option );
}
$to_remove = array ();
2013-01-08 22:09:14 -06:00
$sql = ' SELECT auth_option_id
FROM ' . ACL_OPTIONS_TABLE . '
2013-01-08 22:07:12 -06:00
WHERE ' . $this->db->sql_in_set(' auth_option ' , $auth_option );
$result = $this -> db -> sql_query ( $sql );
while ( $row = $this -> db -> sql_fetchrow ( $result ))
{
2013-01-09 14:27:01 -06:00
$to_remove [] = ( int ) $row [ 'auth_option_id' ];
2013-01-08 22:07:12 -06:00
}
$this -> db -> sql_freeresult ( $result );
2013-01-09 14:27:01 -06:00
if ( empty ( $to_remove ))
2013-01-08 22:07:12 -06:00
{
2013-01-09 14:27:01 -06:00
return ;
2013-01-08 22:07:12 -06:00
}
$type = ( string ) $type ; // Prevent PHP bug.
switch ( $type )
{
2013-01-09 15:41:04 -06:00
case 'role' :
2013-01-08 22:09:14 -06:00
$sql = ' SELECT role_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_name = '" . $this->db->sql_escape($name) . "' " ;
2013-01-08 22:07:12 -06:00
$this -> db -> sql_query ( $sql );
2013-01-09 14:27:01 -06:00
$role_id = ( int ) $this -> db -> sql_fetchfield ( 'role_id' );
2013-01-08 22:07:12 -06:00
if ( ! $role_id )
{
2013-09-10 14:01:09 +02:00
throw new \phpbb\db\migration\exception ( 'ROLE_NOT_EXIST' , $name );
2013-01-08 22:07:12 -06:00
}
$sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '
WHERE ' . $this->db->sql_in_set(' auth_option_id ' , $to_remove );
$this -> db -> sql_query ( $sql );
break ;
2013-01-09 15:41:04 -06:00
case 'group' :
2013-01-08 22:09:14 -06:00
$sql = ' SELECT group_id
FROM ' . GROUPS_TABLE . "
WHERE group_name = '" . $this->db->sql_escape($name) . "' " ;
2013-01-08 22:07:12 -06:00
$this -> db -> sql_query ( $sql );
2013-01-09 14:27:01 -06:00
$group_id = ( int ) $this -> db -> sql_fetchfield ( 'group_id' );
2013-01-08 22:07:12 -06:00
if ( ! $group_id )
{
2013-09-10 14:01:09 +02:00
throw new \phpbb\db\migration\exception ( 'GROUP_NOT_EXIST' , $name );
2013-01-08 22:07:12 -06:00
}
// If the group has a role set for them we will remove the requested permissions from that role.
2013-01-08 22:09:14 -06:00
$sql = ' SELECT auth_role_id
FROM ' . ACL_GROUPS_TABLE . '
2013-01-08 22:07:12 -06:00
WHERE group_id = ' . $group_id . '
AND auth_role_id <> 0 ' ;
$this -> db -> sql_query ( $sql );
2013-01-09 14:27:01 -06:00
$role_id = ( int ) $this -> db -> sql_fetchfield ( 'auth_role_id' );
2013-01-08 22:07:12 -06:00
if ( $role_id )
{
2013-01-08 22:09:14 -06:00
$sql = ' SELECT role_name
FROM ' . ACL_ROLES_TABLE . '
2013-01-08 22:07:12 -06:00
WHERE role_id = ' . $role_id ;
$this -> db -> sql_query ( $sql );
$role_name = $this -> db -> sql_fetchfield ( 'role_name' );
return $this -> permission_unset ( $role_name , $auth_option , 'role' );
}
$sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
WHERE ' . $this->db->sql_in_set(' auth_option_id ' , $to_remove );
$this -> db -> sql_query ( $sql );
break ;
}
$this -> auth -> acl_clear_prefetch ();
}
2013-01-09 18:24:32 -06:00
/**
2013-02-04 13:46:23 -06:00
* { @ inheritdoc }
2013-01-09 18:24:32 -06:00
*/
public function reverse ()
{
$arguments = func_get_args ();
$original_call = array_shift ( $arguments );
$call = false ;
switch ( $original_call )
{
case 'add' :
$call = 'remove' ;
break ;
case 'remove' :
$call = 'add' ;
break ;
case 'permission_set' :
$call = 'permission_unset' ;
break ;
case 'permission_unset' :
$call = 'permission_set' ;
break ;
case 'role_add' :
$call = 'role_remove' ;
break ;
case 'role_remove' :
$call = 'role_add' ;
break ;
case 'role_update' :
// Set to the original value if the current value is what we compared to originally
$arguments = array (
$arguments [ 1 ],
$arguments [ 0 ],
);
break ;
}
if ( $call )
{
return call_user_func_array ( array ( & $this , $call ), $arguments );
}
}
2013-01-08 22:09:14 -06:00
}