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

Replace "Edit" controller with "EditPro" controller

Summary: Ref T2222. Remove the old controller and swap in the new ApplicationTransactions one.

Test Plan: Made a pile of edits.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2222

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

+48 -253
-2
src/__phutil_library_map__.php
··· 466 466 'DifferentialRevisionControlSystem' => 'applications/differential/constants/DifferentialRevisionControlSystem.php', 467 467 'DifferentialRevisionDetailView' => 'applications/differential/view/DifferentialRevisionDetailView.php', 468 468 'DifferentialRevisionEditController' => 'applications/differential/controller/DifferentialRevisionEditController.php', 469 - 'DifferentialRevisionEditControllerPro' => 'applications/differential/controller/DifferentialRevisionEditControllerPro.php', 470 469 'DifferentialRevisionEditor' => 'applications/differential/editor/DifferentialRevisionEditor.php', 471 470 'DifferentialRevisionIDFieldParserTestCase' => 'applications/differential/field/specification/__tests__/DifferentialRevisionIDFieldParserTestCase.php', 472 471 'DifferentialRevisionIDFieldSpecification' => 'applications/differential/field/specification/DifferentialRevisionIDFieldSpecification.php', ··· 3034 3033 ), 3035 3034 'DifferentialRevisionDetailView' => 'AphrontView', 3036 3035 'DifferentialRevisionEditController' => 'DifferentialController', 3037 - 'DifferentialRevisionEditControllerPro' => 'DifferentialController', 3038 3036 'DifferentialRevisionEditor' => 'PhabricatorEditor', 3039 3037 'DifferentialRevisionIDFieldParserTestCase' => 'PhabricatorTestCase', 3040 3038 'DifferentialRevisionIDFieldSpecification' => 'DifferentialFieldSpecification',
-2
src/applications/differential/application/PhabricatorApplicationDifferential.php
··· 49 49 'changeset/' => 'DifferentialChangesetViewController', 50 50 'revision/edit/(?:(?P<id>[1-9]\d*)/)?' 51 51 => 'DifferentialRevisionEditController', 52 - 'revision/editpro/(?:(?P<id>[1-9]\d*)/)?' 53 - => 'DifferentialRevisionEditControllerPro', 54 52 'revision/land/(?:(?P<id>[1-9]\d*))/(?P<strategy>[^/]+)/' 55 53 => 'DifferentialRevisionLandController', 56 54 'comment/' => array(
+48 -64
src/applications/differential/controller/DifferentialRevisionEditController.php
··· 1 1 <?php 2 2 3 - final class DifferentialRevisionEditController extends DifferentialController { 3 + final class DifferentialRevisionEditController 4 + extends DifferentialController { 4 5 5 6 private $id; 6 7 ··· 22 23 ->withIDs(array($this->id)) 23 24 ->needRelationships(true) 24 25 ->needReviewerStatus(true) 26 + ->needActiveDiffs(true) 25 27 ->requireCapabilities( 26 28 array( 27 29 PhabricatorPolicyCapability::CAN_VIEW, ··· 33 35 } 34 36 } else { 35 37 $revision = DifferentialRevision::initializeNewRevision($viewer); 38 + $revision->attachReviewerStatus(array()); 36 39 } 37 - 38 - $aux_fields = $this->loadAuxiliaryFields($revision); 39 40 40 41 $diff_id = $request->getInt('diffID'); 41 42 if ($diff_id) { ··· 54 55 $diff = null; 55 56 } 56 57 57 - $errors = array(); 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 + } 58 66 67 + $field_list = PhabricatorCustomField::getObjectFields( 68 + $revision, 69 + PhabricatorCustomField::ROLE_EDIT); 70 + $field_list 71 + ->setViewer($viewer) 72 + ->readFieldsFromStorage($revision); 59 73 74 + $validation_exception = null; 60 75 if ($request->isFormPost() && !$request->getStr('viaDiffView')) { 61 - foreach ($aux_fields as $aux_field) { 62 - $aux_field->setValueFromRequest($request); 63 - try { 64 - $aux_field->validateField(); 65 - } catch (DifferentialFieldValidationException $ex) { 66 - $errors[] = $ex->getMessage(); 67 - } 76 + $xactions = $field_list->buildFieldTransactionsFromRequest( 77 + new DifferentialTransaction(), 78 + $request); 79 + 80 + if ($diff) { 81 + $xactions[] = id(new DifferentialTransaction()) 82 + ->setTransactionType(DifferentialTransaction::TYPE_UPDATE) 83 + ->setNewValue($diff->getPHID()); 68 84 } 69 85 70 - if (!$errors) { 71 - $is_new = !$revision->getID(); 72 - $user = $request->getUser(); 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 + } 73 94 74 - $editor = new DifferentialRevisionEditor($revision); 75 - $editor->setActor($request->getUser()); 76 - if ($diff) { 77 - $editor->addDiff($diff, $request->getStr('comments')); 78 - } 79 - $editor->setAuxiliaryFields($aux_fields); 80 - $editor->setAphrontRequestForEventDispatch($request); 81 - $editor->save(); 95 + $editor = id(new DifferentialTransactionEditor()) 96 + ->setActor($viewer) 97 + ->setContentSourceFromRequest($request) 98 + ->setContinueOnNoEffect(true); 82 99 83 - return id(new AphrontRedirectResponse()) 84 - ->setURI('/D'.$revision->getID()); 100 + try { 101 + $editor->applyTransactions($revision, $xactions); 102 + $revision_uri = '/D'.$revision->getID(); 103 + return id(new AphrontRedirectResponse())->setURI($revision_uri); 104 + } catch (PhabricatorApplicationTransactionValidationException $ex) { 105 + $validation_exception = $ex; 85 106 } 86 107 } 87 108 88 - $aux_phids = array(); 89 - foreach ($aux_fields as $key => $aux_field) { 90 - $aux_phids[$key] = $aux_field->getRequiredHandlePHIDsForRevisionEdit(); 91 - } 92 - $phids = array_mergev($aux_phids); 93 - $phids = array_unique($phids); 94 - $handles = $this->loadViewerHandles($phids); 95 - foreach ($aux_fields as $key => $aux_field) { 96 - $aux_field->setHandles(array_select_keys($handles, $aux_phids[$key])); 97 - } 98 109 99 110 $form = new AphrontFormView(); 100 111 $form->setUser($request->getUser()); ··· 123 134 id(new AphrontFormDividerControl())); 124 135 } 125 136 126 - $preview = array(); 127 - foreach ($aux_fields as $aux_field) { 128 - $control = $aux_field->renderEditControl(); 129 - if ($control) { 130 - $form->appendChild($control); 131 - } 132 - $preview[] = $aux_field->renderEditPreview(); 133 - } 137 + $field_list->appendFieldsToForm($form); 134 138 135 139 $submit = id(new AphrontFormSubmitControl()) 136 140 ->setValue('Save'); ··· 161 165 162 166 $form_box = id(new PHUIObjectBoxView()) 163 167 ->setHeaderText($title) 164 - ->setFormErrors($errors) 168 + ->setValidationException($validation_exception) 165 169 ->setForm($form); 166 170 167 171 $crumbs->addTextCrumb($title); ··· 170 174 array( 171 175 $crumbs, 172 176 $form_box, 173 - $preview), 177 + ), 174 178 array( 175 179 'title' => $title, 176 180 'device' => true, 177 181 )); 178 - } 179 - 180 - private function loadAuxiliaryFields(DifferentialRevision $revision) { 181 - 182 - $user = $this->getRequest()->getUser(); 183 - 184 - $aux_fields = DifferentialFieldSelector::newSelector() 185 - ->getFieldSpecifications(); 186 - foreach ($aux_fields as $key => $aux_field) { 187 - $aux_field->setRevision($revision); 188 - if (!$aux_field->shouldAppearOnEdit()) { 189 - unset($aux_fields[$key]); 190 - } else { 191 - $aux_field->setUser($user); 192 - } 193 - } 194 - 195 - return DifferentialAuxiliaryField::loadFromStorage( 196 - $revision, 197 - $aux_fields); 198 182 } 199 183 200 184 }
-185
src/applications/differential/controller/DifferentialRevisionEditControllerPro.php
··· 1 - <?php 2 - 3 - final class DifferentialRevisionEditControllerPro 4 - extends DifferentialController { 5 - 6 - private $id; 7 - 8 - public function willProcessRequest(array $data) { 9 - $this->id = idx($data, 'id'); 10 - } 11 - 12 - public function processRequest() { 13 - $request = $this->getRequest(); 14 - $viewer = $request->getUser(); 15 - 16 - if (!$this->id) { 17 - $this->id = $request->getInt('revisionID'); 18 - } 19 - 20 - if ($this->id) { 21 - $revision = id(new DifferentialRevisionQuery()) 22 - ->setViewer($viewer) 23 - ->withIDs(array($this->id)) 24 - ->needRelationships(true) 25 - ->needReviewerStatus(true) 26 - ->needActiveDiffs(true) 27 - ->requireCapabilities( 28 - array( 29 - PhabricatorPolicyCapability::CAN_VIEW, 30 - PhabricatorPolicyCapability::CAN_EDIT, 31 - )) 32 - ->executeOne(); 33 - if (!$revision) { 34 - return new Aphront404Response(); 35 - } 36 - } else { 37 - $revision = DifferentialRevision::initializeNewRevision($viewer); 38 - $revision->attachReviewerStatus(array()); 39 - } 40 - 41 - $diff_id = $request->getInt('diffID'); 42 - if ($diff_id) { 43 - $diff = id(new DifferentialDiffQuery()) 44 - ->setViewer($viewer) 45 - ->withIDs(array($diff_id)) 46 - ->executeOne(); 47 - if (!$diff) { 48 - return new Aphront404Response(); 49 - } 50 - if ($diff->getRevisionID()) { 51 - // TODO: Redirect? 52 - throw new Exception("This diff is already attached to a revision!"); 53 - } 54 - } else { 55 - $diff = null; 56 - } 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 - 67 - $field_list = PhabricatorCustomField::getObjectFields( 68 - $revision, 69 - PhabricatorCustomField::ROLE_EDIT); 70 - $field_list 71 - ->setViewer($viewer) 72 - ->readFieldsFromStorage($revision); 73 - 74 - $validation_exception = null; 75 - if ($request->isFormPost() && !$request->getStr('viaDiffView')) { 76 - $xactions = $field_list->buildFieldTransactionsFromRequest( 77 - new DifferentialTransaction(), 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 - } 94 - 95 - $editor = id(new DifferentialTransactionEditor()) 96 - ->setActor($viewer) 97 - ->setContentSourceFromRequest($request) 98 - ->setContinueOnNoEffect(true); 99 - 100 - try { 101 - $editor->applyTransactions($revision, $xactions); 102 - $revision_uri = '/D'.$revision->getID(); 103 - return id(new AphrontRedirectResponse())->setURI($revision_uri); 104 - } catch (PhabricatorApplicationTransactionValidationException $ex) { 105 - $validation_exception = $ex; 106 - } 107 - } 108 - 109 - 110 - $form = new AphrontFormView(); 111 - $form->setUser($request->getUser()); 112 - if ($diff) { 113 - $form->addHiddenInput('diffID', $diff->getID()); 114 - } 115 - 116 - if ($revision->getID()) { 117 - $form->setAction( 118 - '/differential/revision/editpro/'.$revision->getID().'/'); 119 - } else { 120 - $form->setAction('/differential/revision/editpro/'); 121 - } 122 - 123 - if ($diff && $revision->getID()) { 124 - $form 125 - ->appendChild( 126 - id(new AphrontFormTextAreaControl()) 127 - ->setLabel(pht('Comments')) 128 - ->setName('comments') 129 - ->setCaption(pht("Explain what's new in this diff.")) 130 - ->setValue($request->getStr('comments'))) 131 - ->appendChild( 132 - id(new AphrontFormSubmitControl()) 133 - ->setValue(pht('Save'))) 134 - ->appendChild( 135 - id(new AphrontFormDividerControl())); 136 - } 137 - 138 - $field_list->appendFieldsToForm($form); 139 - 140 - $submit = id(new AphrontFormSubmitControl()) 141 - ->setValue('Save'); 142 - if ($diff) { 143 - $submit->addCancelButton('/differential/diff/'.$diff->getID().'/'); 144 - } else { 145 - $submit->addCancelButton('/D'.$revision->getID()); 146 - } 147 - 148 - $form->appendChild($submit); 149 - 150 - $crumbs = $this->buildApplicationCrumbs(); 151 - if ($revision->getID()) { 152 - if ($diff) { 153 - $title = pht('Update Differential Revision'); 154 - $crumbs->addTextCrumb( 155 - 'D'.$revision->getID(), 156 - '/differential/diff/'.$diff->getID().'/'); 157 - } else { 158 - $title = pht('Edit Differential Revision'); 159 - $crumbs->addTextCrumb( 160 - 'D'.$revision->getID(), 161 - '/D'.$revision->getID()); 162 - } 163 - } else { 164 - $title = pht('Create New Differential Revision'); 165 - } 166 - 167 - $form_box = id(new PHUIObjectBoxView()) 168 - ->setHeaderText($title) 169 - ->setValidationException($validation_exception) 170 - ->setForm($form); 171 - 172 - $crumbs->addTextCrumb($title); 173 - 174 - return $this->buildApplicationPage( 175 - array( 176 - $crumbs, 177 - $form_box, 178 - ), 179 - array( 180 - 'title' => $title, 181 - 'device' => true, 182 - )); 183 - } 184 - 185 - }