forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20130728.ponderunique.php
58 lines (47 loc) · 1.33 KB
/
20130728.ponderunique.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
$map = array();
echo pht('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 pht('Processing answer ID #%d...', $aid)."\n";
if (empty($map[$qid][$author_phid])) {
echo pht('Answer is unique.')."\n";
$map[$qid][$author_phid] = $answer;
continue;
} else {
echo pht('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 pht('Done.')."\n";