@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<?php
2
3$map = array();
4
5echo pht('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());
12foreach ($answers as $answer) {
13 $aid = $answer->getID();
14 $qid = $answer->getQuestionID();
15 $author_phid = $answer->getAuthorPHID();
16
17 echo pht('Processing answer ID #%d...', $aid)."\n";
18
19 if (empty($map[$qid][$author_phid])) {
20 echo pht('Answer is unique.')."\n";
21 $map[$qid][$author_phid] = $answer;
22 continue;
23 } else {
24 echo pht('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();
58echo pht('Done.')."\n";