Index: trunk/admin/install/install_lib.php =================================================================== diff -u -N -r4885 -r6093 --- trunk/admin/install/install_lib.php (.../install_lib.php) (revision 4885) +++ trunk/admin/install/install_lib.php (.../install_lib.php) (revision 6093) @@ -36,7 +36,7 @@ } else { - return ($a_extension == 'php') ? 1 : -1; + return ($a_extension == 'php') ? 1 : -1; // this makes .php extension go AFTER .sql in the sorting } } else @@ -49,6 +49,8 @@ { $dir = @dir($admindirname.'/install/upgrades'); + if (!$dir) return ''; + $upgrades_arr = Array(); $version = ''; @@ -926,7 +928,7 @@ $app->Redirect('', Array('pass' => 'all', 'admin' => 1, 'Refresh' => 1), '', 'modules/mod_status.php'); } - + /** * [UPGRADE] Initializes [cached] category/item templates with default values for each module * @@ -938,26 +940,26 @@ { $table_prefix = GetTablePrefix(); $inst_ado =& inst_GetADODBConnection(); - + // get module root category by module name $sql = 'SELECT RootCat FROM '.$table_prefix.'Modules WHERE Name = '.$inst_ado->qstr($module); $module_root = $inst_ado->GetOne($sql); - + // set category & item template to module root category $sql = 'UPDATE '.$table_prefix.'Category - SET CategoryTemplate = '.$inst_ado->qstr($category_template).', ItemTemplate = '.$inst_ado->qstr($item_template).' + SET CategoryTemplate = '.$inst_ado->qstr($category_template).' WHERE CategoryId = '.$module_root; $inst_ado->Execute($sql); - + // set cached category & item templates to all sub-categories of module root category $sql = 'UPDATE '.$table_prefix.'Category - SET CachedCategoryTemplate = '.$inst_ado->qstr($category_template).', CachedItemTemplate = '.$inst_ado->qstr($item_template).' + SET CachedCategoryTemplate = '.$inst_ado->qstr($category_template).' WHERE ParentPath LIKE "|'.$module_root.'|%'; $inst_ado->Execute($sql); } - + /** * [UPGRADE] Moves custom field values for prefix specified from CustomMetaData table to prefix dependant separate table * @@ -966,50 +968,50 @@ function convertCustomFields($prefix) { $application =& kApplication::Instance(); - + $ml_helper =& $application->recallObject('kMultiLanguageHelper'); $ml_helper->createFields($prefix.'-cdata', true); - + $db =& $application->GetADODBConnection(); - + $custom_fields = $application->getUnitOption($prefix, 'CustomFields'); if (!$custom_fields) { return true; } - + $custom_table = $application->getUnitOption($prefix.'-cdata', 'TableName'); - + // copy value from Value field to l_Value field, where destination field is empty $m_lang = $application->GetVar('m_lang'); $sql = 'UPDATE '.TABLE_PREFIX.'CustomMetaData SET l'.$m_lang.'_Value = Value WHERE LENGTH(l'.$m_lang.'_Value) = 0'; $db->Query($sql); - + $i = 1; $field_mask = ''; $language_count = $ml_helper->getLanguageCount(); while ($i <= $language_count) { - $field_mask .= 'cdata%1$s.l'.$i.'_Value AS l'.$i.'_cust_%1$s, '; + $field_mask .= 'cdata%1$s.l'.$i.'_Value AS l'.$i.'_cust_%1$s, '; $i++; } $field_mask = preg_replace('/(.*), $/', '\\1', $field_mask); - + $join_mask = 'LEFT JOIN '.TABLE_PREFIX.'CustomMetaData cdata%1$s ON main_table.ResourceId = cdata%1$s.ResourceId AND cdata%1$s.CustomFieldId = %1$s'; - + $fields_sql = Array(); $joins_sql = Array(); foreach ($custom_fields as $custom_id => $custom_name) { array_push($fields_sql, sprintf($field_mask, $custom_id) ); array_push($joins_sql, sprintf($join_mask, $custom_id)); } - - $sql = 'INSERT INTO '.$custom_table.' + + $sql = 'INSERT INTO '.$custom_table.' SELECT 0 AS CustomDataId, main_table.ResourceId, '.implode(', ', $fields_sql).' FROM '.$application->getUnitOption($prefix, 'TableName').' main_table '.implode(' ', $joins_sql); $db->Query($sql); } - + /** * [INSTALL] Link custom field records with search config records + create custom field columns * @@ -1030,15 +1032,46 @@ WHERE (TableName = "CustomField") AND (LOWER(ModuleName) = "'.strtolower($module_name).'") AND (FieldName = '.$db->qstr($cf_name).')'; $db->Query($sql); } - + $application->refreshModuleInfo(); // this module configs are now processed - + // because of configs was read only from installed before modules (in-portal), then reread configs $unit_config_reader =& $application->recallObject('kUnitConfigReader'); $unit_config_reader->scanModules(MODULES_PATH.'/'.strtolower($module_name)); - + // create correct columns in ProductsCustomData table $ml_helper =& $application->recallObject('kMultiLanguageHelper'); $ml_helper->createFields($prefix.'-cdata', true); } + + function moveItemTemplatesToCustom($module_name, $prefix) + { + $application =& kApplication::Instance(); + $root_parent_path = $application->Conn->GetOne( + 'SELECT ParentPath FROM '.TABLE_PREFIX.'Category + WHERE CategoryId = '.$application->ModuleInfo[$module_name]['RootCat']); + $item_t_customfield = $application->Conn->GetOne('SELECT CustomFieldId FROM '.TABLE_PREFIX.'CustomField WHERE FieldName = \''.$prefix.'_ItemTemplate\''); + $item_t_customfield = 'l1_cust_'.$item_t_customfield; + + $current_item_tpls = $application->Conn->Query( + 'SELECT ResourceId, ItemTemplate FROM '.TABLE_PREFIX.'Category + WHERE ParentPath LIKE "'.$root_parent_path.'%" AND ItemTemplate != "" AND ItemTemplate IS NOT NULL'); + + foreach ($current_item_tpls as $a_cat) { + $has_cdata = $application->Conn->GetOne( + 'SELECT CustomDataId FROM '.TABLE_PREFIX.'CategoryCustomData + WHERE ResourceId = '.$a_cat['ResourceId']); + + if (!$has_cdata) { + $query = 'INSERT INTO '.TABLE_PREFIX.'CategoryCustomData (ResourceId) VALUES ('.$a_cat['ResourceId'].')'; + $application->Conn->Query($query); + } + + $query = 'UPDATE '.TABLE_PREFIX.'CategoryCustomData + SET '.$item_t_customfield.' = '.$application->Conn->qstr($a_cat['ItemTemplate']).' + WHERE ResourceId = '.$a_cat['ResourceId']; + $application->Conn->Query($query); + } + + } ?>