[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class HarbormasterStepEditController extends HarbormasterController { 4 5 private $id; 6 private $planID; 7 private $className; 8 9 public function willProcessRequest(array $data) { 10 $this->id = idx($data, 'id'); 11 $this->planID = idx($data, 'plan'); 12 $this->className = idx($data, 'class'); 13 } 14 15 public function processRequest() { 16 $request = $this->getRequest(); 17 $viewer = $request->getUser(); 18 19 $this->requireApplicationCapability( 20 HarbormasterManagePlansCapability::CAPABILITY); 21 22 if ($this->id) { 23 $step = id(new HarbormasterBuildStepQuery()) 24 ->setViewer($viewer) 25 ->withIDs(array($this->id)) 26 ->executeOne(); 27 if (!$step) { 28 return new Aphront404Response(); 29 } 30 $plan = $step->getBuildPlan(); 31 32 $is_new = false; 33 } else { 34 $plan = id(new HarbormasterBuildPlanQuery()) 35 ->setViewer($viewer) 36 ->withIDs(array($this->planID)) 37 ->executeOne(); 38 if (!$plan) { 39 return new Aphront404Response(); 40 } 41 42 $impl = HarbormasterBuildStepImplementation::getImplementation( 43 $this->className); 44 if (!$impl) { 45 return new Aphront404Response(); 46 } 47 48 $step = HarbormasterBuildStep::initializeNewStep($viewer) 49 ->setBuildPlanPHID($plan->getPHID()) 50 ->setClassName($this->className); 51 52 $is_new = true; 53 } 54 55 $plan_uri = $this->getApplicationURI('plan/'.$plan->getID().'/'); 56 57 $implementation = $step->getStepImplementation(); 58 59 $field_list = PhabricatorCustomField::getObjectFields( 60 $step, 61 PhabricatorCustomField::ROLE_EDIT); 62 $field_list 63 ->setViewer($viewer) 64 ->readFieldsFromStorage($step); 65 66 $e_name = true; 67 $v_name = $step->getName(); 68 $e_description = true; 69 $v_description = $step->getDescription(); 70 $e_depends_on = true; 71 $raw_depends_on = $step->getDetail('dependsOn', array()); 72 73 $v_depends_on = id(new PhabricatorHandleQuery()) 74 ->setViewer($viewer) 75 ->withPHIDs($raw_depends_on) 76 ->execute(); 77 78 $errors = array(); 79 $validation_exception = null; 80 if ($request->isFormPost()) { 81 $e_name = null; 82 $v_name = $request->getStr('name'); 83 $e_description = null; 84 $v_description = $request->getStr('description'); 85 $e_depends_on = null; 86 $v_depends_on = $request->getArr('dependsOn'); 87 88 $xactions = $field_list->buildFieldTransactionsFromRequest( 89 new HarbormasterBuildStepTransaction(), 90 $request); 91 92 $editor = id(new HarbormasterBuildStepEditor()) 93 ->setActor($viewer) 94 ->setContinueOnNoEffect(true) 95 ->setContentSourceFromRequest($request); 96 97 $name_xaction = id(new HarbormasterBuildStepTransaction()) 98 ->setTransactionType(HarbormasterBuildStepTransaction::TYPE_NAME) 99 ->setNewValue($v_name); 100 array_unshift($xactions, $name_xaction); 101 102 $depends_on_xaction = id(new HarbormasterBuildStepTransaction()) 103 ->setTransactionType( 104 HarbormasterBuildStepTransaction::TYPE_DEPENDS_ON) 105 ->setNewValue($v_depends_on); 106 array_unshift($xactions, $depends_on_xaction); 107 108 $description_xaction = id(new HarbormasterBuildStepTransaction()) 109 ->setTransactionType( 110 HarbormasterBuildStepTransaction::TYPE_DESCRIPTION) 111 ->setNewValue($v_description); 112 array_unshift($xactions, $description_xaction); 113 114 if ($is_new) { 115 // When creating a new step, make sure we have a create transaction 116 // so we'll apply the transactions even if the step has no 117 // configurable options. 118 $create_xaction = id(new HarbormasterBuildStepTransaction()) 119 ->setTransactionType(HarbormasterBuildStepTransaction::TYPE_CREATE); 120 array_unshift($xactions, $create_xaction); 121 } 122 123 try { 124 $editor->applyTransactions($step, $xactions); 125 return id(new AphrontRedirectResponse())->setURI($plan_uri); 126 } catch (PhabricatorApplicationTransactionValidationException $ex) { 127 $validation_exception = $ex; 128 } 129 } 130 131 $form = id(new AphrontFormView()) 132 ->setUser($viewer) 133 ->appendChild( 134 id(new AphrontFormTextControl()) 135 ->setName('name') 136 ->setLabel(pht('Name')) 137 ->setError($e_name) 138 ->setValue($v_name)); 139 140 $form 141 ->appendChild( 142 id(new AphrontFormTokenizerControl()) 143 ->setDatasource(id(new HarbormasterBuildDependencyDatasource()) 144 ->setParameters(array( 145 'planPHID' => $plan->getPHID(), 146 'stepPHID' => $is_new ? null : $step->getPHID(), 147 ))) 148 ->setName('dependsOn') 149 ->setLabel(pht('Depends On')) 150 ->setError($e_depends_on) 151 ->setValue($v_depends_on)); 152 153 $field_list->appendFieldsToForm($form); 154 155 $form 156 ->appendChild( 157 id(new PhabricatorRemarkupControl()) 158 ->setUser($viewer) 159 ->setName('description') 160 ->setLabel(pht('Description')) 161 ->setError($e_description) 162 ->setValue($v_description)); 163 164 if ($is_new) { 165 $submit = pht('Create Build Step'); 166 $header = pht('New Step: %s', $implementation->getName()); 167 $crumb = pht('Add Step'); 168 } else { 169 $submit = pht('Save Build Step'); 170 $header = pht('Edit Step: %s', $implementation->getName()); 171 $crumb = pht('Edit Step'); 172 } 173 174 $form->appendChild( 175 id(new AphrontFormSubmitControl()) 176 ->setValue($submit) 177 ->addCancelButton($plan_uri)); 178 179 $box = id(new PHUIObjectBoxView()) 180 ->setHeaderText($header) 181 ->setValidationException($validation_exception) 182 ->setForm($form); 183 184 $crumbs = $this->buildApplicationCrumbs(); 185 $id = $plan->getID(); 186 $crumbs->addTextCrumb(pht('Plan %d', $id), $plan_uri); 187 $crumbs->addTextCrumb($crumb); 188 189 $variables = $this->renderBuildVariablesTable(); 190 191 if ($is_new) { 192 $xaction_view = null; 193 } else { 194 $xactions = id(new HarbormasterBuildStepTransactionQuery()) 195 ->setViewer($viewer) 196 ->withObjectPHIDs(array($step->getPHID())) 197 ->execute(); 198 199 $xaction_view = id(new PhabricatorApplicationTransactionView()) 200 ->setUser($viewer) 201 ->setObjectPHID($step->getPHID()) 202 ->setTransactions($xactions) 203 ->setShouldTerminate(true); 204 } 205 206 return $this->buildApplicationPage( 207 array( 208 $crumbs, 209 $box, 210 $variables, 211 $xaction_view, 212 ), 213 array( 214 'title' => $implementation->getName(), 215 )); 216 } 217 218 private function renderBuildVariablesTable() { 219 $viewer = $this->getRequest()->getUser(); 220 221 $variables = HarbormasterBuild::getAvailableBuildVariables(); 222 ksort($variables); 223 224 $rows = array(); 225 $rows[] = pht( 226 'The following variables can be used in most fields. To reference '. 227 'a variable, use `$name}` in a field.'); 228 $rows[] = pht('| Variable | Description |'); 229 $rows[] = '|---|---|'; 230 foreach ($variables as $name => $description) { 231 $rows[] = '| `'.$name.'` | '.$description.' |'; 232 } 233 $rows = implode("\n", $rows); 234 235 $form = id(new AphrontFormView()) 236 ->setUser($viewer) 237 ->appendRemarkupInstructions($rows); 238 239 return id(new PHUIObjectBoxView()) 240 ->setHeaderText(pht('Build Variables')) 241 ->appendChild($form); 242 } 243 244 }
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 |