Index: trunk/admin/install/upgrades/inportal_upgrade_v1.1.4.php =================================================================== diff -u -r3244 -r3440 --- trunk/admin/install/upgrades/inportal_upgrade_v1.1.4.php (.../inportal_upgrade_v1.1.4.php) (revision 3244) +++ trunk/admin/install/upgrades/inportal_upgrade_v1.1.4.php (.../inportal_upgrade_v1.1.4.php) (revision 3440) @@ -7,7 +7,113 @@ $modules_list = GetModuleArray(); $path = $pathtoroot.$modules_list[$module_prefix].'admin/include/parser.php'; if ( file_exists($path) ) include_once($path); - + + + // !!! do not use variable $rs as record-set; + // rid - ResourceId + + $rid_modules=GetModuleArray(); + foreach($rid_modules as $rid_module_name) + { + $rid_path=$pathtoroot.$rid_module_name.'admin/include/parser.php'; + if(file_exists($rid_path)) include_once($rid_path); + } + + function dupe_ResourceIDs_check() + { + global $objModules, $ado; + + // 1. get required info about each module installed + $ret=Array(); + $table_info=$objModules->ExecuteFunction('GetModuleInfo', 'dupe_resourceids'); + + foreach($table_info as $module_name => $module_info) + { + foreach($module_info as $module_sub_info) + { + $module_sub_info['Module']=$module_name; + array_push($ret,$module_sub_info); + } + } + + // 2. build mega sql joining all tables in on and search resource id throught them + $ado->Execute('DROP TABLE IF EXISTS '.GetTablePrefix().'DupeRIDs'); + + $sql = Array(); + $sql_template = 'SELECT %1$s AS ID, \'%1$s\' AS IDField, ResourceId, \'%2$s\' AS TableName, \'%3$s\' AS Module FROM '.GetTablePrefix().'%2$s '; + foreach($ret as $sql_part) + { + $sql[]=sprintf($sql_template,$sql_part['IDField'],$sql_part['Table'],$sql_part['Module']); + } + + $module_table=GetTablePrefix().'DupeRIDs '; + + $sql='CREATE TABLE '.$module_table.' '.implode(' UNION ',$sql); + $ado->Execute($sql); + + $sql='SELECT ResourceId FROM '.$module_table.' GROUP BY ResourceId HAVING COUNT(*)>1'; + $duplicate_rids=$ado->GetCol($sql); + if(!$duplicate_rids) return; + + $sql='SELECT * FROM '.$module_table.' WHERE ResourceId IN ('.implode(',',$duplicate_rids).') ORDER BY TableName,ResourceId,ID'; + $rs=$ado->Execute($sql); + + $originals=Array(); // this are originals + $dupes=Array(); // this is dupes + + $update_tpl='UPDATE '.GetTablePrefix().'%s SET ResourceId=%s WHERE %s=%s'; + + $non_category_items = Array(); + while(!$rs->EOF) + { + $rec=&$rs->fields; + if( isset($originals[$rec['ResourceId']]) ) + { + // this is dupe + $next_id = GetNextResourceId(); + $update_sql = sprintf($update_tpl,$rec['TableName'],$next_id,$rec['IDField'],$rec['ID']); + $ado->Execute($update_sql); + $dupes[$next_id] = $rec['ID']; + if($rec['Module'] == 'In-Portal') $non_category_items[$next_id] = $rec['ID']; + } + else + { + // this is original + $originals[ $rec['ResourceId'] ]=$rec['ID']; + } + $rs->MoveNext(); + } + + if($dupes) + { + // find lost+found category + global $objCatList; + if( !(isset($objCatList) && is_object($objCatList)) ) $objCatList=new clsCatList(); + + $cat=$objCatList->GetItemByField('Name','Lost & Found'); + if( !is_object($cat) ) + { + $cat=&$objCatList->Add(0,'Lost & Found','Lost & Found Items',adodb_mktime(),0,0,2,2,2,0,'',''); + $cat->UpdateACL(); + } + + $cat_id=$cat->UniqueId(); + + // move to lost + found category + foreach($dupes as $dupe_rid => $dupe_id) + { + if( !isset($non_category_items[$dupe_rid]) ) + { + $ado->Execute('INSERT INTO '.GetTablePrefix().'CategoryItems VALUES ('.$cat_id.','.$dupe_rid.',1)'); + } + } + + } + $ado->Execute('DROP TABLE IF EXISTS '.$module_table); + } + + dupe_ResourceIDs_check(); + $module_info = m_GetModuleInfo('filenames'); $sql = 'SELECT '.$module_info['title_field'].', '.$module_info['id_field'].' FROM '.$table_prefix.$module_info['table']; $items_rs = $inst_ado->Execute($sql); @@ -21,5 +127,7 @@ $inst_ado->Execute($sql); $items_rs->MoveNext(); } - + + + ?> \ No newline at end of file Index: trunk/admin/install/upgrades/inportal_check_v1.1.4.php =================================================================== diff -u -r3282 -r3440 --- trunk/admin/install/upgrades/inportal_check_v1.1.4.php (.../inportal_check_v1.1.4.php) (revision 3282) +++ trunk/admin/install/upgrades/inportal_check_v1.1.4.php (.../inportal_check_v1.1.4.php) (revision 3440) @@ -1,106 +1,4 @@ ExecuteFunction('GetModuleInfo', 'dupe_resourceids'); - - foreach($table_info as $module_name => $module_info) - { - foreach($module_info as $module_sub_info) - { - $module_sub_info['Module']=$module_name; - array_push($ret,$module_sub_info); - } - } - - // 2. build mega sql joining all tables in on and search resource id throught them - $ado->Execute('DROP TABLE IF EXISTS '.GetTablePrefix().'DupeRIDs'); - - $sql = Array(); - $sql_template = 'SELECT %1$s AS ID, \'%1$s\' AS IDField, ResourceId, \'%2$s\' AS TableName, \'%3$s\' AS Module FROM '.GetTablePrefix().'%2$s '; - foreach($ret as $sql_part) - { - $sql[]=sprintf($sql_template,$sql_part['IDField'],$sql_part['Table'],$sql_part['Module']); - } - - $module_table=GetTablePrefix().'DupeRIDs '; - - $sql='CREATE TABLE '.$module_table.' '.implode(' UNION ',$sql); - $ado->Execute($sql); - - $sql='SELECT ResourceId FROM '.$module_table.' GROUP BY ResourceId HAVING COUNT(*)>1'; - $duplicate_rids=$ado->GetCol($sql); - if(!$duplicate_rids) return; - - $sql='SELECT * FROM '.$module_table.' WHERE ResourceId IN ('.implode(',',$duplicate_rids).') ORDER BY TableName,ResourceId,ID'; - $rs=$ado->Execute($sql); - - $originals=Array(); // this are originals - $dupes=Array(); // this is dupes - - $update_tpl='UPDATE '.GetTablePrefix().'%s SET ResourceId=%s WHERE %s=%s'; - - $non_category_items = Array(); - while(!$rs->EOF) - { - $rec=&$rs->fields; - if( isset($originals[$rec['ResourceId']]) ) - { - // this is dupe - $next_id = GetNextResourceId(); - $update_sql = sprintf($update_tpl,$rec['TableName'],$next_id,$rec['IDField'],$rec['ID']); - $ado->Execute($update_sql); - $dupes[$next_id] = $rec['ID']; - if($rec['Module'] == 'In-Portal') $non_category_items[$next_id] = $rec['ID']; - } - else - { - // this is original - $originals[ $rec['ResourceId'] ]=$rec['ID']; - } - $rs->MoveNext(); - } - - if($dupes) - { - // find lost+found category - global $objCatList; - if( !(isset($objCatList) && is_object($objCatList)) ) $objCatList=new clsCatList(); - - $cat=$objCatList->GetItemByField('Name','Lost & Found'); - if( !is_object($cat) ) - { - $cat=&$objCatList->Add(0,'Lost & Found','Lost & Found Items',adodb_mktime(),0,0,2,2,2,0,'',''); - } - - $cat_id=$cat->UniqueId(); - - // move to lost + found category - foreach($dupes as $dupe_rid => $dupe_id) - { - if( !isset($non_category_items[$dupe_rid]) ) - { - $ado->Execute('INSERT INTO '.GetTablePrefix().'CategoryItems VALUES ('.$cat_id.','.$dupe_rid.',1)'); - } - } - - } - $ado->Execute('DROP TABLE IF EXISTS '.$module_table); - } - - dupe_ResourceIDs_check(); - ?> \ No newline at end of file Index: trunk/core/kernel/utility/http_query.php =================================================================== diff -u -r3425 -r3440 --- trunk/core/kernel/utility/http_query.php (.../http_query.php) (revision 3425) +++ trunk/core/kernel/utility/http_query.php (.../http_query.php) (revision 3440) @@ -68,7 +68,7 @@ * @access public */ var $Conn; - + /** * Loads info from $_POST, $_GET and * related arrays into common place @@ -81,7 +81,7 @@ { parent::Params(); $this->Conn =& $this->Application->GetADODBConnection(); - + $this->Order = $order; $this->Admin = $this->Application->IsAdmin(); // better cache this value, not to calculate it each time in foreach } @@ -97,7 +97,7 @@ } ini_set('magic_quotes_gpc', 0); } - + function removeSpecials($array) { $ret = Array(); @@ -133,31 +133,31 @@ $this->Get = $this->AddVars($_GET); $this->processQueryString(); break; - + case 'P': $this->Post = $this->AddVars($_POST); $this->convertPostEvents(); break; - + case 'C': $this->Cookie = $this->AddVars($_COOKIE); break; - + case 'E'; $this->Env = $this->AddVars($_ENV); break; - + case 'S'; $this->Server = $this->AddVars($_SERVER); break; - + case 'F'; $this->convertFiles(); $this->Files = $this->MergeVars($_FILES, false); //do not strip slashes! break; } } - + if( $this->Application->RewriteURLs() ) { if( $this->Application->isDebugMode() ) @@ -170,7 +170,7 @@ { $this->processRewriteURL(); } - + } } @@ -288,22 +288,22 @@ } $passed = implode(',', $passed); $this->Set('passed', $passed); - + $env = $this->Application->BuildEnv( $this->Get('t'), $module_params, $passed, false, false ); $this->Set(ENV_VAR_NAME, $env); $_REQUEST['env'] = $_GET['env'] = $env; // for capability with old in-portal code } - + function processRewriteURL() { // directory_1_2_3/sc1/inlink/detail/3/l1_ka_asd.html - + $url = $this->Get('_mod_rw_url_'); - if( substr($url, -5) == '.html' ) $url = substr($url, 0, strlen($url) - 5 ); - + if( substr($url, -5) == '.html' ) $url = substr($url, 0, strlen($url) - 5 ); + $url_parts = $url ? explode('/', $url) : Array(); - - if($this->Get('rewrite') == 'on') + + if($this->Get('rewrite') == 'on' || !$url_parts) { // set default values $defaults = Array('m_cat_id' => 0, 'm_cat_page' => 1, 'm_opener' => 's'); @@ -312,7 +312,7 @@ $this->Set($default_key, $default_value); } } - + if(!$url_parts) { $this->Application->Phrases = new PhrasesCache(); @@ -328,9 +328,9 @@ { $this->Set('t', ''); } - + $url_part = array_shift($url_parts); - + // match language $sql = 'SELECT LanguageId FROM '.TABLE_PREFIX.'Language WHERE LOWER(PackName) = '.$this->Conn->qstr($url_part).' AND Enabled = 1'; $language_id = $this->Conn->GetOne($sql); @@ -340,12 +340,12 @@ $this->Set('m_lang', $language_id); $url_part = $url_parts ? array_shift($url_parts) : ''; // prepare next url part for parsing } - + $this->Application->VerifyLanguageId(); - + $this->Application->Phrases->Init('phrases'); // $this->Get('m_lang') ); - + // match theme if($url_part) { @@ -356,10 +356,9 @@ $this->Set('m_theme', $theme_id); $url_part = $url_parts ? array_shift($url_parts) : ''; // prepare next url part for parsing } - - $this->Application->VerifyThemeId(); } - + $this->Application->VerifyThemeId(); // verify anyway - will set default if not found!!! + // match category if($url_part) { @@ -370,24 +369,24 @@ do { $category_path = trim($category_path.'/'.$url_part, '/'); - + if( preg_match('/(.*)_([\d]+)$/', $category_path, $rets) ) { $category_path = $rets[1]; $this->Set('m_cat_page', $rets[2]); } - + $sql = 'SELECT CategoryId FROM '.TABLE_PREFIX.'Category WHERE NamedParentPath = '.$this->Conn->qstr($category_path); array_push($category_stack, $this->Conn->GetOne($sql) ); $category_found = end($category_stack); if($category_found) $url_part = array_shift($url_parts); - + }while ($category_found && $url_part); - + if( count($category_stack) >= 2 ) { $category_id = array_pop($category_stack); // remove last not found category - if($category_id === false) + if($category_id === false) { $category_id = array_pop($category_stack); } @@ -401,7 +400,7 @@ $url_part = array_shift($url_parts); } } - + // match module $next_template = $this->Get('next_template'); if($url_part || $next_template) @@ -415,7 +414,7 @@ { $module_folder = $url_part; } - + foreach ($this->Application->ModuleInfo as $module_name => $module_data) { if( trim($module_data['TemplatePath'], '/') == $module_folder ) @@ -425,7 +424,7 @@ } } } - + // match template $template_path = ''; $template_found = false; @@ -437,17 +436,17 @@ do { $template_path = implode('/', $template_parts); - + $sql = 'SELECT FileId FROM '.TABLE_PREFIX.'ThemeFiles WHERE CONCAT(FilePath, "/", FileName) = '.$this->Conn->qstr('/'.$template_path.'.tpl'); $template_found = $this->Conn->GetOne($sql); if(!$template_found) { array_unshift( $url_parts, array_pop($template_parts) ); } - + }while (!$template_found && $template_parts); } - + // guess template if no existing template found if(!$template_found && isset($module_folder) && $module_folder) { @@ -466,22 +465,22 @@ if(!$template_path) $template_path = 'error_notfound'; } } - - + + $this->Set('t', $this->getDefaultTemplate($template_found ? $template_path : '') ); // pass params left to module - + $passed = Array('m'); $module_params = Array(); - + if( isset($module_prefix) ) { $passed[] = $module_prefix; $module_event = new kEvent($module_prefix.':ParseEnv', Array('url_parts' => $url_parts) ); $this->Application->HandleEvent($module_event); $item_id = $this->Get($module_prefix.'_id'); $module_params = Array($module_prefix.'_id' => $item_id ? $item_id : '0' ); - + if($module_event->status == erFAIL) { $not_found = $this->Application->ConfigValue('ErrorTemplate'); @@ -491,14 +490,14 @@ $this->finalizeParsing($passed, $module_params); } - + function getDefaultTemplate($t) { $t = $this->getTemplateName( trim($t, '/') ); if (!$t) $t = 'index'; return trim($t, '/'); } - + function extractSIDAndTemplate(&$parts) { if ( defined('INPORTAL_ENV') && INPORTAL_ENV ) // SID-TEMPLATE @@ -527,7 +526,7 @@ $this->Set('t', $this->getDefaultTemplate($t) ); } } - + /** * Process QueryString only, create * events, ids, based on config @@ -677,7 +676,7 @@ } return $array; } - + /** * Returns all $_GET array excluding system parameters, that are not allowed to be passed through generated urls *