aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/upgrades/2010060401.php
blob: 2106bdbc030f3f58bb043de62980e22b1e77e117 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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");
}