Changeset View
Changeset View
Standalone View
Standalone View
resources/sql/patches/20130728.ponderunique.php
| <?php | <?php | ||||
| $map = array(); | $map = array(); | ||||
| echo "Merging duplicate answers by authors...\n"; | echo pht('Merging duplicate answers by authors...')."\n"; | ||||
| $atable = new PonderAnswer(); | $atable = new PonderAnswer(); | ||||
| $conn_w = $atable->establishConnection('w'); | $conn_w = $atable->establishConnection('w'); | ||||
| $conn_w->openTransaction(); | $conn_w->openTransaction(); | ||||
| $answers = new LiskMigrationIterator(new PonderAnswer()); | $answers = new LiskMigrationIterator(new PonderAnswer()); | ||||
| foreach ($answers as $answer) { | foreach ($answers as $answer) { | ||||
| $aid = $answer->getID(); | $aid = $answer->getID(); | ||||
| $qid = $answer->getQuestionID(); | $qid = $answer->getQuestionID(); | ||||
| $author_phid = $answer->getAuthorPHID(); | $author_phid = $answer->getAuthorPHID(); | ||||
| echo "Processing answer ID #{$aid}...\n"; | echo pht('Processing answer ID #%d...', $aid)."\n"; | ||||
| if (empty($map[$qid][$author_phid])) { | if (empty($map[$qid][$author_phid])) { | ||||
| echo "Answer is unique.\n"; | echo pht('Answer is unique.')."\n"; | ||||
| $map[$qid][$author_phid] = $answer; | $map[$qid][$author_phid] = $answer; | ||||
| continue; | continue; | ||||
| } else { | } else { | ||||
| echo "Merging answer.\n"; | echo pht('Merging answer.')."\n"; | ||||
| $target = $map[$qid][$author_phid]; | $target = $map[$qid][$author_phid]; | ||||
| queryfx( | queryfx( | ||||
| $conn_w, | $conn_w, | ||||
| 'UPDATE %T SET content = %s WHERE id = %d', | 'UPDATE %T SET content = %s WHERE id = %d', | ||||
| $target->getTableName(), | $target->getTableName(), | ||||
| $target->getContent(). | $target->getContent(). | ||||
| "\n\n". | "\n\n". | ||||
| Show All 17 Lines | queryfx( | ||||
| 'UPDATE %T SET targetPHID = %s WHERE targetPHID = %s', | 'UPDATE %T SET targetPHID = %s WHERE targetPHID = %s', | ||||
| 'ponder_comment', | 'ponder_comment', | ||||
| $target->getPHID(), | $target->getPHID(), | ||||
| $answer->getPHID()); | $answer->getPHID()); | ||||
| } | } | ||||
| } | } | ||||
| $conn_w->saveTransaction(); | $conn_w->saveTransaction(); | ||||
| echo "Done.\n"; | echo pht('Done.')."\n"; | ||||