From be37104ac63cd25f2eac831ca03d6d2b19976e1c Mon Sep 17 00:00:00 2001 From: cash Date: Sun, 22 Aug 2010 21:53:48 +0000 Subject: Merged r6684:6694 from 1.7 branch to trunk (pages plugin was manually merged due to standardization of code in trunk but not branch) git-svn-id: http://code.elgg.org/elgg/trunk@6848 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/entities.php | 19 +++++++++------ engine/lib/relationships.php | 4 +--- engine/lib/upgrades/2010071001.php | 48 ++++++++++++++++++++++++++++++++++++++ engine/lib/upgrades/2010071002.php | 48 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 engine/lib/upgrades/2010071001.php create mode 100644 engine/lib/upgrades/2010071002.php (limited to 'engine/lib') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 1750f12e1..e6c2baa8e 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -801,7 +801,9 @@ abstract class ElggEntity implements $this->attributes['subtype'] = get_subtype_id($this->attributes['type'], $this->attributes['subtype']); // Cache object handle - if ($this->attributes['guid']) cache_entity($this); + if ($this->attributes['guid']) { + cache_entity($this); + } return $this->attributes['guid']; } @@ -1693,21 +1695,24 @@ function entity_row_to_elggstar($row) { if (!($new_entity instanceof ElggEntity)) { throw new ClassException(sprintf(elgg_echo('ClassException:ClassnameNotClass'), $classname, 'ElggEntity')); } - } - else { + } else { error_log(sprintf(elgg_echo('ClassNotFoundException:MissingClass'), $classname)); } } else { switch ($row->type) { case 'object' : - $new_entity = new ElggObject($row); break; + $new_entity = new ElggObject($row); + break; case 'user' : - $new_entity = new ElggUser($row); break; + $new_entity = new ElggUser($row); + break; case 'group' : - $new_entity = new ElggGroup($row); break; + $new_entity = new ElggGroup($row); + break; case 'site' : - $new_entity = new ElggSite($row); break; + $new_entity = new ElggSite($row); + break; default: throw new InstallationException(sprintf(elgg_echo('InstallationException:TypeNotSupported'), $row->type)); } diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php index f1d119452..dd59b8d3f 100644 --- a/engine/lib/relationships.php +++ b/engine/lib/relationships.php @@ -625,9 +625,7 @@ $count = false, $site_guid = 0) { $options['owner_guid'] = $owner_guid; } - if ($limit) { - $options['limit'] = $limit; - } + $options['limit'] = $limit; if ($offset) { $options['offset'] = $offset; diff --git a/engine/lib/upgrades/2010071001.php b/engine/lib/upgrades/2010071001.php new file mode 100644 index 000000000..4df044cff --- /dev/null +++ b/engine/lib/upgrades/2010071001.php @@ -0,0 +1,48 @@ +type != 'user') { + // only to be used for user directories + return FALSE; + } + + if (!$user->time_created) { + // no idea where this user has its files + return FALSE; + } + + $time_created = date('Y/m/d', $user->time_created); + return "$time_created/$user->guid/"; +} + +$sizes = array('large', 'medium', 'small', 'tiny', 'master', 'topbar'); + +global $DB_QUERY_CACHE, $DB_PROFILE, $ENTITY_CACHE, $CONFIG; +$users = mysql_query("SELECT guid, username FROM {$CONFIG->dbprefix}users_entity WHERE username != ''"); +while ($user = mysql_fetch_object($users)) { + $DB_QUERY_CACHE = $DB_PROFILE = $ENTITY_CACHE = array(); + + $user_directory = user_file_matrix_2010071001($user->guid); + if (!$user_directory) { + continue; + } + $profile_directory = $CONFIG->dataroot . $user_directory . "profile/"; + if (!file_exists($profile_directory)) { + continue; + } + + foreach ($sizes as $size) { + $old_filename = "$profile_directory{$user->username}{$size}.jpg"; + $new_filename = "$profile_directory{$user->guid}{$size}.jpg"; + if (file_exists($old_filename)) { + if (!rename($old_filename, $new_filename)) { + error_log("Failed to rename profile photo for $user->username"); + } + } + } +} diff --git a/engine/lib/upgrades/2010071002.php b/engine/lib/upgrades/2010071002.php new file mode 100644 index 000000000..cdf08c830 --- /dev/null +++ b/engine/lib/upgrades/2010071002.php @@ -0,0 +1,48 @@ +dbprefix}users_entity WHERE username != ''"); +while ($user = mysql_fetch_object($users)) { + $DB_QUERY_CACHE = $DB_PROFILE = $ENTITY_CACHE = array(); + + $user = get_entity($user->guid); + foreach ($NOTIFICATION_HANDLERS as $method => $foo) { + $notify = "notify$method"; + $metaname = "collections_notifications_preferences_$method"; + $collections_preferences = $user->$metaname; + if (!$collections_preferences) { + continue; + } + if (!is_array($collections_preferences)) { + $collections_preferences = array($collections_preferences); + } + foreach ($collections_preferences as $collection_id) { + // check the all friends notifications + if ($collection_id == -1) { + $options = array( + 'relationship' => 'friend', + 'relationship_guid' => $user->guid, + 'limit' => 0 + ); + $friends = elgg_get_entities_from_relationship($options); + foreach ($friends as $friend) { + if (!check_entity_relationship($user->guid, $notify, $friend->guid)) { + add_entity_relationship($user->guid, $notify, $friend->guid); + } + } + } else { + $members = get_members_of_access_collection($collection_id, TRUE); + foreach ($members as $member) { + if (!check_entity_relationship($user->guid, $notify, $members)) { + add_entity_relationship($user->guid, $notify, $member); + } + } + } + } + } +} -- cgit v1.2.3