diff options
author | Simon Rettberg | 2018-02-14 13:54:45 +0100 |
---|---|---|
committer | Simon Rettberg | 2018-02-14 13:54:45 +0100 |
commit | e39bc13cee5db3d4905498e0fe3ac89fd3ccbfe7 (patch) | |
tree | 48d4c4bae3d26f467847acace3ab0c83be1a234b /modules-available/permissionmanager/inc/permissiondbupdate.inc.php | |
parent | [permissionmanager] Speed up queries for saving roles and assignments (diff) | |
download | slx-admin-e39bc13cee5db3d4905498e0fe3ac89fd3ccbfe7.tar.gz slx-admin-e39bc13cee5db3d4905498e0fe3ac89fd3ccbfe7.tar.xz slx-admin-e39bc13cee5db3d4905498e0fe3ac89fd3ccbfe7.zip |
[permissionmanager] Apply formatting
Diffstat (limited to 'modules-available/permissionmanager/inc/permissiondbupdate.inc.php')
-rw-r--r-- | modules-available/permissionmanager/inc/permissiondbupdate.inc.php | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/modules-available/permissionmanager/inc/permissiondbupdate.inc.php b/modules-available/permissionmanager/inc/permissiondbupdate.inc.php index 0f37a053..f2e7a366 100644 --- a/modules-available/permissionmanager/inc/permissiondbupdate.inc.php +++ b/modules-available/permissionmanager/inc/permissiondbupdate.inc.php @@ -1,6 +1,7 @@ <?php -class PermissionDbUpdate { +class PermissionDbUpdate +{ /** * Insert all user/role combinations into the user_x_role table. @@ -8,9 +9,10 @@ class PermissionDbUpdate { * @param array $users userids * @param array $roles roleids */ - public static function addRoleToUser($users, $roles) { + public static function addRoleToUser($users, $roles) + { $arg = array(); - foreach($users AS $userid) { + foreach ($users AS $userid) { foreach ($roles AS $roleid) { $arg[] = compact('userid', 'roleid'); } @@ -25,7 +27,8 @@ class PermissionDbUpdate { * @param array $users userids * @param array $roles roleids */ - public static function removeRoleFromUser($users, $roles) { + public static function removeRoleFromUser($users, $roles) + { $query = "DELETE FROM user_x_role WHERE userid IN (:users) AND roleid IN (:roles)"; Database::exec($query, array("users" => $users, "roles" => $roles)); } @@ -35,7 +38,8 @@ class PermissionDbUpdate { * * @param string $roleid roleid */ - public static function deleteRole($roleid) { + public static function deleteRole($roleid) + { Database::exec("DELETE FROM role WHERE roleid = :roleid", array("roleid" => $roleid)); } @@ -47,28 +51,31 @@ class PermissionDbUpdate { * @param array $permissions array of permissions * @param string|null $roleid roleid or null if the role does not exist yet */ - public static function saveRole($rolename, $locations, $permissions, $roleid = NULL) { + 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)); + array("rolename" => $rolename, "roleid" => $roleid)); Database::exec("DELETE FROM role_x_location - WHERE roleid = :roleid AND locationid NOT IN (:locations)", array("roleid" => $roleid, 'locations' => $locations)); + WHERE roleid = :roleid AND locationid NOT IN (:locations)", + array("roleid" => $roleid, 'locations' => $locations)); Database::exec("DELETE FROM role_x_permission - WHERE roleid = :roleid AND permissionid NOT IN (:permissions)", array("roleid" => $roleid, 'permissions' => $permissions)); + WHERE roleid = :roleid AND permissionid NOT IN (:permissions)", + array("roleid" => $roleid, 'permissions' => $permissions)); } else { Database::exec("INSERT INTO role (rolename) VALUES (:rolename)", array("rolename" => $rolename)); $roleid = Database::lastInsertId(); } - $arg = array_map(function($loc) use ($roleid) { + + $arg = array_map(function ($loc) use ($roleid) { return compact('roleid', 'loc'); }, $locations); - Database::exec("INSERT IGNORE INTO role_x_location (roleid, locationid) VALUES :arg", - ['arg' => $arg]); - $arg = array_map(function($perm) use ($roleid) { + Database::exec("INSERT IGNORE INTO role_x_location (roleid, locationid) VALUES :arg", ['arg' => $arg]); + + $arg = array_map(function ($perm) use ($roleid) { return compact('roleid', 'perm'); }, $permissions); - Database::exec("INSERT IGNORE INTO role_x_permission (roleid, permissionid) VALUES :arg", - ['arg' => $arg]); + Database::exec("INSERT IGNORE INTO role_x_permission (roleid, permissionid) VALUES :arg", ['arg' => $arg]); } } |