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