From 53305ecf5ccd83618faebedb1ae9ef8e0ce61d8c Mon Sep 17 00:00:00 2001 From: brettp Date: Fri, 18 Jun 2010 21:19:11 +0000 Subject: Merged r6506:6509 from 1.7 to trunk. git-svn-id: http://code.elgg.org/elgg/trunk@6516 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/upgrades/2010061501.php | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 engine/lib/upgrades/2010061501.php (limited to 'engine/lib/upgrades/2010061501.php') diff --git a/engine/lib/upgrades/2010061501.php b/engine/lib/upgrades/2010061501.php new file mode 100644 index 000000000..19d6467ed --- /dev/null +++ b/engine/lib/upgrades/2010061501.php @@ -0,0 +1,70 @@ +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, 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, 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 $DB_QUERY_CACHE, $DB_PROFILE, $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)) { + $DB_QUERY_CACHE = $DB_PROFILE = $ENTITY_CACHE = array(); + + $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'); + } + } + } +} \ No newline at end of file -- cgit v1.2.3