mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40:55 +01:00
6172f2bbd1
Summary: Ref T3578. I forget if this was an explicit decision or not, but we currently let the same user answer questions multiple times. I think this probably causes more confusion than it provides freedom. In conjunction with other UI issues (commenting being weird, notably), we're seeing some use of answers to comment, which is undesirable. Require each answer's author to be unique. Merge existing nonunique authors' answers. Test Plan: {F52062} Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3578 Differential Revision: https://secure.phabricator.com/D6605
58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?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";
|