Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97238258
20130728.ponderunique.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jan 3, 17:07
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Jan 5, 17:07 (2 d)
Engine
blob
Format
Raw Data
Handle
23361928
Attached To
rPH Phabricator
20130728.ponderunique.php
View Options
<?php
$map
=
array
();
echo
"Merging duplicate answers by authors...
\n
"
;
$atable
=
new
PonderAnswer
();
$conn_w
=
$atable
->
establishConnection
(
'w'
);
$conn_w
->
openTransaction
();
$answers
=
new
LiskMigrationIterator
(
new
PonderAnswer
());
foreach
(
$answers
as
$answer
)
{
$aid
=
$answer
->
getID
();
$qid
=
$answer
->
getQuestionID
();
$author_phid
=
$answer
->
getAuthorPHID
();
echo
"Processing answer ID #{$aid}...
\n
"
;
if
(
empty
(
$map
[
$qid
][
$author_phid
]))
{
echo
"Answer is unique.
\n
"
;
$map
[
$qid
][
$author_phid
]
=
$answer
;
continue
;
}
else
{
echo
"Merging answer.
\n
"
;
$target
=
$map
[
$qid
][
$author_phid
];
queryfx
(
$conn_w
,
'UPDATE %T SET content = %s WHERE id = %d'
,
$target
->
getTableName
(),
$target
->
getContent
().
"
\n\n
"
.
"---"
.
"
\n\n
"
.
"> (This content was automatically merged from another answer by the "
.
"same author.)"
.
"
\n\n
"
.
$answer
->
getContent
(),
$target
->
getID
());
queryfx
(
$conn_w
,
'DELETE FROM %T WHERE id = %d'
,
$target
->
getTableName
(),
$answer
->
getID
());
queryfx
(
$conn_w
,
'UPDATE %T SET targetPHID = %s WHERE targetPHID = %s'
,
'ponder_comment'
,
$target
->
getPHID
(),
$answer
->
getPHID
());
}
}
$conn_w
->
saveTransaction
();
echo
"Done.
\n
"
;
Event Timeline
Log In to Comment