3 final class HarbormasterBuildStep
extends HarbormasterDAO
5 PhabricatorApplicationTransactionInterface
,
6 PhabricatorPolicyInterface
,
7 PhabricatorCustomFieldInterface
,
8 PhabricatorConduitResultInterface
{
11 protected $description;
12 protected $buildPlanPHID;
14 protected $details = array();
15 protected $sequence = 0;
16 protected $stepAutoKey;
18 private $buildPlan = self
::ATTACHABLE
;
19 private $customFields = self
::ATTACHABLE
;
20 private $implementation;
22 public static function initializeNewStep(PhabricatorUser
$actor) {
23 return id(new HarbormasterBuildStep())
28 protected function getConfiguration() {
30 self
::CONFIG_AUX_PHID
=> true,
31 self
::CONFIG_SERIALIZATION
=> array(
32 'details' => self
::SERIALIZATION_JSON
,
34 self
::CONFIG_COLUMN_SCHEMA
=> array(
35 'className' => 'text255',
36 'sequence' => 'uint32',
37 'description' => 'text',
40 // This should not be nullable. Current `null` values indicate steps
41 // which predated editable names. These should be backfilled with
42 // default names, then the code for handling `null` should be removed.
44 'stepAutoKey' => 'text32?',
46 self
::CONFIG_KEY_SCHEMA
=> array(
48 'columns' => array('buildPlanPHID'),
50 'key_stepautokey' => array(
51 'columns' => array('buildPlanPHID', 'stepAutoKey'),
55 ) + parent
::getConfiguration();
58 public function generatePHID() {
59 return PhabricatorPHID
::generateNewPHID(
60 HarbormasterBuildStepPHIDType
::TYPECONST
);
63 public function attachBuildPlan(HarbormasterBuildPlan
$plan) {
64 $this->buildPlan
= $plan;
68 public function getBuildPlan() {
69 return $this->assertAttached($this->buildPlan
);
72 public function getDetail($key, $default = null) {
73 return idx($this->details
, $key, $default);
76 public function setDetail($key, $value) {
77 $this->details
[$key] = $value;
81 public function getName() {
82 if (strlen($this->name
)) {
86 return $this->getStepImplementation()->getName();
89 public function getStepImplementation() {
90 if ($this->implementation
=== null) {
91 $obj = HarbormasterBuildStepImplementation
::requireImplementation(
93 $obj->loadSettings($this);
94 $this->implementation
= $obj;
97 return $this->implementation
;
100 public function isAutostep() {
101 return ($this->getStepAutoKey() !== null);
104 public function willStartBuild(
105 PhabricatorUser
$viewer,
106 HarbormasterBuildable
$buildable,
107 HarbormasterBuild
$build,
108 HarbormasterBuildPlan
$plan) {
109 return $this->getStepImplementation()->willStartBuild(
118 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
121 public function getApplicationTransactionEditor() {
122 return new HarbormasterBuildStepEditor();
125 public function getApplicationTransactionTemplate() {
126 return new HarbormasterBuildStepTransaction();
130 /* -( PhabricatorPolicyInterface )----------------------------------------- */
133 public function getCapabilities() {
135 PhabricatorPolicyCapability
::CAN_VIEW
,
136 PhabricatorPolicyCapability
::CAN_EDIT
,
140 public function getPolicy($capability) {
141 return $this->getBuildPlan()->getPolicy($capability);
144 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
145 return $this->getBuildPlan()->hasAutomaticCapability($capability, $viewer);
148 public function describeAutomaticCapability($capability) {
149 return pht('A build step has the same policies as its build plan.');
153 /* -( PhabricatorCustomFieldInterface )------------------------------------ */
156 public function getCustomFieldSpecificationForRole($role) {
160 public function getCustomFieldBaseClass() {
161 return 'HarbormasterBuildStepCustomField';
164 public function getCustomFields() {
165 return $this->assertAttached($this->customFields
);
168 public function attachCustomFields(PhabricatorCustomFieldAttachment
$fields) {
169 $this->customFields
= $fields;
173 /* -( PhabricatorConduitResultInterface )---------------------------------- */
176 public function getFieldSpecificationsForConduit() {
178 id(new PhabricatorConduitSearchFieldSpecification())
181 ->setDescription(pht('The name of the build step.')),
182 id(new PhabricatorConduitSearchFieldSpecification())
183 ->setKey('description')
184 ->setType('remarkup')
185 ->setDescription(pht('The build step description.')),
186 id(new PhabricatorConduitSearchFieldSpecification())
187 ->setKey('buildPlanPHID')
191 'The PHID of the build plan this build step belongs to.')),
195 public function getFieldValuesForConduit() {
196 // T6203: This can be removed once the field becomes non-nullable.
197 $name = $this->getName();
198 $name = phutil_string_cast($name);
202 'description' => array(
203 'raw' => $this->getDescription(),
205 'buildPlanPHID' => $this->getBuildPlanPHID(),
209 public function getConduitSearchAttachments() {