fix_acl.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Fixes issues with Group ACLs
  4. *
  5. */
  6. // maybe this could take a while
  7. set_time_limit(0);
  8. // what do we need to fix
  9. $fix = get_input("fix");
  10. switch ($fix) {
  11. case "missing":
  12. // users without access to group content
  13. $missing_users = group_tools_get_missing_acl_users();
  14. if (!empty($missing_users)) {
  15. // make sure we can see all users
  16. $hidden = access_get_show_hidden_status();
  17. access_show_hidden_entities(true);
  18. foreach ($missing_users as $user_data) {
  19. /**
  20. * $user_data = row stdClass
  21. * -> acl_id => the acl the user should be added to
  22. * -> group_guid => the group the acl belongs to
  23. * -> user_guid => the user that should be added
  24. */
  25. add_user_to_access_collection($user_data->user_guid, $user_data->acl_id);
  26. }
  27. // restore hidden settings
  28. access_show_hidden_entities($hidden);
  29. system_message(elgg_echo("group_tools:action:fix_acl:success:missing", array(count($missing_users))));
  30. } else {
  31. register_error(elgg_echo("group_tools:action:fix_acl:error:missing:nothing"));
  32. }
  33. break;
  34. case "excess":
  35. // users with access to group content, but no longer member
  36. $excess_users = group_tools_get_excess_acl_users();
  37. if (!empty($excess_users)) {
  38. foreach ($excess_users as $user_data) {
  39. /**
  40. * $user_data = row stdClass
  41. * -> acl_id => the acl the user should be removed from
  42. * -> group_guid => the group the acl belongs to
  43. * -> user_guid => the user that should be removed
  44. */
  45. group_tools_remove_user_from_access_collection($user_data->user_guid, $user_data->acl_id);
  46. }
  47. system_message(elgg_echo("group_tools:action:fix_acl:success:excess", array(count($excess_users))));
  48. } else {
  49. register_error(elgg_echo("group_tools:action:fix_acl:error:excess:nothing"));
  50. }
  51. break;
  52. case "without":
  53. // groups without acl
  54. $groups = group_tools_get_groups_without_acl();
  55. if (!empty($groups)) {
  56. // create the acl's for each group
  57. foreach ($groups as $group) {
  58. groups_create_event_listener("create", "group", $group);
  59. }
  60. // now add the group members
  61. $missing_users = group_tools_get_missing_acl_users();
  62. if (!empty($missing_users)) {
  63. // make sure we can see all users
  64. $hidden = access_get_show_hidden_status();
  65. access_show_hidden_entities(true);
  66. foreach ($missing_users as $user_data) {
  67. /**
  68. * $user_data = row stdClass
  69. * -> acl_id => the acl the user should be added to
  70. * -> group_guid => the group the acl belongs to
  71. * -> user_guid => the user that should be added
  72. */
  73. add_user_to_access_collection($user_data->user_guid, $user_data->acl_id);
  74. }
  75. // restore hidden settings
  76. access_show_hidden_entities($hidden);
  77. }
  78. system_message(elgg_echo("group_tools:action:fix_acl:success:without", array(count($groups))));
  79. } else {
  80. register_error(elgg_echo("group_tools:action:fix_acl:error:without:nothing"));
  81. }
  82. break;
  83. case "all":
  84. // fix all problems
  85. // first: groups without acl
  86. $groups = group_tools_get_groups_without_acl();
  87. if (!empty($groups)) {
  88. // create the acl's for each group
  89. foreach ($groups as $group) {
  90. groups_create_event_listener("create", "group", $group);
  91. }
  92. system_message(elgg_echo("group_tools:action:fix_acl:success:without", array(count($groups))));
  93. }
  94. // now add the group members
  95. $missing_users = group_tools_get_missing_acl_users();
  96. if (!empty($missing_users)) {
  97. // make sure we can see all users
  98. $hidden = access_get_show_hidden_status();
  99. access_show_hidden_entities(true);
  100. foreach ($missing_users as $user_data) {
  101. /**
  102. * $user_data = row stdClass
  103. * -> acl_id => the acl the user should be added to
  104. * -> group_guid => the group the acl belongs to
  105. * -> user_guid => the user that should be added
  106. */
  107. add_user_to_access_collection($user_data->user_guid, $user_data->acl_id);
  108. }
  109. // restore hidden settings
  110. access_show_hidden_entities($hidden);
  111. system_message(elgg_echo("group_tools:action:fix_acl:success:missing", array(count($missing_users))));
  112. }
  113. // users with access to group content, but no longer member
  114. $excess_users = group_tools_get_excess_acl_users();
  115. if (!empty($excess_users)) {
  116. foreach ($excess_users as $user_data) {
  117. /**
  118. * $user_data = row stdClass
  119. * -> acl_id => the acl the user should be removed from
  120. * -> group_guid => the group the acl belongs to
  121. * -> user_guid => the user that should be removed
  122. */
  123. group_tools_remove_user_from_access_collection($user_data->user_guid, $user_data->acl_id);
  124. }
  125. system_message(elgg_echo("group_tools:action:fix_acl:success:excess", array(count($excess_users))));
  126. }
  127. break;
  128. default:
  129. register_error(elgg_echo("group_tools:action:fix_acl:error:input", array($fix)));
  130. break;
  131. }
  132. forward(REFERER);