@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
3echo pht('Moving Slowvote comments to transactions...')."\n";
4
5$viewer = PhabricatorUser::getOmnipotentUser();
6
7$table_xaction = new PhabricatorSlowvoteTransaction();
8$table_comment = new PhabricatorSlowvoteTransactionComment();
9$conn_w = $table_xaction->establishConnection('w');
10
11$comments = new LiskRawMigrationIterator($conn_w, 'slowvote_comment');
12
13$conn_w->openTransaction();
14
15foreach ($comments as $comment) {
16 $id = $comment['id'];
17 $poll_id = $comment['pollID'];
18 $author_phid = $comment['authorPHID'];
19 $text = $comment['commentText'];
20 $date_created = $comment['dateCreated'];
21 $date_modified = $comment['dateModified'];
22
23 echo pht('Migrating comment %d.', $id)."\n";
24
25 $poll = id(new PhabricatorSlowvoteQuery())
26 ->setViewer($viewer)
27 ->withIDs(array($poll_id))
28 ->executeOne();
29 if (!$poll) {
30 echo pht('No poll.')."\n";
31 continue;
32 }
33
34 $user = id(new PhabricatorPeopleQuery())
35 ->setViewer($viewer)
36 ->withPHIDs(array($author_phid))
37 ->executeOne();
38 if (!$user) {
39 echo pht('No user.')."\n";
40 continue;
41 }
42
43 $comment_phid = PhabricatorPHID::generateNewPHID(
44 PhabricatorPHIDConstants::PHID_TYPE_XCMT);
45 $xaction_phid = PhabricatorPHID::generateNewPHID(
46 PhabricatorApplicationTransactionTransactionPHIDType::TYPECONST,
47 PhabricatorSlowvotePollPHIDType::TYPECONST);
48
49 $content_source = PhabricatorContentSource::newForSource(
50 PhabricatorOldWorldContentSource::SOURCECONST)->serialize();
51
52 queryfx(
53 $conn_w,
54 'INSERT INTO %T (phid, transactionPHID, authorPHID, viewPolicy, editPolicy,
55 commentVersion, content, contentSource, isDeleted,
56 dateCreated, dateModified)
57 VALUES (%s, %s, %s, %s, %s,
58 %d, %s, %s, %d,
59 %d, %d)',
60 $table_comment->getTableName(),
61 $comment_phid,
62 $xaction_phid,
63 $user->getPHID(),
64 PhabricatorPolicies::POLICY_PUBLIC,
65 $user->getPHID(),
66 1,
67 $text,
68 $source,
69 0,
70 $date_created,
71 $date_modified);
72
73 queryfx(
74 $conn_w,
75 'INSERT INTO %T (phid, authorPHID, objectPHID, viewPolicy, editPolicy,
76 commentPHID, commentVersion, transactionType, oldValue, newValue,
77 contentSource, metadata, dateCreated, dateModified)
78 VALUES (%s, %s, %s, %s, %s,
79 %s, %d, %s, %s, %s,
80 %s, %s, %d, %d)',
81 $table_xaction->getTableName(),
82 $xaction_phid,
83 $user->getPHID(),
84 $poll->getPHID(),
85 PhabricatorPolicies::POLICY_PUBLIC,
86 $user->getPHID(),
87 $comment_phid,
88 1,
89 PhabricatorTransactions::TYPE_COMMENT,
90 null,
91 null,
92 $source,
93 '{}',
94 $date_created,
95 $date_modified);
96}
97
98$conn_w->saveTransaction();
99
100echo pht('Done.')."\n";