Skip to content

Commit 6172f2b

Browse files
author
epriestley
committedJul 29, 2013
Require answers' authors to be unique in Ponder
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
1 parent 61e7043 commit 6172f2b

File tree

4 files changed

+89
-9
lines changed

4 files changed

+89
-9
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
$map = array();
4+
5+
echo "Merging duplicate answers by authors...\n";
6+
7+
$atable = new PonderAnswer();
8+
$conn_w = $atable->establishConnection('w');
9+
$conn_w->openTransaction();
10+
11+
$answers = new LiskMigrationIterator(new PonderAnswer());
12+
foreach ($answers as $answer) {
13+
$aid = $answer->getID();
14+
$qid = $answer->getQuestionID();
15+
$author_phid = $answer->getAuthorPHID();
16+
17+
echo "Processing answer ID #{$aid}...\n";
18+
19+
if (empty($map[$qid][$author_phid])) {
20+
echo "Answer is unique.\n";
21+
$map[$qid][$author_phid] = $answer;
22+
continue;
23+
} else {
24+
echo "Merging answer.\n";
25+
$target = $map[$qid][$author_phid];
26+
queryfx(
27+
$conn_w,
28+
'UPDATE %T SET content = %s WHERE id = %d',
29+
$target->getTableName(),
30+
31+
$target->getContent().
32+
"\n\n".
33+
"---".
34+
"\n\n".
35+
"> (This content was automatically merged from another answer by the ".
36+
"same author.)".
37+
"\n\n".
38+
$answer->getContent(),
39+
40+
$target->getID());
41+
42+
queryfx(
43+
$conn_w,
44+
'DELETE FROM %T WHERE id = %d',
45+
$target->getTableName(),
46+
$answer->getID());
47+
48+
queryfx(
49+
$conn_w,
50+
'UPDATE %T SET targetPHID = %s WHERE targetPHID = %s',
51+
'ponder_comment',
52+
$target->getPHID(),
53+
$answer->getPHID());
54+
}
55+
}
56+
57+
$conn_w->saveTransaction();
58+
echo "Done.\n";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE {$NAMESPACE}_ponder.ponder_answer
2+
ADD UNIQUE KEY `key_oneanswerperquestion` (questionID, authorPHID);

‎src/applications/ponder/controller/PonderQuestionViewController.php

+21-9
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ public function processRequest() {
2727
$question_xactions = $this->buildQuestionTransactions($question);
2828
$answers = $this->buildAnswers($question->getAnswers());
2929

30-
$answer_add_panel = new PonderAddAnswerView();
31-
$answer_add_panel
32-
->setQuestion($question)
33-
->setUser($user)
34-
->setActionURI("/ponder/answer/add/");
30+
$authors = mpull($question->getAnswers(), null, 'getAuthorPHID');
31+
if (isset($authors[$user->getPHID()])) {
32+
// TODO: Make this pretty
33+
$answer_add_panel = pht(
34+
'You have already answered this question.');
35+
} else {
36+
$answer_add_panel = new PonderAddAnswerView();
37+
$answer_add_panel
38+
->setQuestion($question)
39+
->setUser($user)
40+
->setActionURI("/ponder/answer/add/");
41+
}
3542

3643
$header = id(new PhabricatorHeaderView())
3744
->setHeader($question->getTitle());
@@ -268,10 +275,15 @@ private function buildAnswerProperties(PonderAnswer $answer) {
268275
$view->invokeWillRenderEvent();
269276

270277
$view->addTextContent(
271-
PhabricatorMarkupEngine::renderOneObject(
272-
$answer,
273-
$answer->getMarkupField(),
274-
$viewer));
278+
phutil_tag(
279+
'div',
280+
array(
281+
'class' => 'phabricator-remarkup',
282+
),
283+
PhabricatorMarkupEngine::renderOneObject(
284+
$answer,
285+
$answer->getMarkupField(),
286+
$viewer)));
275287

276288
return $view;
277289
}

‎src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php

+8
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,14 @@ public function getPatches() {
14871487
'type' => 'sql',
14881488
'name' => $this->getPatchPath('20130726.ponderxactions.sql'),
14891489
),
1490+
'20130728.ponderunique.php' => array(
1491+
'type' => 'php',
1492+
'name' => $this->getPatchPath('20130728.ponderunique.php'),
1493+
),
1494+
'20130728.ponderuniquekey.sql' => array(
1495+
'type' => 'sql',
1496+
'name' => $this->getPatchPath('20130728.ponderuniquekey.sql'),
1497+
),
14901498
);
14911499
}
14921500
}

0 commit comments

Comments
 (0)
Failed to load comments.