Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1051422
inportal_check_v1.1.4.php
No One
Temporary
Actions
Download 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 3, 11:32 PM
Size
3 KB
Mime Type
text/x-php
Expires
Sat, Jul 5, 11:32 PM (1 d, 11 h)
Engine
blob
Format
Raw Data
Handle
679102
Attached To
rINP In-Portal
inportal_check_v1.1.4.php
View Options
<?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'
,
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
();
?>
Event Timeline
Log In to Comment