@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 149 lines 4.2 kB view raw
1<?php 2 3$conn_w = id(new PhabricatorAuditTransaction())->establishConnection('w'); 4$rows = new LiskRawMigrationIterator($conn_w, 'audit_comment'); 5 6$content_source = PhabricatorContentSource::newForSource( 7 PhabricatorOldWorldContentSource::SOURCECONST)->serialize(); 8 9echo pht('Migrating Audit comments to modern storage...')."\n"; 10foreach ($rows as $row) { 11 $id = $row['id']; 12 echo pht('Migrating comment %d...', $id)."\n"; 13 14 $comments = queryfx_all( 15 $conn_w, 16 'SELECT * FROM %T WHERE legacyCommentID = %d', 17 'audit_transaction_comment', 18 $id); 19 20 $main_comments = array(); 21 $inline_comments = array(); 22 23 foreach ($comments as $comment) { 24 if ($comment['pathID']) { 25 $inline_comments[] = $comment; 26 } else { 27 $main_comments[] = $comment; 28 } 29 } 30 31 $metadata = json_decode($row['metadata'], true); 32 if (!is_array($metadata)) { 33 $metadata = array(); 34 } 35 36 $xactions = array(); 37 38 // Build the main action transaction. 39 switch ($row['action']) { 40 case PhabricatorAuditActionConstants::ADD_AUDITORS: 41 $phids = idx($metadata, 'added-auditors', array()); 42 $xactions[] = array( 43 'type' => $row['action'], 44 'old' => null, 45 'new' => array_fuse($phids), 46 ); 47 break; 48 case PhabricatorAuditActionConstants::ADD_CCS: 49 $phids = idx($metadata, 'added-ccs', array()); 50 $xactions[] = array( 51 'type' => $row['action'], 52 'old' => null, 53 'new' => array_fuse($phids), 54 ); 55 break; 56 case PhabricatorAuditActionConstants::COMMENT: 57 case PhabricatorAuditActionConstants::INLINE: 58 // These actions will have their transactions created by other rules. 59 break; 60 default: 61 // Otherwise, this is an accept/concern/etc action. 62 $xactions[] = array( 63 'type' => PhabricatorAuditActionConstants::ACTION, 64 'old' => null, 65 'new' => $row['action'], 66 ); 67 break; 68 } 69 70 71 // Build the main comment transaction. 72 foreach ($main_comments as $main) { 73 $xactions[] = array( 74 'type' => PhabricatorTransactions::TYPE_COMMENT, 75 'old' => null, 76 'new' => null, 77 'phid' => $main['transactionPHID'], 78 'comment' => $main, 79 ); 80 } 81 82 // Build inline comment transactions. 83 foreach ($inline_comments as $inline) { 84 $xactions[] = array( 85 'type' => PhabricatorAuditActionConstants::INLINE, 86 'old' => null, 87 'new' => null, 88 'phid' => $inline['transactionPHID'], 89 'comment' => $inline, 90 ); 91 } 92 93 foreach ($xactions as $xaction) { 94 // Generate a new PHID, if we don't already have one from the comment 95 // table. We pregenerated into the comment table to make this a little 96 // easier, so we only need to write to one table. 97 $xaction_phid = idx($xaction, 'phid'); 98 if (!$xaction_phid) { 99 $xaction_phid = PhabricatorPHID::generateNewPHID( 100 PhabricatorApplicationTransactionTransactionPHIDType::TYPECONST, 101 PhabricatorRepositoryCommitPHIDType::TYPECONST); 102 } 103 unset($xaction['phid']); 104 105 $comment_phid = null; 106 $comment_version = 0; 107 if (idx($xaction, 'comment')) { 108 $comment_phid = $xaction['comment']['phid']; 109 $comment_version = 1; 110 } 111 112 $old = idx($xaction, 'old'); 113 $new = idx($xaction, 'new'); 114 $meta = idx($xaction, 'meta', array()); 115 116 queryfx( 117 $conn_w, 118 'INSERT INTO %T (phid, authorPHID, objectPHID, viewPolicy, editPolicy, 119 commentPHID, commentVersion, transactionType, oldValue, newValue, 120 contentSource, metadata, dateCreated, dateModified) 121 VALUES (%s, %s, %s, %s, %s, %ns, %d, %s, %ns, %ns, %s, %s, %d, %d)', 122 'audit_transaction', 123 124 // PHID, authorPHID, objectPHID 125 $xaction_phid, 126 $row['actorPHID'], 127 $row['targetPHID'], 128 129 // viewPolicy, editPolicy, commentPHID, commentVersion 130 'public', 131 $row['actorPHID'], 132 $comment_phid, 133 $comment_version, 134 135 // transactionType, oldValue, newValue, contentSource, metadata 136 $xaction['type'], 137 json_encode($old), 138 json_encode($new), 139 $content_source, 140 json_encode($meta), 141 142 // dates 143 $row['dateCreated'], 144 $row['dateModified']); 145 } 146 147} 148 149echo pht('Done.')."\n";