3 final class HarbormasterStepEditController
4 extends HarbormasterPlanController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $this->getViewer();
8 $id = $request->getURIData('id');
11 $step = id(new HarbormasterBuildStepQuery())
14 ->requireCapabilities(
16 PhabricatorPolicyCapability
::CAN_VIEW
,
17 PhabricatorPolicyCapability
::CAN_EDIT
,
21 return new Aphront404Response();
23 $plan = $step->getBuildPlan();
27 $plan_id = $request->getURIData('plan');
28 $class = $request->getURIData('class');
30 $plan = id(new HarbormasterBuildPlanQuery())
32 ->withIDs(array($plan_id))
33 ->requireCapabilities(
35 PhabricatorPolicyCapability
::CAN_VIEW
,
36 PhabricatorPolicyCapability
::CAN_EDIT
,
40 return new Aphront404Response();
43 $impl = HarbormasterBuildStepImplementation
::getImplementation($class);
45 return new Aphront404Response();
48 if ($impl->shouldRequireAutotargeting()) {
49 // No manual creation of autotarget steps.
50 return new Aphront404Response();
53 $step = HarbormasterBuildStep
::initializeNewStep($viewer)
54 ->setBuildPlanPHID($plan->getPHID())
55 ->setClassName($class);
60 $plan_uri = $this->getApplicationURI('plan/'.$plan->getID().'/');
63 $cancel_uri = $plan_uri;
65 $cancel_uri = $this->getApplicationURI('step/view/'.$step->getID().'/');
68 $implementation = $step->getStepImplementation();
70 $field_list = PhabricatorCustomField
::getObjectFields(
72 PhabricatorCustomField
::ROLE_EDIT
);
75 ->readFieldsFromStorage($step);
78 $v_name = $step->getName();
79 $e_description = null;
80 $v_description = $step->getDescription();
82 $v_depends_on = $step->getDetail('dependsOn', array());
85 $validation_exception = null;
86 if ($request->isFormPost()) {
88 $v_name = $request->getStr('name');
89 $v_description = $request->getStr('description');
90 $v_depends_on = $request->getArr('dependsOn');
92 $xactions = $field_list->buildFieldTransactionsFromRequest(
93 new HarbormasterBuildStepTransaction(),
96 $editor = id(new HarbormasterBuildStepEditor())
98 ->setContinueOnNoEffect(true)
99 ->setContentSourceFromRequest($request);
101 $name_xaction = id(new HarbormasterBuildStepTransaction())
102 ->setTransactionType(HarbormasterBuildStepTransaction
::TYPE_NAME
)
103 ->setNewValue($v_name);
104 array_unshift($xactions, $name_xaction);
106 $depends_on_xaction = id(new HarbormasterBuildStepTransaction())
107 ->setTransactionType(
108 HarbormasterBuildStepTransaction
::TYPE_DEPENDS_ON
)
109 ->setNewValue($v_depends_on);
110 array_unshift($xactions, $depends_on_xaction);
112 $description_xaction = id(new HarbormasterBuildStepTransaction())
113 ->setTransactionType(
114 HarbormasterBuildStepTransaction
::TYPE_DESCRIPTION
)
115 ->setNewValue($v_description);
116 array_unshift($xactions, $description_xaction);
119 // When creating a new step, make sure we have a create transaction
120 // so we'll apply the transactions even if the step has no
121 // configurable options.
122 $create_xaction = id(new HarbormasterBuildStepTransaction())
123 ->setTransactionType(HarbormasterBuildStepTransaction
::TYPE_CREATE
);
124 array_unshift($xactions, $create_xaction);
128 $editor->applyTransactions($step, $xactions);
130 $step_uri = $this->getApplicationURI('step/view/'.$step->getID().'/');
132 return id(new AphrontRedirectResponse())->setURI($step_uri);
133 } catch (PhabricatorApplicationTransactionValidationException
$ex) {
134 $validation_exception = $ex;
138 $form = id(new AphrontFormView())
141 $instructions = $implementation->getEditInstructions();
142 if (strlen($instructions)) {
143 $form->appendRemarkupInstructions($instructions);
147 id(new AphrontFormTextControl())
149 ->setLabel(pht('Name'))
151 ->setValue($v_name));
153 $form->appendChild(id(new AphrontFormDividerControl()));
155 $field_list->appendFieldsToForm($form);
157 $form->appendChild(id(new AphrontFormDividerControl()));
161 id(new AphrontFormTokenizerControl())
162 ->setDatasource(id(new HarbormasterBuildDependencyDatasource())
163 ->setParameters(array(
164 'planPHID' => $plan->getPHID(),
165 'stepPHID' => $is_new ?
null : $step->getPHID(),
167 ->setName('dependsOn')
168 ->setLabel(pht('Depends On'))
169 ->setError($e_depends_on)
170 ->setValue($v_depends_on));
174 id(new PhabricatorRemarkupControl())
176 ->setName('description')
177 ->setLabel(pht('Description'))
178 ->setError($e_description)
179 ->setValue($v_description));
181 $crumbs = $this->buildApplicationCrumbs();
182 $id = $plan->getID();
183 $crumbs->addTextCrumb(pht('Plan %d', $id), $plan_uri);
186 $submit = pht('Create Build Step');
187 $header = id(new PHUIHeaderView())
188 ->setHeader(pht('New Step: %s', $implementation->getName()))
189 ->setHeaderIcon('fa-plus-square');
190 $crumbs->addTextCrumb(pht('Add Step'));
192 $submit = pht('Save Build Step');
193 $header = id(new PHUIHeaderView())
194 ->setHeader(pht('Edit Step: %s', $implementation->getName()))
195 ->setHeaderIcon('fa-pencil');
196 $crumbs->addTextCrumb(pht('Step %d', $step->getID()), $cancel_uri);
197 $crumbs->addTextCrumb(pht('Edit Step'));
199 $crumbs->setBorder(true);
202 id(new AphrontFormSubmitControl())
204 ->addCancelButton($cancel_uri));
206 $box = id(new PHUIObjectBoxView())
207 ->setHeaderText(pht('Step'))
208 ->setValidationException($validation_exception)
209 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
212 $variables = $this->renderBuildVariablesTable();
215 $xaction_view = null;
218 $timeline = $this->buildTransactionTimeline(
220 new HarbormasterBuildStepTransactionQuery());
221 $timeline->setShouldTerminate(true);
224 $view = id(new PHUITwoColumnView())
232 return $this->newPage()
233 ->setTitle($implementation->getName())
235 ->appendChild($view);
239 private function renderBuildVariablesTable() {
240 $viewer = $this->getRequest()->getUser();
242 $variables = HarbormasterBuild
::getAvailableBuildVariables();
247 'The following variables can be used in most fields. '.
248 'To reference a variable, use `%s` in a field.',
254 $rows[] = '|---|---|';
255 foreach ($variables as $name => $description) {
256 $rows[] = '| `'.$name.'` | '.$description.' |';
258 $rows = implode("\n", $rows);
260 $form = id(new AphrontFormView())
262 ->appendRemarkupInstructions($rows);
264 return id(new PHUIObjectBoxView())
265 ->setHeaderText(pht('Build Variables'))
266 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
267 ->appendChild($form);