@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+89 -9
+58
resources/sql/patches/20130728.ponderunique.php
··· 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";
+2
resources/sql/patches/20130728.ponderuniquekey.sql
··· 1 + ALTER TABLE {$NAMESPACE}_ponder.ponder_answer 2 + ADD UNIQUE KEY `key_oneanswerperquestion` (questionID, authorPHID);
+21 -9
src/applications/ponder/controller/PonderQuestionViewController.php
··· 27 27 $question_xactions = $this->buildQuestionTransactions($question); 28 28 $answers = $this->buildAnswers($question->getAnswers()); 29 29 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 + } 35 42 36 43 $header = id(new PhabricatorHeaderView()) 37 44 ->setHeader($question->getTitle()); ··· 268 275 $view->invokeWillRenderEvent(); 269 276 270 277 $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))); 275 287 276 288 return $view; 277 289 }
+8
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 1487 1487 'type' => 'sql', 1488 1488 'name' => $this->getPatchPath('20130726.ponderxactions.sql'), 1489 1489 ), 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 + ), 1490 1498 ); 1491 1499 } 1492 1500 }