fix_auto_join.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Make sure everyone is a member of the autojoin group
  4. */
  5. // this could take a while ;)
  6. set_time_limit(0);
  7. $group_guid = (int) get_input("group_guid");
  8. if (!empty($group_guid)) {
  9. $group = get_entity($group_guid);
  10. if (!empty($group) && ($group instanceof ElggGroup)) {
  11. // set counters
  12. $already = 0;
  13. $new = 0;
  14. $failure = 0;
  15. $options = array(
  16. "type" => "user",
  17. "relationship" => "member_of_site",
  18. "relationship_guid" => elgg_get_site_entity()->getGUID(),
  19. "inverse_relationship" => true,
  20. "limit" => false,
  21. );
  22. $users = new ElggBatch("elgg_get_entities_from_relationship", $options);
  23. foreach ($users as $user) {
  24. if (!$group->isMember($user)) {
  25. if ($group->join($user)) {
  26. $new++;
  27. } else {
  28. $failure++;
  29. }
  30. } else {
  31. $already++;
  32. }
  33. }
  34. system_message(elgg_echo("group_tools:action:fix_auto_join:success", array($new, $already, $failure)));
  35. } else {
  36. register_error(elgg_echo("group_tools:action:error:entity"));
  37. }
  38. } else {
  39. register_error(elgg_echo("group_tools:action:error:input"));
  40. }
  41. forward(REFERER);