2011052801.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Make sure all users have the relationship member_of_site
  4. */
  5. global $ENTITY_CACHE;
  6. $db_prefix = get_config('dbprefix');
  7. $limit = 100;
  8. $q = "SELECT e.* FROM {$db_prefix}entities e
  9. WHERE e.type = 'user' AND e.guid NOT IN (
  10. SELECT guid_one FROM {$db_prefix}entity_relationships
  11. WHERE guid_two = 1 AND relationship = 'member_of_site'
  12. )
  13. LIMIT $limit";
  14. $users = get_data($q);
  15. while ($users) {
  16. $ENTITY_CACHE = array();
  17. // do manually to not trigger any events because these aren't new users.
  18. foreach ($users as $user) {
  19. $rel_q = "INSERT INTO {$db_prefix}entity_relationships VALUES (
  20. '',
  21. '$user->guid',
  22. 'member_of_site',
  23. '$user->site_guid',
  24. '$user->time_created'
  25. )";
  26. insert_data($rel_q);
  27. }
  28. // every time we run this query we've just reduced the rows it returns by $limit
  29. // so don't pass an offset.
  30. $q = "SELECT e.* FROM {$db_prefix}entities e
  31. WHERE e.type = 'user' AND e.guid NOT IN (
  32. SELECT guid_one FROM {$db_prefix}entity_relationships
  33. WHERE guid_two = 1 AND relationship = 'member_of_site'
  34. )
  35. LIMIT $limit";
  36. $users = get_data($q);
  37. }