Index: branches/5.2.x/core/install/upgrades.php =================================================================== diff -u -N -r14588 -r14697 --- branches/5.2.x/core/install/upgrades.php (.../upgrades.php) (revision 14588) +++ branches/5.2.x/core/install/upgrades.php (.../upgrades.php) (revision 14697) @@ -1,6 +1,6 @@ Conn->Query($sql); } } + + /** + * Update to 5.2.0-B1; Transform list sortings storage + * + * @param string $mode when called mode {before, after) + */ + public function Upgrade_5_2_0_B1($mode) + { + if ($mode == 'after') { + $this->transformSortings(); + } + } + + /** + * Transforms a way, how list sortings are stored + * + * @return void + */ + function transformSortings() + { + $sql = 'SELECT VariableName, PortalUserId + FROM ' . TABLE_PREFIX . 'PersistantSessionData + WHERE VariableName LIKE "%_Sort1.%"'; + $sortings = $this->Conn->Query($sql); + + foreach ($sortings AS $sorting) { + if ( !preg_match('/^(.*)_Sort1.(.*)$/', $sorting['VariableName'], $regs) ) { + continue; + } + + $user_id = $sorting['PortalUserId']; + $prefix_special = $regs[1] . '_'; + $view_name = '.' . $regs[2]; + + $old_variable_names = Array ( + $prefix_special . 'Sort1' . $view_name, $prefix_special . 'Sort1_Dir' . $view_name, + $prefix_special . 'Sort2' . $view_name, $prefix_special . 'Sort2_Dir' . $view_name, + ); + $old_variable_names = array_map(Array (&$this->Conn, 'qstr'), $old_variable_names); + + $sql = 'SELECT VariableValue, VariableName + FROM ' . TABLE_PREFIX . 'PersistantSessionData + WHERE PortalUserId = ' . $user_id . ' AND VariableName IN (' . implode(',', $old_variable_names) . ')'; + $sorting_data = $this->Conn->GetCol($sql, 'VariableName'); + + // prepare & save new sortings + $new_sorting = Array ( + 'Sort1' => $sorting_data[$prefix_special . 'Sort1' . $view_name], + 'Sort1_Dir' => $sorting_data[$prefix_special . 'Sort1_Dir' . $view_name], + ); + + if ( isset($sorting_data[$prefix_special . 'Sort2' . $view_name]) ) { + $new_sorting['Sort2'] = $sorting_data[$prefix_special . 'Sort2' . $view_name]; + $new_sorting['Sort2_Dir'] = $sorting_data[$prefix_special . 'Sort2_Dir' . $view_name]; + } + + $fields_hash = Array ( + 'PortalUserId' => $user_id, + 'VariableName' => $prefix_special . 'Sortings' . $view_name, + 'VariableValue' => serialize($new_sorting), + ); + + $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'PersistantSessionData'); + + // delete sortings, that were already processed + $sql = 'DELETE FROM ' . TABLE_PREFIX . 'PersistantSessionData + WHERE PortalUserId = ' . $user_id . ' AND VariableName IN (' . implode(',', $old_variable_names) . ')'; + $this->Conn->Query($sql); + } + } } \ No newline at end of file