Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F773485
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
Sun, Feb 2, 1:06 PM
Size
13 KB
Mime Type
text/x-diff
Expires
Tue, Feb 4, 1:06 PM (2 h, 18 m)
Engine
blob
Format
Raw Data
Handle
556704
Attached To
rINP In-Portal
in-portal
View Options
Index: trunk/kernel/admin/include/parser.php
===================================================================
--- trunk/kernel/admin/include/parser.php (revision 1219)
+++ trunk/kernel/admin/include/parser.php (revision 1220)
@@ -1,278 +1,285 @@
<?php
function adListSubCats($ParentId, $template, $KeywordsVar = 'SearchWord')
{
global $var_list, $m_cat_filter, $m_category_sort, $m_category_sortby,
$objCatList, $objSession,$pathtoroot, $objConfig,$admin;
if($objCatList->NumCategories()==0)
return "<br>No Categories<br><br>";
$o="<table border=0 cellspacing=2 width=\"100%\"><tbody><tr>";
$i=1;
$list = $objSession->GetVariable($KeywordsVar);
if(strlen($list))
$Keywords = explode(",",$list);
$template = $pathtoroot.$admin."/templates/".$template;
$topleft = 0;
$topright = 0;
$rightcount = 0;
$totalcats = 0;
$totalcats = $objCatList->NumItems();
$topleft = ceil($totalcats/2);
$topright = $totalcats-$topleft;
for ($x=0;$x<$topleft;$x++)
{
//printingleft
$cat = $objCatList->Items[$x];
if($cat->Get("CategoryId")!=$ParentId)
{
if ($i > 2)
{
$o.="</tr>\n<tr>";
$i = 1;
}
//$cat->LoadPermissions($objSession->Get("GroupId"));
if(strlen($list))
{
$h = $cat->AdminParseTemplate($template);
$h = HighlightKeywords($Keywords, $h);
$o .= $h;
$h = "";
}
else
$o.=$cat->AdminParseTemplate($template);
$i++;
}
//printingright
if ($rightcount < $topright && (($x+$topleft) <$totalcats))
{
$cat = $objCatList->Items[$x+$topleft];
if($cat->Get("CategoryId")!=$ParentId)
{
if ($i > 2)
{
$o.="</tr>\n<tr>";
$i = 1;
}
//$cat->LoadPermissions($objSession->Get("GroupId"));
if(strlen($list))
{
$h = $cat->AdminParseTemplate($template);
$h = HighlightKeywords($Keywords, $h);
$o .= $h;
$h = "";
}
else
$o.=$cat->AdminParseTemplate($template);
$i++;
}
$rightcount++;
}
}
$o .="\n</tr></tbody></table>\n";
return $o;
}
function list_custom($c,$Type)
{
global $objSession, $objCustomFieldList, $objCustomDataList,
$imagesURL;
$field_list = $objCustomFieldList->Query_CustomField("Type=$Type");
if (count($field_list) == 0)
return "No Custom Fields<br><br>";
$o="";
$i = 1;
$objCustomDataList->SourceTable = $objSession->GetEditTable("CustomMetaData");
$objCustomDataList->LoadResource($c->Get("ResourceId"));
foreach($field_list as $field)
{
$fieldname = $field->Get("FieldName");
$fieldlabel = $field->Get("FieldLabel");
$fieldid = $field->Get("CustomFieldId");
$f = $objCustomDataList->GetDataItem($fieldid);
if(is_object($f))
{
$fieldvalue = $f->Get("Value");
}
else
$fieldvalue="";
$o .="<tr " . int_table_color_ret() .">";
$o .="<td valign=\"top\"><img src=\"$imagesURL/itemicons/icon16_custom.gif\" height=\"16\" width=\"16\" align=\"absmiddle\"><span class=\"text\"> $fieldname</span></td>
<td valign=\"top\"><span class=\"text\">$fieldlabel</span></td>
<td>
<input type=\"text\" name=\"customdata[$fieldid]\" class=\"text\" size=\"30\" value=\"$fieldvalue\">
</td></tr>\n";
$i++;
}
return $o;
}
function adListRelatedCategories($Item)
{
global $objCatList;
if(is_object($Item))
{
$catlist = $Item->GetRelatedCategories(0);
$o = "";
foreach($catlist as $catrel)
{
$o .= "<input type=checkbox NAME=\"dellist[]\" VALUE=\"".$catrel->Get("RelationshipId")."\">";
$cat = $objCatList->GetByResource($catrel->Get("TargetId"));
$path = $cat->ParentNames();
if(strlen($path))
{
$o .= implode(">",$path);
}
$o .="<br>\n";
}
}
return $o;
}
function adListRelatedItems($Item)
{
global $objCatList;
if(is_object($Item))
{
$item_list=$Item->GetRelatedItems(0);
$o = "";
foreach($item_list as $i)
{
$data = $i->GetTargetItemData();
$o .= "<tr ".int_table_color_ret().">";
$o .= "<TD>";
$o .= "<input type=checkbox NAME=\"dellist[]\" VALUE=\"".$i->Get("RelationshipId")."\">";
$o .= $data[$data["TitleField"]];
$o .= "</TD>";
$o .= "<TD>".$data["SourceTable"]."</TD>";
$cat =& $objCatList->GetCategory($data["CategoryId"]);
$o .= "<TD>";
$path = $cat->ParentNames();
if(strlen($path))
{
$o .= implode(">",$path);
}
$o .= "</TD></TR>";
}
}
return $o;
}
function adListItemReviews($Item)
{
global $pathtoroot,$admin;
$Reviews = $Item->GetItemReviews();
$o = "";
if($Reviews->ItemCount()>0)
{
foreach($Reviews->ItemList as $r)
{
$o .= "<TR ".int_table_color_ret().">";
$o .= "<TD width=\"5%\">";
if($r->Get("Pending")==0)
{
$o .= "<INPUT TYPE=checkbox NAME=\"deletelist[]\" VALUE=\"".$r->Get("ReviewId")."\"> Delete";
}
$o .= "</TD><TD width=\"5%\">";
if($r->Get("Pending")!=0)
{
$o .= "<INPUT TYPE=checkbox NAME=\"approvelist[]\" VALUE=\"".$r->Get("ReviewId")."\"> Approve";
}
$o .= "</TD>";
$o .= $r->parse_template(admintemplate($pathtoroot.$admin."/templates/review_element.tpl"));
$o .= "</TR>";
}
}
return $o;
}
function adImageUploadFormTags($img)
{
static $file_count=0;
$o = "";
if($file_count==0)
{
$o .= "<INPUT TYPE=HIDDEN NAME=\"img\" VALUE=1>";
}
$o .= "<TD><INPUT TYPE=TEXT NAME=\"img_Name_$file_count\" VALUE=\"".$img->Get("Name")."\"></TD>";
$o .= "<TD><INPUT TYPE=TEXT NAME=\"img_Alt_$file_count\" VALUE=\"".$img->Get("AltName")."\"></TD>";
$o .= "<TD>";
$o .= "<INPUT TYPE=TEXT size=40 NAME=\"img_Url_$file_count\" VALUE=\"".$img->Get("Url")."\">";
$o .= "</TD><TD>";
$o .= "<INPUT TYPE=FILE class=\"button\" VALUE=\"".$img->Get("Url")."\" NAME=\"$file_count\">";
$o .= "<INPUT TYPE=HIDDEN NAME=\"img_Res_$file_count\" VALUE=\"".$img->Get("ResourceId")."\">";
$o .= "<INPUT TYPE=HIDDEN NAME=\"img_Rel_$file_count\" VALUE=\"".$img->Get("RelatedTo")."\">";
$o .= "<INPUT TYPE=HIDDEN NAME=\"img_Thumb_$file_count\" VALUE=\"".$img->Get("IsThumbnail")."\">";
$parts = pathinfo($img->Get("LocalPath"));
$destdir = $parts["dirname"];
$o .= "<INPUT TYPE=HIDDEN NAME=\"img_DestDir_$file_count\" VALUE=\"$destdir\">";
if($img->Get("RelatedTo")>0)
$o .= "<input type=\"submit\" name=\"img_Del_$file_count\" value=\"Delete\" class=\"button2\">";
$o .= "</TD>";
$file_count++;
return $o;
}
function m_GetModuleInfo($info_type)
{
// get information for building sql in
switch($info_type)
{
case 'rel_list': // Edit Category -> Relations List
return Array( 'MainTable' => 'Category', 'ItemNameField' => 'CachedNavbar',
'ItemNamePhrase' => 'la_Text_Category', 'TargetType' => 1);
break;
case 'summary_pending':
global $imagesURL;
$ret = Array();
$UserURL = $GLOBALS['adminURL'].'/users/user_list.php?env='.BuildEnv();
// pending users
$ret[] = Array( 'link' => "config_val('User_View', '4' ,'$UserURL')",
'icon_image' => $imagesURL.'/itemicons/icon16_user_pending.gif',
'phrase' => 'la_Text_Users', 'list_var_name' => 'objUsers' );
// pending categories
$ret[] = Array( 'link' => "PendingLink('category','Category_View',41)",
'icon_image' => $imagesURL.'/itemicons/icon16_cat_pending.gif',
'phrase' => 'la_tab_Categories', 'list_var_name' => 'objCatList');
return $ret;
break;
case 'all_bitmask': // return bitmask value equals to "all" for module filter
return Array('VarName' => 'Category_View', 'Bits' => 127);
break;
+
+ case 'dupe_resourceids':
+ $ret=Array();
+ $ret[]=Array('Table'=>'Category','IDField'=>'CategoryId');
+ $ret[]=Array('Table'=>'PortalGroup','IDField'=>'GroupId');
+ $ret[]=Array('Table'=>'PortalUser','IDField'=>'PortalUserId');
+ return $ret;
}
return false;
}
?>
Property changes on: trunk/kernel/admin/include/parser.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.5
\ No newline at end of property
+1.6
\ No newline at end of property
Index: trunk/admin/install/upgrades/inportal_check_v1.0.10.php
===================================================================
--- trunk/admin/install/upgrades/inportal_check_v1.0.10.php (revision 1219)
+++ trunk/admin/install/upgrades/inportal_check_v1.0.10.php (revision 1220)
@@ -1,24 +1,100 @@
<?php
// !!! do not use variable $rs as record-set;
-$sql='SELECT ResourceId,COUNT(*) as c FROM '.$g_TablePrefix.'Category GROUP BY 1 HAVING c>1';
-$rs2 = $ado->Execute($sql);
-if ($rs2 && !$rs2->EOF)
-{
- $result|=$failCheck;
- $CheckErrors[] = 'You have duplicate ResourceId in table "'.$g_TablePrefix.'Category"';
-}
-$sql='SELECT ResourceId,COUNT(*) as c FROM '.$g_TablePrefix.'PortalGroup GROUP BY 1 HAVING c>1';
-$rs2 = $ado->Execute($sql);
-if ($rs2 && !$rs2->EOF)
-{
- $result|=$failCheck;
- $CheckErrors[] = 'You have duplicate ResourceId in table "'.$g_TablePrefix.'PortalGroup"';
-}
-$sql='SELECT ResourceId,COUNT(*) as c FROM '.$g_TablePrefix.'PortalUser GROUP BY 1 HAVING c>1';
-$rs2 = $ado->Execute($sql);
-if ($rs2 && !$rs2->EOF)
-{
- $result|=$failCheck;
- $CheckErrors[] = 'You have duplicate ResourceId in table "'.$g_TablePrefix.'PortalUser"';
-}
+ // 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 FROM ".GetTablePrefix()."%2\$s ";
+ foreach($ret as $sql_part)
+ {
+ $sql[]=sprintf($sql_template,$sql_part['IDField'],$sql_part['Table']);
+ }
+
+ $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';
+ 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'];
+ }
+ 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)
+ {
+ $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.0.10.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property
Event Timeline
Log In to Comment