diff options
Diffstat (limited to 'engine/lib/upgrades')
45 files changed, 1529 insertions, 0 deletions
| diff --git a/engine/lib/upgrades/2008100701.php b/engine/lib/upgrades/2008100701.php new file mode 100644 index 000000000..b8d4dfdbc --- /dev/null +++ b/engine/lib/upgrades/2008100701.php @@ -0,0 +1,7 @@ +<?php + +/** + * Because Elgg now has a plugable account activation process we need to activate + * the email account activation plugin for existing installs. + */ +enable_plugin('uservalidationbyemail', $CONFIG->site->guid); diff --git a/engine/lib/upgrades/2008101303.php b/engine/lib/upgrades/2008101303.php new file mode 100644 index 000000000..69e44e3a0 --- /dev/null +++ b/engine/lib/upgrades/2008101303.php @@ -0,0 +1,9 @@ +<?php + +// Upgrade to solve login issue + +if ($users = get_entities_from_metadata('validated_email', '', 'user', '', 0, 9999)) { +	foreach ($users as $user) { +		set_user_validation_status($user->guid, true, 'email'); +	} +} diff --git a/engine/lib/upgrades/2009022701.php b/engine/lib/upgrades/2009022701.php new file mode 100644 index 000000000..54083a34d --- /dev/null +++ b/engine/lib/upgrades/2009022701.php @@ -0,0 +1,7 @@ +<?php +global $CONFIG; + +/** + * Disable update client since this has now been removed. + */ +disable_plugin('updateclient', $CONFIG->site->guid); diff --git a/engine/lib/upgrades/2009041701.php b/engine/lib/upgrades/2009041701.php new file mode 100644 index 000000000..7b31a3bc9 --- /dev/null +++ b/engine/lib/upgrades/2009041701.php @@ -0,0 +1,8 @@ +<?php + +global $CONFIG; + +/** + * Elgg now has kses tag filtering built as a plugin. This needs to be enabled. + */ +enable_plugin('kses', $CONFIG->site->guid); diff --git a/engine/lib/upgrades/2009070101.php b/engine/lib/upgrades/2009070101.php new file mode 100644 index 000000000..d0eae9b91 --- /dev/null +++ b/engine/lib/upgrades/2009070101.php @@ -0,0 +1,9 @@ +<?php + +global $CONFIG; + +/** + * Kses appears to be a dead project so we are deprecating it in favour of htmlawed. + */ +disable_plugin('kses', $CONFIG->site->guid); +enable_plugin('htmlawed', $CONFIG->site->guid); diff --git a/engine/lib/upgrades/2009102801.php b/engine/lib/upgrades/2009102801.php new file mode 100644 index 000000000..3ad113fb2 --- /dev/null +++ b/engine/lib/upgrades/2009102801.php @@ -0,0 +1,222 @@ +<?php + +/** + * Move user's data directories from using username to registration date + */ + +/** + * Generates a file matrix like Elgg 1.0 did + * + * @param string $username Username of user + * + * @return string File matrix path + */ +function file_matrix_1_0($username) { +	$matrix = ""; + +	$len = strlen($username); +	if ($len > 5) { +		$len = 5; +	} + +	for ($n = 0; $n < $len; $n++) { +		if (ctype_alnum($username[$n])) { +			$matrix .= $username[$n] . "/"; +		} +	} + +	return $matrix . $username . "/"; +} + + +/** + * Generate a file matrix like Elgg 1.1, 1.2 and 1.5 + * + * @param string $filename The filename + * + * @return string + */ +function file_matrix_1_1($filename) { +	$matrix = ""; + +	$name = $filename; +	$filename = mb_str_split($filename); +	if (!$filename) { +		return false; +	} + +	$len = count($filename); +	if ($len > 5) { +		$len = 5; +	} + +	for ($n = 0; $n < $len; $n++) { +		$matrix .= $filename[$n] . "/"; +	} + +	return $matrix . $name . "/"; +} + +/** + * Handle splitting multibyte strings + * + * @param string $string  String to split. + * @param string $charset Charset to use. + * + * @return array|false + */ +function mb_str_split($string, $charset = 'UTF8') { +	if (is_callable('mb_substr')) { +		$length = mb_strlen($string); +		$array = array(); + +		while ($length) { +			$array[] = mb_substr($string, 0, 1, $charset); +			$string = mb_substr($string, 1, $length, $charset); + +			$length = mb_strlen($string); +		} + +		return $array; +	} else { +		return str_split($string); +	} + +	return false; +} + + +/** + * 1.6 style file matrix + * + * @param string $filename The filename + * + * @return string + */ +function file_matrix_1_6($filename) { +	$invalid_fs_chars = '*\'\\/"!$%^&*.%(){}[]#~?<>;|¬`@-+='; + +	$matrix = ""; + +	$name = $filename; +	$filename = mb_str_split($filename); +	if (!$filename) { +		return false; +	} + +	$len = count($filename); +	if ($len > 5) { +		$len = 5; +	} + +	for ($n = 0; $n < $len; $n++) { + +		// Prevent a matrix being formed with unsafe characters +		$char = $filename[$n]; +		if (strpos($invalid_fs_chars, $char) !== false) { +			$char = '_'; +		} + +		$matrix .= $char . "/"; +	} + +	return $matrix . $name . "/"; +} + + +/** + * Scans a directory and moves any files from $from to $to + * preserving structure and handling existing paths. + * Will no overwrite files in $to. + * + * TRAILING SLASHES REQUIRED. + * + * @param string $from       From dir. + * @param string $to         To dir. + * @param bool   $move       True to move, false to copy. + * @param string $preference to|from If file collisions, which dir has preference. + * + * @return bool + */ +function merge_directories($from, $to, $move = false, $preference = 'to') { +	if (!$entries = scandir($from)) { +		return false; +	} + +	// character filtering needs to be elsewhere. +	if (!is_dir($to)) { +		mkdir($to, 0700, true); +	} + +	if ($move === true) { +		$f = 'rename'; +	} else { +		$f = 'copy'; +	} + +	foreach ($entries as $entry) { +		if ($entry == '.' || $entry == '..') { +			continue; +		} + +		$from_path = $from . $entry; +		$to_path = $to . $entry; + +		// check to see if the path exists and is a dir, if so, recurse. +		if (is_dir($from_path) && is_dir($to_path)) { +			$from_path .= '/'; +			$to_path .= '/'; +			merge_directories($from_path, $to_path, $move, $preference); + +			// since it's a dir that already exists we don't need to move it +			continue; +		} + +		// only move if target doesn't exist or if preference is for the from dir +		if (!file_exists($to_path) || $preference == 'from') { + +			if ($f($from_path, $to_path)) { +				//elgg_dump("Moved/Copied $from_path to $to_path"); +			} +		} else { +			//elgg_dump("Ignoring $from_path -> $to_path"); +		} +	} +} + +/** + * Create a 1.7 style user file matrix based upon date. + * + * @param int $guid Guid of owner + * + * @return string File matrix path + */ +function user_file_matrix($guid) { +	// lookup the entity +	$user = get_entity($guid); +	if ($user->type != 'user') { +		// only to be used for user directories +		return FALSE; +	} + +	$time_created = date('Y/m/d', $user->time_created); +	return "$time_created/$user->guid/"; +} + +global $ENTITY_CACHE, $CONFIG; +/** + * Upgrade file locations + */ +$users = mysql_query("SELECT guid, username +	FROM {$CONFIG->dbprefix}users_entity WHERE username != ''"); +while ($user = mysql_fetch_object($users)) { +	$ENTITY_CACHE = array(); +	_elgg_invalidate_query_cache(); + +	$to = $CONFIG->dataroot . user_file_matrix($user->guid); +	foreach (array('1_0', '1_1', '1_6') as $version) { +		$function = "file_matrix_$version"; +		$from = $CONFIG->dataroot . $function($user->username); +		merge_directories($from, $to, $move = TRUE, $preference = 'from'); +	} +} diff --git a/engine/lib/upgrades/2010010501.php b/engine/lib/upgrades/2010010501.php new file mode 100644 index 000000000..1e83caa55 --- /dev/null +++ b/engine/lib/upgrades/2010010501.php @@ -0,0 +1,8 @@ +<?php + +global $CONFIG; + +/** + * Enable the search plugin + */	 +enable_plugin('search', $CONFIG->site->guid); diff --git a/engine/lib/upgrades/2010033101.php b/engine/lib/upgrades/2010033101.php new file mode 100644 index 000000000..4779295fd --- /dev/null +++ b/engine/lib/upgrades/2010033101.php @@ -0,0 +1,70 @@ +<?php + +/** + * Conditional upgrade for UTF8 as described in https://github.com/elgg/elgg/issues/1928 + */ + +// get_version() returns the code version. +// we want the DB version. +$dbversion = (int) datalist_get('version'); + +// 2009100701 was the utf8 upgrade for 1.7. +// if we've already upgraded, don't try again. +if ($dbversion < 2009100701) { +	// if the default client connection is utf8 there is no reason +	// to run this upgrade because the strings are already stored correctly. + +	// start a new link to the DB to see what its defaults are. +	$link = mysql_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, TRUE); +	mysql_select_db($CONFIG->dbname, $link); + +	$q = "SHOW VARIABLES LIKE 'character_set_client'"; +	$r = mysql_query($q); +	$client = mysql_fetch_assoc($r); + +	$q = "SHOW VARIABLES LIKE 'character_set_connection'"; +	$r = mysql_query($q); +	$connection = mysql_fetch_assoc($r); + +	// only run upgrade if not already talking utf8. +	if ($client['Value'] != 'utf8' && $connection['Value'] != 'utf8') { +		$qs = array(); +		$qs[] = "SET NAMES utf8"; + +		$qs[] = "ALTER TABLE {$CONFIG->dbprefix}metastrings DISABLE KEYS"; +		$qs[] = "REPLACE INTO {$CONFIG->dbprefix}metastrings (id, string) +			SELECT id, unhex(hex(convert(string using latin1))) +			FROM {$CONFIG->dbprefix}metastrings"; +		$qs[] = "ALTER TABLE {$CONFIG->dbprefix}metastrings ENABLE KEYS"; + +		$qs[] = "ALTER TABLE {$CONFIG->dbprefix}groups_entity DISABLE KEYS"; +		$qs[] = "REPLACE INTO {$CONFIG->dbprefix}groups_entity (guid, name, description) +			SELECT guid, unhex(hex(convert(name using latin1))), +				unhex(hex(convert(description using latin1))) +			FROM {$CONFIG->dbprefix}groups_entity"; +		$qs[] = "ALTER TABLE {$CONFIG->dbprefix}groups_entity ENABLE KEYS"; + +		$qs[] = "ALTER TABLE {$CONFIG->dbprefix}objects_entity DISABLE KEYS"; +		$qs[] = "REPLACE INTO {$CONFIG->dbprefix}objects_entity (guid, title, description) +			SELECT guid, unhex(hex(convert(title using latin1))), +				unhex(hex(convert(description using latin1))) +			FROM {$CONFIG->dbprefix}objects_entity"; +		$qs[] = "ALTER TABLE {$CONFIG->dbprefix}objects_entity ENABLE KEYS"; + +		$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity DISABLE KEYS"; +		$qs[] = "REPLACE INTO {$CONFIG->dbprefix}users_entity +			(guid, name, username, password, salt, email, language, code, +			banned, last_action, prev_last_action, last_login, prev_last_login) +				SELECT guid, unhex(hex(convert(name using latin1))), +					username, password, salt, email, language, code, +					banned, last_action, prev_last_action, last_login, prev_last_login +				FROM {$CONFIG->dbprefix}users_entity"; +		$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity ENABLE KEYS"; + +		foreach ($qs as $q) { +			if (!update_data($q)) { +				throw new Exception('Couldn\'t execute upgrade query: ' . $q); +			} +		} +	} +} diff --git a/engine/lib/upgrades/2010040201.php b/engine/lib/upgrades/2010040201.php new file mode 100644 index 000000000..789bf5dfc --- /dev/null +++ b/engine/lib/upgrades/2010040201.php @@ -0,0 +1,41 @@ +<?php + +/** + * Pull admin metadata setting into users_entity table column + */ + +$siteadmin = get_metastring_id('siteadmin'); +$admin = get_metastring_id('admin'); +$yes = get_metastring_id('yes'); +$one = get_metastring_id('1'); + +$qs = array(); + +$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity DISABLE KEYS"; + +$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity +	ADD admin ENUM('yes', 'no') NOT NULL DEFAULT 'no' AFTER `banned`"; + +$qs[] = "UPDATE {$CONFIG->dbprefix}users_entity SET admin = 'yes' where guid IN (select x.guid FROM( +SELECT * FROM {$CONFIG->dbprefix}users_entity as e, +	{$CONFIG->dbprefix}metadata as md +	WHERE ( +		md.name_id IN ('$admin', '$siteadmin') +		AND md.value_id IN ('$yes', '$one') +		AND e.guid = md.entity_guid +		AND e.banned = 'no' +	)) as x)"; + +$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity ADD KEY admin (admin)"; + +$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity ENABLE KEYS"; + +$qs[] = "DELETE FROM {$CONFIG->dbprefix}metadata +	WHERE ( +		name_id IN ('$admin', '$siteadmin') +		AND value_id IN ('$yes', '$one') +	)"; + +foreach ($qs as $q) { +	update_data($q); +} diff --git a/engine/lib/upgrades/2010052601.php b/engine/lib/upgrades/2010052601.php new file mode 100644 index 000000000..a9cca6dc5 --- /dev/null +++ b/engine/lib/upgrades/2010052601.php @@ -0,0 +1,27 @@ +<?php + +// Upgrade to fix encoding issues on group data: #1963 + +elgg_set_ignore_access(TRUE); + +$params = array('type' => 'group', +				'limit' => 0); +$groups = elgg_get_entities($params); +if ($groups) { +	foreach ($groups as $group) { +		$group->name = _elgg_html_decode($group->name); +		$group->description = _elgg_html_decode($group->description); +		$group->briefdescription = _elgg_html_decode($group->briefdescription); +		$group->website = _elgg_html_decode($group->website); +		if ($group->interests) { +			$tags = $group->interests; +			foreach ($tags as $index => $tag) { +				$tags[$index] = _elgg_html_decode($tag); +			} +			$group->interests = $tags; +		} + +		$group->save(); +	} +} +elgg_set_ignore_access(FALSE); diff --git a/engine/lib/upgrades/2010060101.php b/engine/lib/upgrades/2010060101.php new file mode 100644 index 000000000..bb7f7c1a6 --- /dev/null +++ b/engine/lib/upgrades/2010060101.php @@ -0,0 +1,16 @@ +<?php + +/** + * Clears old simplecache variables out of database + */ + +$query = "DELETE FROM {$CONFIG->dbprefix}datalists WHERE name LIKE 'simplecache%'"; + +delete_data($query); + +if ($CONFIG->simplecache_enabled) { +	datalist_set('simplecache_enabled', 1); +	elgg_regenerate_simplecache(); +} else { +	datalist_set('simplecache_enabled', 0); +} diff --git a/engine/lib/upgrades/2010060401.php b/engine/lib/upgrades/2010060401.php new file mode 100644 index 000000000..6d628b8eb --- /dev/null +++ b/engine/lib/upgrades/2010060401.php @@ -0,0 +1,59 @@ +<?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"); +} diff --git a/engine/lib/upgrades/2010061501.php b/engine/lib/upgrades/2010061501.php new file mode 100644 index 000000000..744c28fd5 --- /dev/null +++ b/engine/lib/upgrades/2010061501.php @@ -0,0 +1,75 @@ +<?php +/** + * utf8 database conversion and file merging for usernames with multibyte chars + * + */ + + +// check that we need to do the utf8 conversion +// C&P logic from 2010033101 +$dbversion = (int) datalist_get('version'); + +if ($dbversion < 2009100701) { +	// start a new link to the DB to see what its defaults are. +	$link = mysql_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, TRUE); +	mysql_select_db($CONFIG->dbname, $link); + +	$q = "SHOW VARIABLES LIKE 'character_set_client'"; +	$r = mysql_query($q); +	$client = mysql_fetch_assoc($r); + +	$q = "SHOW VARIABLES LIKE 'character_set_connection'"; +	$r = mysql_query($q); +	$connection = mysql_fetch_assoc($r); + +	// only run upgrade if not already talking utf8 +	if ($client['Value'] != 'utf8' && $connection['Value'] != 'utf8') { +		$qs = array(); +		$qs[] = "SET NAMES utf8"; + +		$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity DISABLE KEYS"; +		$qs[] = "REPLACE INTO {$CONFIG->dbprefix}users_entity +			(guid, name, username, password, salt, email, language, code, +			banned, admin, last_action, prev_last_action, last_login, prev_last_login) + +			SELECT guid, name, unhex(hex(convert(username using latin1))), +				password, salt, email, language, code, +				banned, admin, last_action, prev_last_action, last_login, prev_last_login +			FROM {$CONFIG->dbprefix}users_entity"; + +		$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity ENABLE KEYS"; + +		foreach ($qs as $q) { +			if (!update_data($q)) { +				throw new Exception('Couldn\'t execute upgrade query: ' . $q); +			} +		} + +		global $ENTITY_CACHE; + +		/** +			Upgrade file locations +		 */ +		// new connection to force into utf8 mode to get the old name +		$link = mysql_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, TRUE); +		mysql_select_db($CONFIG->dbname, $link); + +		// must be the first command +		mysql_query("SET NAMES utf8"); + +		$users = mysql_query("SELECT guid, username FROM {$CONFIG->dbprefix}users_entity +			WHERE username != ''", $link); +		while ($user = mysql_fetch_object($users)) { +			$ENTITY_CACHE = array(); +			_elgg_invalidate_query_cache(); + + +			$to = $CONFIG->dataroot . user_file_matrix($user->guid); +			foreach (array('1_0', '1_1', '1_6') as $version) { +				$function = "file_matrix_$version"; +				$from = $CONFIG->dataroot . $function($user->username); +				merge_directories($from, $to, $move = TRUE, $preference = 'from'); +			} +		} +	} +} diff --git a/engine/lib/upgrades/2010062301.php b/engine/lib/upgrades/2010062301.php new file mode 100644 index 000000000..f679fa46d --- /dev/null +++ b/engine/lib/upgrades/2010062301.php @@ -0,0 +1,33 @@ +<?php + +/** + * Change ownership of group ACLs to group entity + */ + +elgg_set_ignore_access(TRUE); + +$params = array('type' => 'group', +				'limit' => 0); +$groups = elgg_get_entities($params); +if ($groups) { +	foreach ($groups as $group) { +		$acl = $group->group_acl; + +		try { +			$query = "UPDATE {$CONFIG->dbprefix}access_collections +				SET owner_guid = $group->guid WHERE id = $acl"; +			update_data($query); +		} catch (Exception $e) { +			// no acl so create one +			$ac_name = elgg_echo('groups:group') . ": " . $group->name; +			$group_acl = create_access_collection($ac_name, $group->guid); +			if ($group_acl) { +				create_metadata($group->guid, 'group_acl', $group_acl, 'integer', $group->owner_guid); +				$object->group_acl = $group_id; +			} +		} + +	} +} +elgg_set_ignore_access(FALSE); + diff --git a/engine/lib/upgrades/2010062302.php b/engine/lib/upgrades/2010062302.php new file mode 100644 index 000000000..fe33e12ea --- /dev/null +++ b/engine/lib/upgrades/2010062302.php @@ -0,0 +1,33 @@ +<?php + +/** + * Make sure that everyone who belongs to a group is a member of the group's access collection + */ + + +elgg_set_ignore_access(TRUE); + +$params = array('type' => 'group', 'limit' => 0); +$groups = elgg_get_entities($params); +if ($groups) { +	foreach ($groups as $group) { +		$acl = $group->group_acl; + +		$query = "SELECT u.guid FROM {$CONFIG->dbprefix}users_entity u +			JOIN {$CONFIG->dbprefix}entity_relationships r +				ON u.guid = r.guid_one AND r.relationship = 'member' AND r.guid_two = $group->guid +			LEFT JOIN {$CONFIG->dbprefix}access_collection_membership a +				ON u.guid = a.user_guid AND a.access_collection_id = $acl +				WHERE a.user_guid IS NULL"; + +		$results = get_data($query); +		if ($results != FALSE) { +			foreach ($results as $user) { +				$insert = "INSERT INTO {$CONFIG->dbprefix}access_collection_membership +							(user_guid, access_collection_id) VALUES ($user->guid, $acl)"; +				insert_data($insert); +			} +		} +	} +} +elgg_set_ignore_access(FALSE); diff --git a/engine/lib/upgrades/2010070301.php b/engine/lib/upgrades/2010070301.php new file mode 100644 index 000000000..af5c80419 --- /dev/null +++ b/engine/lib/upgrades/2010070301.php @@ -0,0 +1,9 @@ +<?php + +/** + * Group join river view has been renamed + */ + +$query = "UPDATE {$CONFIG->dbprefix}river SET view='river/relationship/member/create' +			WHERE view='river/group/create' AND action_type='join'"; +update_data($query); diff --git a/engine/lib/upgrades/2010071001.php b/engine/lib/upgrades/2010071001.php new file mode 100644 index 000000000..5594493a8 --- /dev/null +++ b/engine/lib/upgrades/2010071001.php @@ -0,0 +1,58 @@ +<?php +/** + *	Change profile image names to use guid rather than username + */ + +/** + * Need the same function to generate a user matrix, but can't call it + * the same thing as the previous update. + * + * @param int $guid User guid. + * + * @return string File matrix + */ +function user_file_matrix_2010071001($guid) { +	// lookup the entity +	$user = get_entity($guid); +	if ($user->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 $ENTITY_CACHE, $CONFIG; +$users = mysql_query("SELECT guid, username FROM {$CONFIG->dbprefix}users_entity +	WHERE username != ''"); +while ($user = mysql_fetch_object($users)) { +	$ENTITY_CACHE = array(); +	_elgg_invalidate_query_cache(); + +	$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..52aa15ef5 --- /dev/null +++ b/engine/lib/upgrades/2010071002.php @@ -0,0 +1,50 @@ +<?php +/** + * Update the notifications based on all friends and access collections + */ + +// loop through all users checking collections and notifications +global $ENTITY_CACHE, $CONFIG; +global $NOTIFICATION_HANDLERS; +$users = mysql_query("SELECT guid, username FROM {$CONFIG->dbprefix}users_entity +	WHERE username != ''"); +while ($user = mysql_fetch_object($users)) { +	$ENTITY_CACHE = array(); +	_elgg_invalidate_query_cache(); + +	$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); +					} +				} +			} +		} +	} +} diff --git a/engine/lib/upgrades/2010111501.php b/engine/lib/upgrades/2010111501.php new file mode 100644 index 000000000..15e4a7d35 --- /dev/null +++ b/engine/lib/upgrades/2010111501.php @@ -0,0 +1,33 @@ +<?php +/** + * Set validation metadata on unvalidated users to false rather than  + * not existing. This is needed because of the change in how validation is + * being handled. + */ + +// turn off system log because of all the metadata this can create +elgg_unregister_event_handler('all', 'all', 'system_log_listener'); +elgg_unregister_event_handler('log', 'systemlog', 'system_log_default_logger'); + +$ia = elgg_set_ignore_access(TRUE); +$hidden_entities = access_get_show_hidden_status(); +access_show_hidden_entities(TRUE); + +$validated_id = get_metastring_id('validated'); +$one_id = get_metastring_id(1); + +$query = "SELECT guid FROM {$CONFIG->dbprefix}entities e +			WHERE e.type = 'user' AND e.enabled = 'no' AND +			NOT EXISTS ( +				SELECT 1 FROM {$CONFIG->dbprefix}metadata md +				WHERE md.entity_guid = e.guid +				AND md.name_id = $validated_id +				AND md.value_id = $one_id)"; + +$user_guids = mysql_query($query); +while ($user_guid = mysql_fetch_object($user_guids)) { +	create_metadata($user_guid->guid, 'validated', false, '', 0, ACCESS_PUBLIC, false); +} + +access_show_hidden_entities($hidden_entities); +elgg_set_ignore_access($ia); diff --git a/engine/lib/upgrades/2010121601.php b/engine/lib/upgrades/2010121601.php new file mode 100644 index 000000000..ad7d26adb --- /dev/null +++ b/engine/lib/upgrades/2010121601.php @@ -0,0 +1,9 @@ +<?php +/** + * Create friends river view has been changed + */ + +$query = "UPDATE {$CONFIG->dbprefix}river  +			SET view='river/relationship/friend/create', action_type='create' +			WHERE view='friends/river/create' AND action_type='friend'"; +update_data($query); diff --git a/engine/lib/upgrades/2010121602.php b/engine/lib/upgrades/2010121602.php new file mode 100644 index 000000000..5b0996b5e --- /dev/null +++ b/engine/lib/upgrades/2010121602.php @@ -0,0 +1,10 @@ +<?php +/** + * Create comment river view has been changed + */ + +$query = "UPDATE {$CONFIG->dbprefix}river +			SET view='river/annotation/generic_comment/create' +			WHERE view='annotation/annotate' AND action_type='comment'"; +update_data($query); + diff --git a/engine/lib/upgrades/2010121701.php b/engine/lib/upgrades/2010121701.php new file mode 100644 index 000000000..375654bac --- /dev/null +++ b/engine/lib/upgrades/2010121701.php @@ -0,0 +1,10 @@ +<?php +/** + * Create group forum topic river view has been changed + */ + +$query = "UPDATE {$CONFIG->dbprefix}river +			SET view='river/object/groupforumtopic/create' +			WHERE view='river/forum/topic/create' AND action_type='create'"; +update_data($query); + diff --git a/engine/lib/upgrades/2010123101.php b/engine/lib/upgrades/2010123101.php new file mode 100644 index 000000000..f4befd1a8 --- /dev/null +++ b/engine/lib/upgrades/2010123101.php @@ -0,0 +1,9 @@ +<?php +/** + * Set default access for older sites + */ + +$access = elgg_get_config('default_access'); +if ($access == false) { +	elgg_save_config('default_access', ACCESS_LOGGED_IN); +} diff --git a/engine/lib/upgrades/2011010101.php b/engine/lib/upgrades/2011010101.php new file mode 100644 index 000000000..f4411ee20 --- /dev/null +++ b/engine/lib/upgrades/2011010101.php @@ -0,0 +1,98 @@ +<?php +/** + * Migrate plugins to the new system using ElggPlugin and private settings + */ + +$old_ia = elgg_set_ignore_access(true); + +$site = get_config('site'); +$old_plugin_order = unserialize($site->pluginorder); +$old_enabled_plugins = $site->enabled_plugins; + +$db_prefix = get_config('dbprefix'); +$plugin_subtype_id = get_subtype_id('object', 'plugin'); + +// easy one first: make sure the the site owns all plugin entities. +$q = "UPDATE {$db_prefix}entities e +	SET owner_guid = $site->guid, container_guid = $site->guid +	WHERE e.type = 'object' AND e.subtype = $plugin_subtype_id"; + +$r = update_data($q); + +// rewrite all plugin:setting:* to ELGG_PLUGIN_USER_SETTING_PREFIX . * +$q = "UPDATE {$db_prefix}private_settings +	SET name = replace(name, 'plugin:settings:', '" . ELGG_PLUGIN_USER_SETTING_PREFIX . "') +	WHERE name LIKE 'plugin:settings:%'"; + +$r = update_data($q); + +// grab current plugin GUIDs to add a temp priority +$q = "SELECT * FROM {$db_prefix}entities e +	JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid +	WHERE e.type = 'object' AND e.subtype = $plugin_subtype_id"; + +$plugins = get_data($q); + +foreach ($plugins as $plugin) { +	$priority = elgg_namespace_plugin_private_setting('internal', 'priority'); +	set_private_setting($plugin->guid, $priority, 0); +} + +// force regenerating plugin entities +elgg_generate_plugin_entities(); + +// set the priorities for all plugins +// this function rewrites it to a normal index so use the current one. +elgg_set_plugin_priorities($old_plugin_order); + +// add relationships for enabled plugins +if ($old_enabled_plugins) { +	// they might only have one plugin enabled. +	if (!is_array($old_enabled_plugins)) { +		$old_enabled_plugins = array($old_enabled_plugins); +	} + +	// sometimes there were problems and you'd get 1000s of enabled plugins. +	$old_enabled_plugins = array_unique($old_enabled_plugins); + +	foreach ($old_enabled_plugins as $plugin_id) { +		$plugin = elgg_get_plugin_from_id($plugin_id); + +		if ($plugin) { +			$plugin->activate(); +		} +	} +} + +// invalidate caches +elgg_invalidate_simplecache(); +elgg_reset_system_cache(); + +// clean up. +remove_metadata($site->guid, 'pluginorder'); +remove_metadata($site->guid, 'enabled_plugins'); + +elgg_set_ignore_access($old_id); + +/** + * @hack + * + * We stop the upgrade at this point because plugins weren't given the chance to + * load due to the new plugin code introduced with Elgg 1.8. Instead, we manually + * set the version and start the upgrade process again. + * + * The variables from upgrade_code() are available because this script was included + */ +if ($upgrade_version > $version) { +	datalist_set('version', $upgrade_version); +} + +// add ourselves to the processed_upgrades. +$processed_upgrades[] = '2011010101.php'; + +$processed_upgrades = array_unique($processed_upgrades); +elgg_set_processed_upgrades($processed_upgrades); + +_elgg_upgrade_unlock(); + +forward('upgrade.php'); diff --git a/engine/lib/upgrades/2011021800-1.8_svn-goodbye_walled_garden-083121a656d06894.php b/engine/lib/upgrades/2011021800-1.8_svn-goodbye_walled_garden-083121a656d06894.php new file mode 100644 index 000000000..40b2c71d5 --- /dev/null +++ b/engine/lib/upgrades/2011021800-1.8_svn-goodbye_walled_garden-083121a656d06894.php @@ -0,0 +1,34 @@ +<?php +/** + * Elgg 1.8-svn upgrade 2011021800 + * goodbye_walled_garden + * + * Removes the Walled Garden plugin in favor of new system settings + */ + +global $CONFIG; + +$access = elgg_set_ignore_access(TRUE); + +if (elgg_is_active_plugin('walledgarden')) { +	disable_plugin('walledgarden'); +	set_config('allow_registration', FALSE); +	set_config('walled_garden', TRUE); +} else { +	set_config('allow_registration', TRUE); +	set_config('walled_garden', FALSE); +} + +// this was for people who manually set the config option +$disable_registration = elgg_get_config('disable_registration'); +if ($disable_registration !== null) { +	$allow_registration = !$disable_registration; +	elgg_save_config('allow_registration', $allow_registration); + +	$site = elgg_get_site_entity(); +	$query = "DELETE FROM {$CONFIG->dbprefix}config +				WHERE name = 'disable_registration' AND site_guid = $site->guid"; +	delete_data($query); +} + +elgg_set_ignore_access($access); diff --git a/engine/lib/upgrades/2011022000-1.8_svn-custom_profile_fields-390ac967b0bb5665.php b/engine/lib/upgrades/2011022000-1.8_svn-custom_profile_fields-390ac967b0bb5665.php new file mode 100644 index 000000000..7561b84ba --- /dev/null +++ b/engine/lib/upgrades/2011022000-1.8_svn-custom_profile_fields-390ac967b0bb5665.php @@ -0,0 +1,59 @@ +<?php +/** + * Elgg 2011010401 upgrade 00 + * custom_profile_fields + * + * Migrate 1.7 style custom profile fields to 1.8 + */ + +$plugin = elgg_get_plugin_from_id('profile'); + +// plugin not installed +if (!$plugin) { +	return true; +} + +$settings = $plugin->getAllSettings(); +// no fields to migrate +if (!$settings['user_defined_fields']) { +	return true; +} + +$order = array(); +$remove_settings = array(); + +// make sure we have a name and type +foreach ($settings as $k => $v) { +	if (!preg_match('/admin_defined_profile_([0-9]+)/i', $k, $matches)) { +		continue; +	} + +	$i = $matches[1]; +	$type_name = "admin_defined_profile_type_$i"; +	$type = elgg_extract($type_name, $settings, null); + +	if ($type) { +		// field name +		elgg_save_config($k, $v); +		// field value +		elgg_save_config($type_name, $type); + +		$order[] = $i; +		$remove_settings[] = $k; +		$remove_settings[] = $type_name; +	} +} + +if ($order) { +	// these will always need to be in order, but there might be gaps +	ksort($order); + +	$order_str = implode(',', $order); +	elgg_save_config('profile_custom_fields', $order_str); + +	foreach ($remove_settings as $name) { +		$plugin->unsetSetting($name); +	} + +	$plugin->unsetSetting('user_defined_fields'); +}
\ No newline at end of file diff --git a/engine/lib/upgrades/2011030700-1.8_svn-blog_status_metadata-4645225d7b440876.php b/engine/lib/upgrades/2011030700-1.8_svn-blog_status_metadata-4645225d7b440876.php new file mode 100644 index 000000000..fe2af9928 --- /dev/null +++ b/engine/lib/upgrades/2011030700-1.8_svn-blog_status_metadata-4645225d7b440876.php @@ -0,0 +1,24 @@ +<?php +/** + * Elgg 1.8-svn upgrade 2011030700 + * blog_status_metadata + * + * Add a "status" metadata entry to every blog entity because in 1.8 you can have status = draft or + * status = published + */ +$ia = elgg_set_ignore_access(true); +$options = array( +	'type' => 'object', +	'subtype' => 'blog', +	'limit' => 0, +); +$batch = new ElggBatch('elgg_get_entities', $options); + +foreach ($batch as $entity) { +	if (!$entity->status) { +		// create metadata owned by the original owner +		create_metadata($entity->getGUID(), 'status', 'published', '', $entity->owner_guid, +			$entity->access_id); +	} +} +elgg_set_ignore_access($ia);
\ No newline at end of file diff --git a/engine/lib/upgrades/2011031300-1.8_svn-twitter_api-12b832a5a7a3e1bd.php b/engine/lib/upgrades/2011031300-1.8_svn-twitter_api-12b832a5a7a3e1bd.php new file mode 100644 index 000000000..df60892a6 --- /dev/null +++ b/engine/lib/upgrades/2011031300-1.8_svn-twitter_api-12b832a5a7a3e1bd.php @@ -0,0 +1,54 @@ +<?php +/** + * Elgg 1.8-svn upgrade 2011031300 + * twitter_api + * + * Updates the database for twitterservice to twitter_api changes. + */ + + +$ia = elgg_set_ignore_access(true); + +// make sure we have updated plugins +elgg_generate_plugin_entities(); + +$show_hidden = access_get_show_hidden_status(); +access_show_hidden_entities(true); + +$db_prefix = elgg_get_config('dbprefix'); +$site_guid = elgg_get_site_entity()->getGUID(); +$old = elgg_get_plugin_from_id('twitterservice'); +$new = elgg_get_plugin_from_id('twitter_api'); +$has_settings = false; + +// if not loaded, don't bother. +if (!$old || !$new) { +	return true; +} + +$settings = array('consumer_key', 'consumer_secret', 'sign_on', 'new_users'); + +foreach ($settings as $setting) { +	$value = $old->getSetting($setting); +	if ($value) { +		$has_settings = true; +		$new->setSetting($setting, $value); +	} +} + +// update the user settings +$q = "UPDATE {$db_prefix}private_settings +	SET name = replace(name, 'twitterservice', 'twitter_api') +	WHERE name like '%twitterservice%'"; + +update_data($q); + +// if there were settings, emit a notice to re-enable twitter_api +if ($has_settings) { +	elgg_add_admin_notice('twitter_api:disabled', elgg_echo('update:twitter_api:deactivated')); +} + +$old->delete(); + +access_show_hidden_entities($show_hidden); +elgg_set_ignore_access($ia);
\ No newline at end of file diff --git a/engine/lib/upgrades/2011031600-1.8_svn-datalist_grows_up-0b8aec5a55cc1e1c.php b/engine/lib/upgrades/2011031600-1.8_svn-datalist_grows_up-0b8aec5a55cc1e1c.php new file mode 100644 index 000000000..379244b36 --- /dev/null +++ b/engine/lib/upgrades/2011031600-1.8_svn-datalist_grows_up-0b8aec5a55cc1e1c.php @@ -0,0 +1,18 @@ +<?php +/** + * Elgg 1.8-svn upgrade 2011031600 + * datalist_grows_up + * + * Ups the varchar to 256 for the datalist and config table. + * + * Keeping it as a varchar because of the trailing whitespace trimming it apparently does: + * http://dev.mysql.com/doc/refman/5.0/en/char.html + */ + +$db_prefix = elgg_get_config('dbprefix'); + +$q = "ALTER TABLE {$db_prefix}datalists CHANGE name name VARCHAR(255)"; +update_data($q); + +$q = "ALTER TABLE {$db_prefix}config CHANGE name name VARCHAR(255)"; +update_data($q); diff --git a/engine/lib/upgrades/2011032000-1.8_svn-widgets_arent_plugins-61836261fa280a5c.php b/engine/lib/upgrades/2011032000-1.8_svn-widgets_arent_plugins-61836261fa280a5c.php new file mode 100644 index 000000000..a20970d79 --- /dev/null +++ b/engine/lib/upgrades/2011032000-1.8_svn-widgets_arent_plugins-61836261fa280a5c.php @@ -0,0 +1,10 @@ +<?php +/** + * Elgg 1.8-svn upgrade 2011031800 + * widgets_arent_plugins + * + * At some point in Elgg's history subtype widget was registered with class ElggPlugin. + * Fix that. + */ + +update_subtype('object', 'widget', 'ElggWidget'); diff --git a/engine/lib/upgrades/2011032200-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php b/engine/lib/upgrades/2011032200-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php new file mode 100644 index 000000000..592adb403 --- /dev/null +++ b/engine/lib/upgrades/2011032200-1.8_svn-admins_like_widgets-7f19d2783c1680d3.php @@ -0,0 +1,13 @@ +<?php +/** + * Elgg 1.8-svn upgrade 2011032200 + * admins_like_widgets + * + * Give current admins widgets for those pre-1.8 + */ + +$admins = elgg_get_admins(array('limit' => 0)); +foreach ($admins as $admin) { +	// call the admin handler for the make_admin event +	elgg_add_admin_widgets('make_admin', 'user', $admin); +} diff --git a/engine/lib/upgrades/2011052801.php b/engine/lib/upgrades/2011052801.php new file mode 100644 index 000000000..b5a8e1018 --- /dev/null +++ b/engine/lib/upgrades/2011052801.php @@ -0,0 +1,46 @@ +<?php +/** + * Make sure all users have the relationship member_of_site + */ +global $ENTITY_CACHE; +$db_prefix = get_config('dbprefix'); + +$limit = 100; + +$q = "SELECT e.* FROM {$db_prefix}entities e +	WHERE e.type = 'user' AND e.guid NOT IN ( +		SELECT guid_one FROM {$db_prefix}entity_relationships +			WHERE guid_two = 1 AND relationship = 'member_of_site' +		) +	LIMIT $limit"; + +$users = get_data($q); + +while ($users) { +	$ENTITY_CACHE = array(); +	_elgg_invalidate_query_cache(); + +	// do manually to not trigger any events because these aren't new users. +	foreach ($users as $user) { +		$rel_q = "INSERT INTO {$db_prefix}entity_relationships VALUES ( +			'', +			'$user->guid', +			'member_of_site', +			'$user->site_guid', +			'$user->time_created' +		)"; + +		insert_data($rel_q); +	} + +	// every time we run this query we've just reduced the rows it returns by $limit +	// so don't pass an offset. +	$q = "SELECT e.* FROM {$db_prefix}entities e +		WHERE e.type = 'user' AND e.guid NOT IN ( +			SELECT guid_one FROM {$db_prefix}entity_relationships +				WHERE guid_two = 1 AND relationship = 'member_of_site' +			) +		LIMIT $limit"; + +	$users = get_data($q); +}
\ No newline at end of file diff --git a/engine/lib/upgrades/2011061200-1.8b1-sites_need_a_site_guid-6d9dcbf46c0826cc.php b/engine/lib/upgrades/2011061200-1.8b1-sites_need_a_site_guid-6d9dcbf46c0826cc.php new file mode 100644 index 000000000..41ab29998 --- /dev/null +++ b/engine/lib/upgrades/2011061200-1.8b1-sites_need_a_site_guid-6d9dcbf46c0826cc.php @@ -0,0 +1,31 @@ +<?php +/** + * Elgg 1.8b1 upgrade 2011061200 + * sites_need_a_site_guid + * + * Sites did not have a site guid. This causes problems with getting + * metadata on site objects since we default to the current site. + */ + +global $CONFIG; + +$ia = elgg_set_ignore_access(true); +$access_status = access_get_show_hidden_status(); +access_show_hidden_entities(true); + +$options = array( +	'type' => 'site', +	'site_guid' => 0, +	'limit' => 0, +); +$batch = new ElggBatch('elgg_get_entities', $options); + +foreach ($batch as $entity) { +	if (!$entity->site_guid) { +		update_data("UPDATE {$CONFIG->dbprefix}entities SET site_guid=$entity->guid +				WHERE guid=$entity->guid"); +	} +} + +access_show_hidden_entities($access_status); +elgg_set_ignore_access($ia); diff --git a/engine/lib/upgrades/2011092500-1.8.0.1-forum_reply_river_view-5758ce8d86ac56ce.php b/engine/lib/upgrades/2011092500-1.8.0.1-forum_reply_river_view-5758ce8d86ac56ce.php new file mode 100644 index 000000000..3a9200b51 --- /dev/null +++ b/engine/lib/upgrades/2011092500-1.8.0.1-forum_reply_river_view-5758ce8d86ac56ce.php @@ -0,0 +1,12 @@ +<?php +/** + * Elgg 1.8.0.1 upgrade 2011092500 + * forum_reply_river_view + * + * The forum reply river view is in a new location in Elgg 1.8 + */ + +$query = "UPDATE {$CONFIG->dbprefix}river SET view='river/annotation/group_topic_post/reply', +			action_type='reply' +			WHERE view='river/forum/create' AND action_type='create'"; +update_data($query); diff --git a/engine/lib/upgrades/2011123100-1.8.2-fix_friend_river-b17e7ff8345c2269.php b/engine/lib/upgrades/2011123100-1.8.2-fix_friend_river-b17e7ff8345c2269.php new file mode 100644 index 000000000..4dc43cd32 --- /dev/null +++ b/engine/lib/upgrades/2011123100-1.8.2-fix_friend_river-b17e7ff8345c2269.php @@ -0,0 +1,12 @@ +<?php +/** + * Elgg 1.8.2 upgrade 2011123100 + * fix_friend_river + * + * Action type was incorrect due to previoud friends river upgrade + */ + +$query = "UPDATE {$CONFIG->dbprefix}river +			SET action_type='friend' +			WHERE view='river/relationship/friend/create' AND action_type='create'"; +update_data($query); diff --git a/engine/lib/upgrades/2011123101-1.8.2-fix_blog_status-b14c2a0e7b9e7d55.php b/engine/lib/upgrades/2011123101-1.8.2-fix_blog_status-b14c2a0e7b9e7d55.php new file mode 100644 index 000000000..e351c6ac9 --- /dev/null +++ b/engine/lib/upgrades/2011123101-1.8.2-fix_blog_status-b14c2a0e7b9e7d55.php @@ -0,0 +1,25 @@ +<?php +/** + * Elgg 1.8.2 upgrade 2011123101 + * fix_blog_status + * + * Most blog posts did not have their status properly set with 1.8 upgrade so we run + * the blog status upgrade again + */ + +$ia = elgg_set_ignore_access(true); +$options = array( +	'type' => 'object', +	'subtype' => 'blog', +	'limit' => 0, +); +$batch = new ElggBatch('elgg_get_entities', $options); + +foreach ($batch as $entity) { +	if (!$entity->status) { +		// create metadata owned by the original owner +		create_metadata($entity->getGUID(), 'status', 'published', '', $entity->owner_guid, +			$entity->access_id); +	} +} +elgg_set_ignore_access($ia);
\ No newline at end of file diff --git a/engine/lib/upgrades/2012012000-1.8.3-ip_in_syslog-87fe0f068cf62428.php b/engine/lib/upgrades/2012012000-1.8.3-ip_in_syslog-87fe0f068cf62428.php new file mode 100644 index 000000000..b9514e156 --- /dev/null +++ b/engine/lib/upgrades/2012012000-1.8.3-ip_in_syslog-87fe0f068cf62428.php @@ -0,0 +1,12 @@ +<?php +/** + * Elgg 1.8.3 upgrade 2012012000 + * ip_in_syslog + * + * Adds a field for an IP address in the system log table + */ + +$db_prefix = elgg_get_config('dbprefix'); +$q = "ALTER TABLE {$db_prefix}system_log ADD ip_address VARCHAR(15) NOT NULL AFTER time_created"; + +update_data($q);
\ No newline at end of file diff --git a/engine/lib/upgrades/2012012100-1.8.3-system_cache-93100e7d55a24a11.php b/engine/lib/upgrades/2012012100-1.8.3-system_cache-93100e7d55a24a11.php new file mode 100644 index 000000000..3a9aae2a1 --- /dev/null +++ b/engine/lib/upgrades/2012012100-1.8.3-system_cache-93100e7d55a24a11.php @@ -0,0 +1,13 @@ +<?php +/** + * Elgg 1.8.3 upgrade 2012012100 + * system_cache + * + * Convert viewpath cache to system cache + */ + +$value = datalist_get('viewpath_cache_enabled'); +datalist_set('system_cache_enabled', $value); + +$query = "DELETE FROM {$CONFIG->dbprefix}datalists WHERE name='viewpath_cache_enabled'"; +delete_data($query); diff --git a/engine/lib/upgrades/2012041800-1.8.3-dont_filter_passwords-c0ca4a18b38ae2bc.php b/engine/lib/upgrades/2012041800-1.8.3-dont_filter_passwords-c0ca4a18b38ae2bc.php new file mode 100644 index 000000000..b82ffbebf --- /dev/null +++ b/engine/lib/upgrades/2012041800-1.8.3-dont_filter_passwords-c0ca4a18b38ae2bc.php @@ -0,0 +1,11 @@ +<?php +/** + * Elgg 1.8.3 upgrade 2012041800 + * dont_filter_passwords + * + * Add admin notice that password handling has changed and if  + * users can't login to have them reset their passwords. + */ +elgg_add_admin_notice('dont_filter_passwords', 'Password handling has been updated to be more secure and flexible. ' +	. 'This change may prevent a small number of users from logging in with their existing passwords. ' +	. 'If a user is unable to log in, please advise him or her to reset their password, or reset it as an admin user.'); diff --git a/engine/lib/upgrades/2012041801-1.8.3-multiple_user_tokens-852225f7fd89f6c5.php b/engine/lib/upgrades/2012041801-1.8.3-multiple_user_tokens-852225f7fd89f6c5.php new file mode 100644 index 000000000..780038c32 --- /dev/null +++ b/engine/lib/upgrades/2012041801-1.8.3-multiple_user_tokens-852225f7fd89f6c5.php @@ -0,0 +1,13 @@ +<?php +/** + * Elgg 1.8.3 upgrade 2012041801 + * multiple_user_tokens + * + * Fixes https://github.com/elgg/elgg/issues/4291 + * Removes the unique index on users_apisessions for user_guid and site_guid + */ + +$db_prefix = elgg_get_config('dbprefix'); +$q = "ALTER TABLE {$db_prefix}users_apisessions DROP INDEX user_guid, +	ADD INDEX user_guid (user_guid, site_guid)"; +update_data($q);
\ No newline at end of file diff --git a/engine/lib/upgrades/2013030600-1.8.13-update_user_location-8999eb8bf1bdd9a3.php b/engine/lib/upgrades/2013030600-1.8.13-update_user_location-8999eb8bf1bdd9a3.php new file mode 100644 index 000000000..8eccf05e2 --- /dev/null +++ b/engine/lib/upgrades/2013030600-1.8.13-update_user_location-8999eb8bf1bdd9a3.php @@ -0,0 +1,24 @@ +<?php +/** + * Elgg 1.8.14 upgrade 2013030600 + * update_user_location + * + * Before Elgg 1.8, a location like "London, England" would be stored as an array. + * This script turns that back into a string. + */ + +$ia = elgg_set_ignore_access(true); +$options = array( +	'type' => 'user', +	'limit' => 0, +); +$batch = new ElggBatch('elgg_get_entities', $options); + +foreach ($batch as $entity) { +	_elgg_invalidate_query_cache(); +	 +	if (is_array($entity->location)) { +		$entity->location = implode(', ', $entity->location); +	} +} +elgg_set_ignore_access($ia); diff --git a/engine/lib/upgrades/2013051700-1.8.15-add_missing_group_index-52a63a3a3ffaced2.php b/engine/lib/upgrades/2013051700-1.8.15-add_missing_group_index-52a63a3a3ffaced2.php new file mode 100644 index 000000000..ee99bdbc8 --- /dev/null +++ b/engine/lib/upgrades/2013051700-1.8.15-add_missing_group_index-52a63a3a3ffaced2.php @@ -0,0 +1,28 @@ +<?php +/** + * Elgg 1.8.15 upgrade 2013051700 + * add_missing_group_index + * + * Some Elgg sites are missing the groups_entity full text index on name and + * description. This checks if it exists and adds it if it does not. + */ + +$db_prefix = elgg_get_config('dbprefix'); + +$full_text_index_exists = false; +$results = get_data("SHOW INDEX FROM {$db_prefix}groups_entity"); +if ($results) { +	foreach ($results as $result) { +		if ($result->Index_type === 'FULLTEXT') { +			$full_text_index_exists = true; +		} +	} +} + +if ($full_text_index_exists == false) { +	$query = "ALTER TABLE {$db_prefix}groups_entity  +		ADD FULLTEXT name_2 (name, description)"; +	if (!update_data($query)) { +		elgg_log("Failed to add full text index to groups_entity table", 'ERROR'); +	} +} diff --git a/engine/lib/upgrades/2013052900-1.8.15-ipv6_in_syslog-f5c2cc0196e9e731.php b/engine/lib/upgrades/2013052900-1.8.15-ipv6_in_syslog-f5c2cc0196e9e731.php new file mode 100644 index 000000000..d333a6cd2 --- /dev/null +++ b/engine/lib/upgrades/2013052900-1.8.15-ipv6_in_syslog-f5c2cc0196e9e731.php @@ -0,0 +1,12 @@ +<?php +/** + * Elgg 1.8.15 upgrade 2013052900 + * ipv6_in_syslog + * + * Upgrade the ip column in system_log to be able to store ipv6 addresses + */ + +$db_prefix = elgg_get_config('dbprefix'); +$q = "ALTER TABLE {$db_prefix}system_log MODIFY COLUMN ip_address varchar(46) NOT NULL"; + +update_data($q);
\ No newline at end of file diff --git a/engine/lib/upgrades/2013060900-1.8.15-site_secret-404fc165cf9e0ac9.php b/engine/lib/upgrades/2013060900-1.8.15-site_secret-404fc165cf9e0ac9.php new file mode 100644 index 000000000..538d74dd6 --- /dev/null +++ b/engine/lib/upgrades/2013060900-1.8.15-site_secret-404fc165cf9e0ac9.php @@ -0,0 +1,16 @@ +<?php +/** + * Elgg 1.8.15 upgrade 2013060900 + * site_secret + * + * Description + */ + +$strength = _elgg_get_site_secret_strength(); + +if ($strength !== 'strong') { +	// a new key is needed immediately +	register_translations(elgg_get_root_path() . 'languages/'); + +	elgg_add_admin_notice('weak_site_key', elgg_echo("upgrade:site_secret_warning:$strength")); +} diff --git a/engine/lib/upgrades/create_upgrade.php b/engine/lib/upgrades/create_upgrade.php new file mode 100644 index 000000000..b34f31b7e --- /dev/null +++ b/engine/lib/upgrades/create_upgrade.php @@ -0,0 +1,152 @@ +<?php +/** + * Creates an upgrade file for Elgg. + * + * Run this from the command line: + * 	php create_upgrade.php upgrade_name + */ + +error_reporting(E_NOTICE); + +// only allow from the command line. +if (php_sapi_name() != 'cli') { +	die('Upgrades can only be created from the command line.'); +} + +if (count($argv) < 2) { +	elgg_create_upgrade_show_usage('No upgrade name.'); +} + +$name = $argv[1]; + +if (strlen($name) > 24) { +	elgg_create_upgrade_show_usage('Upgrade names cannot be longer than 24 characters.'); +} + +require_once '../../../version.php'; +require_once '../elgglib.php'; +$upgrade_path = dirname(__FILE__); + +$upgrade_name = strtolower($name); +$upgrade_name = str_replace(array(' ', '-'), '_', $upgrade_name); +$upgrade_release = str_replace(array(' ', '-'), '_', $release); +$time = time(); +$upgrade_rnd = substr(md5($time), 0, 16); +$upgrade_date = date('Ymd', $time); + +// determine the inc count +$upgrade_inc = 0; +$files = elgg_get_file_list($upgrade_path); +sort($files); + +foreach ($files as $filename) { +	$filename = basename($filename); +	$date = (int)substr($filename, 0, 8); +	$inc = (int)substr($filename, 8, 2); + +	if ($upgrade_date == $date) { +		if ($inc >= $upgrade_inc) { +			$upgrade_inc = $inc + 1; +		} +	} +} + +// zero-pad +// if there are more than 10 upgrades in a day, someone needs talking to. +if ($upgrade_inc < 10) { +	$upgrade_inc = "0$upgrade_inc"; +} + +$upgrade_version = $upgrade_date . $upgrade_inc; + +// make filename +if (substr($release, 0, 3) == '1.7') { +	// 1.7 upgrades are YYYYMMDDXX +	$upgrade_name = $upgrade_version . '.php'; +} else { +	// 1.8+ upgrades are YYYYMMDDXX-release-friendly_name-rnd +	$upgrade_name = $upgrade_version . "-$upgrade_release-$name-$upgrade_rnd.php"; +} + +$upgrade_file = $upgrade_path . '/' . $upgrade_name; + +if (is_file($upgrade_file)) { +	elgg_create_upgrade_show_usage("Upgrade file $upgrade_file already exists. This script has failed you."); +} + +$upgrade_code = <<<___UPGRADE +<?php +/** + * Elgg $release upgrade $upgrade_version + * $name + * + * Description + */ + +// upgrade code here. + +___UPGRADE; + +$h = fopen($upgrade_file, 'wb'); + +if (!$h) { +	die("Could not open file $upgrade_file"); +} + +if (!fwrite($h, $upgrade_code)) { +	die("Could not write to $upgrade_file"); +} else { +	elgg_set_version_dot_php_version($upgrade_version); +	echo <<<___MSG + +Created upgrade file and updated version.php. + +Upgrade file: $upgrade_name +Version:      $upgrade_version + +___MSG; +} + +fclose($h); + + +function elgg_set_version_dot_php_version($version) { +	$file = '../../../version.php'; +	$h = fopen($file, 'r+b'); + +	if (!$h) { +		return false; +	} + +	$out = ''; + +	while (($line = fgets($h)) !== false) { +		$find = "/\\\$version[ ]?=[ ]?[0-9]{10};/"; +		$replace = "\$version = $version;"; +		$out .= preg_replace($find, $replace, $line); +	} + +	rewind($h); + +	fwrite($h, $out); +	fclose($h); +	return true; +} + +/** + * Shows the usage for the create_upgrade script and dies(). + * + * @param string $msg Optional message to display + * @return void + */ +function elgg_create_upgrade_show_usage($msg = '') { +	$text = <<<___MSG +$msg + +Example: +	php create_upgrade.php my_upgrade + +___MSG; + +	die($text); +} | 
