Index: branches/5.1.x/core/install/upgrades.php =================================================================== diff -u -r13824 -r13890 --- branches/5.1.x/core/install/upgrades.php (.../upgrades.php) (revision 13824) +++ branches/5.1.x/core/install/upgrades.php (.../upgrades.php) (revision 13890) @@ -1,6 +1,6 @@ Conn->Query($sql); } } + + /** + * Update to 5.1.1-B1; Transforms DisplayToPublic logic + * + * @param string $mode when called mode {before, after) + */ + function Upgrade_5_1_1_B1($mode) + { + if ($mode == 'after') { + $this->processDisplayToPublic(); + } + } + + function processDisplayToPublic() + { + $profile_mapping = Array ( + 'pp_firstname' => 'FirstName', + 'pp_lastname' => 'LastName', + 'pp_dob' => 'dob', + 'pp_email' => 'Email', + 'pp_phone' => 'Phone', + 'pp_street' => 'Street', + 'pp_city' => 'City', + 'pp_state' => 'State', + 'pp_zip' => 'Zip', + 'pp_country' => 'Country', + ); + + $fields = array_keys($profile_mapping); + $fields = array_map(Array (&$this->Conn, 'qstr'), $fields); + $where_clause = 'VariableName IN (' . implode(',', $fields) . ')'; + + // 1. get user, that have saved their profile at least once + $sql = 'SELECT DISTINCT PortalUserId + FROM ' . TABLE_PREFIX . 'PersistantSessionData + WHERE ' . $where_clause; + $users = $this->Conn->GetCol($sql); + + foreach ($users as $user_id) { + // 2. convert to new format + $sql = 'SELECT VariableValue, VariableName + FROM ' . TABLE_PREFIX . 'PersistantSessionData + WHERE (PortalUserId = ' . $user_id . ') AND ' . $where_clause; + $user_variables = $this->Conn->GetCol($sql, 'VariableName'); + + // go through mapping to preserve variable order + $value = Array (); + + foreach ($profile_mapping as $from_name => $to_name) { + if (array_key_exists($from_name, $user_variables) && $user_variables[$from_name]) { + $value[] = $to_name; + } + } + + if ($value) { + $fields_hash = Array ( + 'DisplayToPublic' => '|' . implode('|', $value) . '|', + ); + + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'PortalUser', 'PortalUserId = ' . $user_id); + } + + // 3. delete old style variables + $sql = 'DELETE FROM ' . TABLE_PREFIX . 'PersistantSessionData + WHERE (PortalUserId = ' . $user_id . ') AND ' . $where_clause; + $this->Conn->Query($sql); + } + } } \ No newline at end of file