diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-06-04 15:41:31 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-06-04 15:41:31 +0000 |
commit | c33a7b4847a5d1537dcc7272dc056bc64f3f1cb3 (patch) | |
tree | 40266cd4f82dc558d167fe9dc7bf7da7ab885f80 /engine/lib/upgrades/2010060401.php | |
parent | f4b1ebbe468e295d59bf7285b335aa51bcf132bb (diff) | |
download | elgg-c33a7b4847a5d1537dcc7272dc056bc64f3f1cb3.tar.gz elgg-c33a7b4847a5d1537dcc7272dc056bc64f3f1cb3.tar.bz2 |
Merged r6349:6351 from 1.7 to trunk.
git-svn-id: http://code.elgg.org/elgg/trunk@6357 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/upgrades/2010060401.php')
-rw-r--r-- | engine/lib/upgrades/2010060401.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/engine/lib/upgrades/2010060401.php b/engine/lib/upgrades/2010060401.php new file mode 100644 index 000000000..2106bdbc0 --- /dev/null +++ b/engine/lib/upgrades/2010060401.php @@ -0,0 +1,57 @@ +<?php + +/** + * Get each user's notify* relationships and confirm that they have a friend + * or member relationship depending on type. This fixes the notify relationships + * that were not updated to due to #1837 + */ + +$count = 0; + +$user_guids = mysql_query("SELECT guid FROM {$CONFIG->dbprefix}users_entity"); +while ($user = mysql_fetch_object($user_guids)) { + + $query = "SELECT * FROM {$CONFIG->dbprefix}entity_relationships WHERE guid_one=$user->guid AND relationship LIKE 'notify%'"; + $relationships = mysql_query($query); + if (mysql_num_rows($relationships) == 0) { + // no notify relationships for this user + continue; + } + + while ($obj = mysql_fetch_object($relationships)) { + $query = "SELECT type FROM {$CONFIG->dbprefix}entities WHERE guid=$obj->guid_two"; + $results = mysql_query($query); + if (mysql_num_rows($results) == 0) { + // entity doesn't exist - shouldn't be possible + continue; + } + + $entity = mysql_fetch_object($results); + + switch ($entity->type) { + case 'user': + $relationship_type = 'friend'; + break; + case 'group': + $relationship_type = 'member'; + break; + } + + if (isset($relationship_type)) { + $query = "SELECT * FROM {$CONFIG->dbprefix}entity_relationships + WHERE guid_one=$user->guid AND relationship='$relationship_type' + AND guid_two=$obj->guid_two"; + $results = mysql_query($query); + if (mysql_num_rows($results) == 0) { + $query = "DELETE FROM {$CONFIG->dbprefix}entity_relationships WHERE id=$obj->id"; + mysql_query($query); + $count++; + } + } + } + +} + +if (is_callable('error_log')) { + error_log("Deleted $count notify relationships in upgrade"); +} |