Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1058698
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jul 10, 8:34 PM
Size
3 KB
Mime Type
text/x-diff
Expires
Sat, Jul 12, 8:34 PM (2 h, 4 m)
Engine
blob
Format
Raw Data
Handle
683727
Attached To
rINP In-Portal
in-portal
View Options
Index: trunk/admin/install/upgrades/inportal_check_v1.1.4.php
===================================================================
--- trunk/admin/install/upgrades/inportal_check_v1.1.4.php (nonexistent)
+++ trunk/admin/install/upgrades/inportal_check_v1.1.4.php (revision 3077)
@@ -0,0 +1,106 @@
+<?php
+// !!! 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',time(),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
Property changes on: trunk/admin/install/upgrades/inportal_check_v1.1.4.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Event Timeline
Log In to Comment