@@ -27,85 +27,39 @@ public function processRequest() {
27
27
$ plan = $ step ->getBuildPlan ();
28
28
29
29
$ implementation = $ step ->getStepImplementation ();
30
- $ implementation ->validateSettingDefinitions ();
31
- $ settings = $ implementation ->getSettings ();
30
+
31
+ $ field_list = PhabricatorCustomField::getObjectFields (
32
+ $ step ,
33
+ PhabricatorCustomField::ROLE_EDIT );
34
+ $ field_list
35
+ ->setViewer ($ viewer )
36
+ ->readFieldsFromStorage ($ step );
32
37
33
38
$ errors = array ();
39
+ $ validation_exception = null ;
34
40
if ($ request ->isFormPost ()) {
35
- foreach ($ implementation ->getSettingDefinitions () as $ name => $ opt ) {
36
- $ readable_name = $ this ->getReadableName ($ name , $ opt );
37
- $ value = $ this ->getValueFromRequest ($ request , $ name , $ opt ['type ' ]);
38
-
39
- // TODO: This won't catch any validation issues unless the field
40
- // is missing completely. How should we check if the user is
41
- // required to enter an integer?
42
- if ($ value === null ) {
43
- $ errors [] = $ readable_name .' is not valid. ' ;
44
- } else {
45
- $ step ->setDetail ($ name , $ value );
46
- }
47
- }
41
+ $ xactions = $ field_list ->buildFieldTransactionsFromRequest (
42
+ new HarbormasterBuildStepTransaction (),
43
+ $ request );
48
44
49
- if (!$ errors ) {
50
- $ step ->save ();
45
+ $ editor = id (new HarbormasterBuildStepEditor ())
46
+ ->setActor ($ viewer )
47
+ ->setContinueOnNoEffect (true )
48
+ ->setContentSourceFromRequest ($ request );
49
+
50
+ try {
51
+ $ editor ->applyTransactions ($ step , $ xactions );
51
52
return id (new AphrontRedirectResponse ())
52
53
->setURI ($ this ->getApplicationURI ('plan/ ' .$ plan ->getID ().'/ ' ));
54
+ } catch (PhabricatorApplicationTransactionValidationException $ ex ) {
55
+ $ validation_exception = $ ex ;
53
56
}
54
57
}
55
58
56
59
$ form = id (new AphrontFormView ())
57
60
->setUser ($ viewer );
58
61
59
- // We need to render out all of the fields for the settings that
60
- // the implementation has.
61
- foreach ($ implementation ->getSettingDefinitions () as $ name => $ opt ) {
62
- if ($ request ->isFormPost ()) {
63
- $ value = $ this ->getValueFromRequest ($ request , $ name , $ opt ['type ' ]);
64
- } else {
65
- $ value = $ settings [$ name ];
66
- }
67
-
68
- switch ($ opt ['type ' ]) {
69
- case BuildStepImplementation::SETTING_TYPE_STRING :
70
- case BuildStepImplementation::SETTING_TYPE_INTEGER :
71
- $ control = id (new AphrontFormTextControl ())
72
- ->setLabel ($ this ->getReadableName ($ name , $ opt ))
73
- ->setName ($ name )
74
- ->setValue ($ value );
75
- break ;
76
- case BuildStepImplementation::SETTING_TYPE_BOOLEAN :
77
- $ control = id (new AphrontFormCheckboxControl ())
78
- ->setLabel ($ this ->getReadableName ($ name , $ opt ))
79
- ->setName ($ name )
80
- ->setValue ($ value );
81
- break ;
82
- case BuildStepImplementation::SETTING_TYPE_ARTIFACT :
83
- $ filter = $ opt ['artifact_type ' ];
84
- $ available_artifacts =
85
- BuildStepImplementation::loadAvailableArtifacts (
86
- $ plan ,
87
- $ step ,
88
- $ filter );
89
- $ options = array ();
90
- foreach ($ available_artifacts as $ key => $ type ) {
91
- $ options [$ key ] = $ key ;
92
- }
93
- $ control = id (new AphrontFormSelectControl ())
94
- ->setLabel ($ this ->getReadableName ($ name , $ opt ))
95
- ->setName ($ name )
96
- ->setValue ($ value )
97
- ->setOptions ($ options );
98
- break ;
99
- default :
100
- throw new Exception ("Unable to render field with unknown type. " );
101
- }
102
-
103
- if (isset ($ opt ['description ' ])) {
104
- $ control ->setCaption ($ opt ['description ' ]);
105
- }
106
-
107
- $ form ->appendChild ($ control );
108
- }
62
+ $ field_list ->appendFieldsToForm ($ form );
109
63
110
64
$ form ->appendChild (
111
65
id (new AphrontFormSubmitControl ())
@@ -115,7 +69,7 @@ public function processRequest() {
115
69
116
70
$ box = id (new PHUIObjectBoxView ())
117
71
->setHeaderText ('Edit Step: ' .$ implementation ->getName ())
118
- ->setValidationException (null )
72
+ ->setValidationException ($ validation_exception )
119
73
->setForm ($ form );
120
74
121
75
$ crumbs = $ this ->buildApplicationCrumbs ();
@@ -127,43 +81,30 @@ public function processRequest() {
127
81
128
82
$ variables = $ this ->renderBuildVariablesTable ();
129
83
84
+ $ xactions = id (new HarbormasterBuildStepTransactionQuery ())
85
+ ->setViewer ($ viewer )
86
+ ->withObjectPHIDs (array ($ step ->getPHID ()))
87
+ ->execute ();
88
+
89
+ $ xaction_view = id (new PhabricatorApplicationTransactionView ())
90
+ ->setUser ($ viewer )
91
+ ->setObjectPHID ($ step ->getPHID ())
92
+ ->setTransactions ($ xactions )
93
+ ->setShouldTerminate (true );
94
+
130
95
return $ this ->buildApplicationPage (
131
96
array (
132
97
$ crumbs ,
133
98
$ box ,
134
99
$ variables ,
100
+ $ xaction_view ,
135
101
),
136
102
array (
137
103
'title ' => $ implementation ->getName (),
138
104
'device ' => true ,
139
105
));
140
106
}
141
107
142
- public function getReadableName ($ name , $ opt ) {
143
- $ readable_name = $ name ;
144
- if (isset ($ opt ['name ' ])) {
145
- $ readable_name = $ opt ['name ' ];
146
- }
147
- return $ readable_name ;
148
- }
149
-
150
- public function getValueFromRequest (AphrontRequest $ request , $ name , $ type ) {
151
- switch ($ type ) {
152
- case BuildStepImplementation::SETTING_TYPE_STRING :
153
- case BuildStepImplementation::SETTING_TYPE_ARTIFACT :
154
- return $ request ->getStr ($ name );
155
- break ;
156
- case BuildStepImplementation::SETTING_TYPE_INTEGER :
157
- return $ request ->getInt ($ name );
158
- break ;
159
- case BuildStepImplementation::SETTING_TYPE_BOOLEAN :
160
- return $ request ->getBool ($ name );
161
- break ;
162
- default :
163
- throw new Exception ("Unsupported setting type ' " .$ type ."'. " );
164
- }
165
- }
166
-
167
108
private function renderBuildVariablesTable () {
168
109
$ viewer = $ this ->getRequest ()->getUser ();
169
110
0 commit comments