Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/resources/sql/autopatches/20140211.dx.2.migcommenttext.php
12250 views
1
<?php
2
3
$conn_w = id(new DifferentialRevision())->establishConnection('w');
4
$rows = new LiskRawMigrationIterator($conn_w, 'differential_comment');
5
6
$content_source = PhabricatorContentSource::newForSource(
7
PhabricatorOldWorldContentSource::SOURCECONST)->serialize();
8
9
echo pht('Migrating Differential comment text to modern storage...')."\n";
10
foreach ($rows as $row) {
11
$id = $row['id'];
12
echo pht('Migrating Differential comment %d...', $id)."\n";
13
if (!strlen($row['content'])) {
14
echo pht('Comment has no text, continuing.')."\n";
15
continue;
16
}
17
18
$revision = id(new DifferentialRevision())->load($row['revisionID']);
19
if (!$revision) {
20
echo pht('Comment has no valid revision, continuing.')."\n";
21
continue;
22
}
23
24
$revision_phid = $revision->getPHID();
25
26
$dst_table = 'differential_inline_comment';
27
28
$xaction_phid = PhabricatorPHID::generateNewPHID(
29
PhabricatorApplicationTransactionTransactionPHIDType::TYPECONST,
30
DifferentialRevisionPHIDType::TYPECONST);
31
32
$comment_phid = PhabricatorPHID::generateNewPHID(
33
PhabricatorPHIDConstants::PHID_TYPE_XCMT,
34
DifferentialRevisionPHIDType::TYPECONST);
35
36
queryfx(
37
$conn_w,
38
'INSERT IGNORE INTO %T
39
(phid, transactionPHID, authorPHID, viewPolicy, editPolicy,
40
commentVersion, content, contentSource, isDeleted,
41
dateCreated, dateModified, revisionPHID, changesetID,
42
legacyCommentID)
43
VALUES (%s, %s, %s, %s, %s,
44
%d, %s, %s, %d,
45
%d, %d, %s, %nd,
46
%d)',
47
'differential_transaction_comment',
48
49
// phid, transactionPHID, authorPHID, viewPolicy, editPolicy
50
$comment_phid,
51
$xaction_phid,
52
$row['authorPHID'],
53
'public',
54
$row['authorPHID'],
55
56
// commentVersion, content, contentSource, isDeleted
57
1,
58
$row['content'],
59
$content_source,
60
0,
61
62
// dateCreated, dateModified, revisionPHID, changesetID, legacyCommentID
63
$row['dateCreated'],
64
$row['dateModified'],
65
$revision_phid,
66
null,
67
$row['id']);
68
}
69
70
echo pht('Done.')."\n";
71
72