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