Browse Source

Optimize permission defaults (#5323)

* Update permission.php
agree 5 years ago
parent
commit
5d462f2d90
1 changed files with 16 additions and 13 deletions
  1. 16 13
      core/groups/resources/classes/permission.php

+ 16 - 13
core/groups/resources/classes/permission.php

@@ -121,6 +121,11 @@
 
 				//delete the group permissions
 					$this->delete();
+					
+				//get the remaining group permissions
+					$sql = "select permission_name, group_name from v_group_permissions ";
+					$database = new database;
+					$remianing_group_permissions = $database->select($sql, null, 'all');
 
 				//get the $apps array from the installed apps from the core and mod directories
 					$config_list = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_config.php");
@@ -150,20 +155,18 @@
 												}
 											}
 										}
-
 										if (!$group_protected) {
-											//if the item uuid is not currently in the db then add it
-											$sql = "select count(*) from v_group_permissions ";
-											$sql .= "where permission_name = :permission_name ";
-											$sql .= "and group_name = :group_name ";
-											$parameters['permission_name'] = $permission['name'];
-											$parameters['group_name'] = $group_name;
-
-											$database = new database;
-											$num_rows = $database->select($sql, $parameters, 'column');
-											unset($sql, $parameters);
-
-											if ($num_rows == 0) {
+											// check if the item is not currently in the db
+											$exists = false;
+											foreach ($remianing_group_permissions as $i => $group_permission) {
+												if ($group_permission['permission_name'] == $permission['name']) {
+													if ($group_permission['group_name'] == $group_name) {
+														$exists = true;
+														break;
+													}
+												}
+											}
+											if (!$exists) {
 												//build default permissions insert array
 												$array['group_permissions'][$x]['group_permission_uuid'] = uuid();
 												$array['group_permissions'][$x]['permission_name'] = $permission['name'];