app_defaults.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. if ($domains_processed == 1) {
  3. //add the permissions
  4. $sql = "select * from v_permissions \n";
  5. $database_permissions = $database->select($sql, null, 'all');
  6. //get the $apps array from the installed apps from the core and mod directories
  7. $config_list = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_config.php");
  8. $x = 0;
  9. foreach ($config_list as $config_path) {
  10. include($config_path);
  11. $x++;
  12. }
  13. //restore default permissions
  14. $x = 0;
  15. foreach ($apps as $app) {
  16. if (!empty($app['permissions'])) {
  17. foreach ($app['permissions'] as $app_permission) {
  18. //check if the permission is in the database
  19. $permission_found = false;
  20. if (!empty($database_permissions)) {
  21. foreach($database_permissions as $row) {
  22. if ($row['permission_name'] == $app_permission['name']) {
  23. $permission_found = true;
  24. }
  25. }
  26. }
  27. //add the permission to the array
  28. if (!$permission_found) {
  29. $array['permissions'][$x]['permission_uuid'] = uuid();
  30. $array['permissions'][$x]['permission_name'] = $app_permission['name'];
  31. $array['permissions'][$x]['application_name'] = $app['name'];
  32. $array['permissions'][$x]['application_uuid'] = $app['uuid'];
  33. $array['permissions'][$x]['insert_date'] = 'now()';
  34. $x++;
  35. }
  36. }
  37. }
  38. }
  39. //save the data to the database
  40. if (!empty($array)) {
  41. //grant temporary permissions
  42. $p = permissions::new();
  43. $p->add('permission_add', 'temp');
  44. //execute insert
  45. $database->app_name = 'permissions';
  46. $database->app_uuid = 'ce1498a0-46e2-487d-85de-4eec7122a984';
  47. $database->save($array, false);
  48. unset($array);
  49. //revoke temporary permissions
  50. $p->delete('permission_add', 'temp');
  51. }
  52. }
  53. ?>