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

Make "EditPro" controller work with diff updates

Summary:
Ref T2222. Make the "EditPro" controller accommodate diff updates, and support the transaction type. This one is pretty straightforward.

Also make `revisionPHID` in the comments table nullable to fix the "Edit" action.

Test Plan:
- Created new revision.
- Updated revision.
- Tried to do some invalid stuff.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2222

Differential Revision: https://secure.phabricator.com/D8376

+117 -14
+4
resources/sql/autopatches/20140228.dxcomment.1.sql
··· 1 + /* Make this column nullable. */ 2 + 3 + ALTER TABLE {$NAMESPACE}_differential.differential_transaction_comment 4 + CHANGE revisionPHID revisionPHID VARCHAR(64) COLLATE utf8_bin;
+2 -1
src/applications/differential/controller/DifferentialDiffViewController.php
··· 58 58 array( 59 59 'value' => $revision->getID(), 60 60 ), 61 - 'D'.$revision->getID().' '.$revision->getTitle()); 61 + phutil_utf8_shorten( 62 + 'D'.$revision->getID().' '.$revision->getTitle(), 128)); 62 63 } 63 64 $select[] = hsprintf('</optgroup>'); 64 65 }
+26
src/applications/differential/controller/DifferentialRevisionEditControllerPro.php
··· 23 23 ->withIDs(array($this->id)) 24 24 ->needRelationships(true) 25 25 ->needReviewerStatus(true) 26 + ->needActiveDiffs(true) 26 27 ->requireCapabilities( 27 28 array( 28 29 PhabricatorPolicyCapability::CAN_VIEW, ··· 34 35 } 35 36 } else { 36 37 $revision = DifferentialRevision::initializeNewRevision($viewer); 38 + $revision->attachReviewerStatus(array()); 37 39 } 38 40 39 41 $diff_id = $request->getInt('diffID'); ··· 53 55 $diff = null; 54 56 } 55 57 58 + if (!$diff) { 59 + if (!$revision->getID()) { 60 + throw new Exception( 61 + pht('You can not create a new revision without a diff!')); 62 + } 63 + } else { 64 + // TODO: It would be nice to show the diff being attached in the UI. 65 + } 66 + 56 67 $field_list = PhabricatorCustomField::getObjectFields( 57 68 $revision, 58 69 PhabricatorCustomField::ROLE_EDIT); ··· 65 76 $xactions = $field_list->buildFieldTransactionsFromRequest( 66 77 new DifferentialTransaction(), 67 78 $request); 79 + 80 + if ($diff) { 81 + $xactions[] = id(new DifferentialTransaction()) 82 + ->setTransactionType(DifferentialTransaction::TYPE_UPDATE) 83 + ->setNewValue($diff->getPHID()); 84 + } 85 + 86 + $comments = $request->getStr('comments'); 87 + if (strlen($comments)) { 88 + $xactions[] = id(new DifferentialTransaction()) 89 + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) 90 + ->attachComment( 91 + id(new DifferentialTransactionComment()) 92 + ->setContent($comments)); 93 + } 68 94 69 95 $editor = id(new DifferentialTransactionEditor()) 70 96 ->setActor($viewer)
-5
src/applications/differential/controller/DifferentialRevisionViewController.php
··· 881 881 ->setRightDiff($right_diff) 882 882 ->setTransactions($xactions); 883 883 884 - // TODO: Make this work and restore edit links. We need to copy 885 - // `revisionPHID` to the new version of the comment. This should be simple, 886 - // but can happen post-merge. See T2222. 887 - $timeline->setShowEditActions(false); 888 - 889 884 return $timeline; 890 885 } 891 886
+58 -4
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 14 14 $types[] = DifferentialTransaction::TYPE_ACTION; 15 15 $types[] = DifferentialTransaction::TYPE_INLINE; 16 16 $types[] = DifferentialTransaction::TYPE_STATUS; 17 - 18 - /* 19 - 20 17 $types[] = DifferentialTransaction::TYPE_UPDATE; 21 - */ 22 18 23 19 return $types; 24 20 } ··· 36 32 return null; 37 33 case DifferentialTransaction::TYPE_INLINE: 38 34 return null; 35 + case DifferentialTransaction::TYPE_UPDATE: 36 + if ($this->getIsNewObject()) { 37 + return null; 38 + } else { 39 + return $object->getActiveDiff()->getPHID(); 40 + } 39 41 } 40 42 41 43 return parent::getCustomTransactionOldValue($object, $xaction); ··· 49 51 case PhabricatorTransactions::TYPE_VIEW_POLICY: 50 52 case PhabricatorTransactions::TYPE_EDIT_POLICY: 51 53 case DifferentialTransaction::TYPE_ACTION: 54 + case DifferentialTransaction::TYPE_UPDATE: 52 55 return $xaction->getNewValue(); 53 56 case DifferentialTransaction::TYPE_INLINE: 54 57 return null; ··· 146 149 case DifferentialTransaction::TYPE_INLINE: 147 150 return; 148 151 case PhabricatorTransactions::TYPE_EDGE: 152 + return; 153 + case DifferentialTransaction::TYPE_UPDATE: 154 + // TODO: Update the `diffPHID` once we add that. 149 155 return; 150 156 case DifferentialTransaction::TYPE_ACTION: 151 157 $status_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW; ··· 336 342 case DifferentialTransaction::TYPE_ACTION: 337 343 case DifferentialTransaction::TYPE_INLINE: 338 344 return; 345 + case DifferentialTransaction::TYPE_UPDATE: 346 + // Now that we're inside the transaction, do a final check. 347 + $diff = $this->loadDiff($xaction->getNewValue()); 348 + 349 + // TODO: It would be slightly cleaner to just revalidate this 350 + // transaction somehow using the same validation code, but that's 351 + // not easy to do at the moment. 352 + 353 + if (!$diff) { 354 + throw new Exception(pht('Diff does not exist!')); 355 + } else { 356 + $revision_id = $diff->getRevisionID(); 357 + if ($revision_id && ($revision_id != $object->getID())) { 358 + throw new Exception( 359 + pht( 360 + 'Diff is already attached to another revision. You lost '. 361 + 'a race?')); 362 + } 363 + } 364 + 365 + $diff->setRevisionID($object->getID()); 366 + $diff->save(); 367 + return; 339 368 } 340 369 341 370 return parent::applyCustomExternalTransaction($object, $xaction); ··· 471 500 472 501 foreach ($xactions as $xaction) { 473 502 switch ($type) { 503 + case DifferentialTransaction::TYPE_UPDATE: 504 + $diff = $this->loadDiff($xaction->getNewValue()); 505 + if (!$diff) { 506 + $errors[] = new PhabricatorApplicationTransactionValidationError( 507 + $type, 508 + pht('Invalid'), 509 + pht('The specified diff does not exist.'), 510 + $xaction); 511 + } else if (($diff->getRevisionID()) && 512 + ($diff->getRevisionID() != $object->getID())) { 513 + $errors[] = new PhabricatorApplicationTransactionValidationError( 514 + $type, 515 + pht('Invalid'), 516 + pht( 517 + 'You can not update this revision to the specified diff, '. 518 + 'because the diff is already attached to another revision.'), 519 + $xaction); 520 + } 521 + break; 474 522 case DifferentialTransaction::TYPE_ACTION: 475 523 $error = $this->validateDifferentialAction( 476 524 $object, ··· 966 1014 return implode("\n", $result); 967 1015 } 968 1016 1017 + private function loadDiff($phid) { 1018 + return id(new DifferentialDiffQuery()) 1019 + ->withPHIDs(array($phid)) 1020 + ->setViewer($this->getActor()) 1021 + ->executeOne(); 1022 + } 969 1023 970 1024 971 1025 }
+1
src/applications/differential/phid/DifferentialPHIDTypeDiff.php
··· 35 35 $id = $diff->getID(); 36 36 37 37 $handle->setName(pht('Diff %d', $id)); 38 + $handle->setURI("/differential/diff/{$id}/"); 38 39 } 39 40 } 40 41
+26 -4
src/applications/differential/storage/DifferentialTransaction.php
··· 70 70 return parent::getBodyForMail(); 71 71 } 72 72 73 + public function getRequiredHandlePHIDs() { 74 + $phids = parent::getRequiredHandlePHIDs(); 75 + 76 + $old = $this->getOldValue(); 77 + $new = $this->getNewValue(); 78 + 79 + switch ($this->getTransactionType()) { 80 + case self::TYPE_UPDATE: 81 + if ($new) { 82 + $phids[] = $new; 83 + } 84 + break; 85 + } 86 + 87 + return $phids; 88 + } 73 89 74 90 public function getTitle() { 75 91 $author_phid = $this->getAuthorPHID(); ··· 87 103 if ($new) { 88 104 // TODO: Migrate to PHIDs and use handles here? 89 105 // TODO: Link this? 90 - return pht( 91 - '%s updated this revision to Diff #%d.', 92 - $author_handle, 93 - $new); 106 + if (phid_get_type($new) == 'DIFF') { 107 + return pht( 108 + '%s updated this revision to %s.', 109 + $author_handle, 110 + $this->renderHandleLink($new)); 111 + } else { 112 + return pht( 113 + '%s updated this revision.', 114 + $author_handle); 115 + } 94 116 } else { 95 117 return pht( 96 118 '%s updated this revision.',