diff options
author | Udo Walter | 2017-11-21 17:24:44 +0100 |
---|---|---|
committer | Udo Walter | 2017-11-21 17:24:44 +0100 |
commit | 3d88bb5a4223d3fdc9084eee3e75defc8da674b0 (patch) | |
tree | 9d15a1ccafa5ec3ee97f991637145e524e70e37c /modules-available/permissionmanager/inc/permissiondbupdate.inc.php | |
parent | [dozmod] implemented new permission system to module for: deleting expired vm... (diff) | |
download | slx-admin-3d88bb5a4223d3fdc9084eee3e75defc8da674b0.tar.gz slx-admin-3d88bb5a4223d3fdc9084eee3e75defc8da674b0.tar.xz slx-admin-3d88bb5a4223d3fdc9084eee3e75defc8da674b0.zip |
[permissionmanager] added key relationships to install script;
changed nested php for loops to sql code; standardized sql column naming;
small bugfixes;
Diffstat (limited to 'modules-available/permissionmanager/inc/permissiondbupdate.inc.php')
-rw-r--r-- | modules-available/permissionmanager/inc/permissiondbupdate.inc.php | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/modules-available/permissionmanager/inc/permissiondbupdate.inc.php b/modules-available/permissionmanager/inc/permissiondbupdate.inc.php index 87c989fa..f144b35e 100644 --- a/modules-available/permissionmanager/inc/permissiondbupdate.inc.php +++ b/modules-available/permissionmanager/inc/permissiondbupdate.inc.php @@ -4,53 +4,49 @@ class PermissionDbUpdate { // insert new user_x_role to database. "ignore" to ignore duplicate entry try public static function addRoleToUser($users, $roles) { - foreach($users AS $user) { - foreach ($roles AS $role) { - $query = "INSERT IGNORE INTO user_x_role (userid, roleid) VALUES (:user, :role)"; - Database::exec($query, array("user" => $user, "role" => $role)); + $query = "INSERT IGNORE INTO user_x_role (userid, roleid) VALUES (:userid, :roleid)"; + foreach($users AS $userid) { + foreach ($roles AS $roleid) { + Database::exec($query, array("userid" => $userid, "roleid" => $roleid)); } } } // remove user_x_role entry from database public static function removeRoleFromUser($users, $roles) { - foreach($users AS $user) { - foreach ($roles AS $role) { - $query = "DELETE FROM user_x_role WHERE userid = :user AND roleid = :role"; - Database::exec($query, array("user" => $user, "role" => $role)); - } - } + $query = "DELETE FROM user_x_role WHERE userid IN (:users) AND roleid IN (:roles)"; + Database::exec($query, array("users" => $users, "roles" => $roles)); } // delete role, delete user_x_role relationships, delete role_x_location relationships, delete role_x_permission relationships - public static function deleteRole($id) { - $query = "DELETE FROM role WHERE id = :id"; - Database::exec($query, array("id" => $id)); - $query = "DELETE FROM user_x_role WHERE roleid = :id"; - Database::exec($query, array("id" => $id)); - $query = "DELETE FROM role_x_location WHERE roleid = :id"; - Database::exec($query, array("id" => $id)); - $query = "DELETE FROM role_x_permission WHERE roleid = :id"; - Database::exec($query, array("id" => $id)); + public static function deleteRole($roleid) { + $query = "DELETE FROM role WHERE roleid = :roleid"; + Database::exec($query, array("roleid" => $roleid)); + $query = "DELETE FROM user_x_role WHERE roleid = :roleid"; + Database::exec($query, array("roleid" => $roleid)); + $query = "DELETE FROM role_x_location WHERE roleid = :roleid"; + Database::exec($query, array("roleid" => $roleid)); + $query = "DELETE FROM role_x_permission WHERE roleid = :roleid"; + Database::exec($query, array("roleid" => $roleid)); } - public static function saveRole($roleName, $locations, $permissions, $role = NULL) { - if ($role) { - Database::exec("UPDATE role SET name = :roleName WHERE id = :role", - array("roleName" => $roleName, "role" => $role)); - Database::exec("DELETE FROM role_x_location WHERE roleid = :role", array("role" => $role)); - Database::exec("DELETE FROM role_x_permission WHERE roleid = :role", array("role" => $role)); + public static function saveRole($rolename, $locations, $permissions, $roleid = NULL) { + if ($roleid) { + Database::exec("UPDATE role SET rolename = :rolename WHERE roleid = :roleid", + array("rolename" => $rolename, "roleid" => $roleid)); + Database::exec("DELETE FROM role_x_location WHERE roleid = :roleid", array("roleid" => $roleid)); + Database::exec("DELETE FROM role_x_permission WHERE roleid = :roleid", array("roleid" => $roleid)); } else { - Database::exec("INSERT INTO role (name) VALUES (:roleName)", array("roleName" => $roleName)); - $role = Database::lastInsertId(); + Database::exec("INSERT INTO role (rolename) VALUES (:rolename)", array("rolename" => $rolename)); + $roleid = Database::lastInsertId(); } - foreach ($locations as $locID) { - Database::exec("INSERT INTO role_x_location (roleid, locid) VALUES (:role, :locid)", - array("role" => $role, "locid" => $locID)); + foreach ($locations as $locationid) { + Database::exec("INSERT INTO role_x_location (roleid, locationid) VALUES (:roleid, :locationid)", + array("roleid" => $roleid, "locationid" => $locationid)); } - foreach ($permissions as $permission) { - Database::exec("INSERT INTO role_x_permission (roleid, permissionid) VALUES (:role, :permission)", - array("role" => $role, "permission" => $permission)); + foreach ($permissions as $permissionid) { + Database::exec("INSERT INTO role_x_permission (roleid, permissionid) VALUES (:roleid, :permissionid)", + array("roleid" => $roleid, "permissionid" => $permissionid)); } } |