2010060401.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Get each user's notify* relationships and confirm that they have a friend
  4. * or member relationship depending on type. This fixes the notify relationships
  5. * that were not updated to due to #1837
  6. */
  7. $count = 0;
  8. $user_guids = mysql_query("SELECT guid FROM {$CONFIG->dbprefix}users_entity");
  9. while ($user = mysql_fetch_object($user_guids)) {
  10. $query = "SELECT * FROM {$CONFIG->dbprefix}entity_relationships
  11. WHERE guid_one=$user->guid AND relationship LIKE 'notify%'";
  12. $relationships = mysql_query($query);
  13. if (mysql_num_rows($relationships) == 0) {
  14. // no notify relationships for this user
  15. continue;
  16. }
  17. while ($obj = mysql_fetch_object($relationships)) {
  18. $query = "SELECT type FROM {$CONFIG->dbprefix}entities WHERE guid=$obj->guid_two";
  19. $results = mysql_query($query);
  20. if (mysql_num_rows($results) == 0) {
  21. // entity doesn't exist - shouldn't be possible
  22. continue;
  23. }
  24. $entity = mysql_fetch_object($results);
  25. switch ($entity->type) {
  26. case 'user':
  27. $relationship_type = 'friend';
  28. break;
  29. case 'group':
  30. $relationship_type = 'member';
  31. break;
  32. }
  33. if (isset($relationship_type)) {
  34. $query = "SELECT * FROM {$CONFIG->dbprefix}entity_relationships
  35. WHERE guid_one=$user->guid AND relationship='$relationship_type'
  36. AND guid_two=$obj->guid_two";
  37. $results = mysql_query($query);
  38. if (mysql_num_rows($results) == 0) {
  39. $query = "DELETE FROM {$CONFIG->dbprefix}entity_relationships WHERE id=$obj->id";
  40. mysql_query($query);
  41. $count++;
  42. }
  43. }
  44. }
  45. }
  46. if (is_callable('error_log')) {
  47. error_log("Deleted $count notify relationships in upgrade");
  48. }