Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / harbormaster / storage / configuration / HarbormasterBuildStep.php
blob71b050adfffc10ac340a7e49ce2c36f9b038f7d3
1 <?php
3 final class HarbormasterBuildStep extends HarbormasterDAO
4 implements
5 PhabricatorApplicationTransactionInterface,
6 PhabricatorPolicyInterface,
7 PhabricatorCustomFieldInterface,
8 PhabricatorConduitResultInterface {
10 protected $name;
11 protected $description;
12 protected $buildPlanPHID;
13 protected $className;
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())
24 ->setName('')
25 ->setDescription('');
28 protected function getConfiguration() {
29 return array(
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',
39 // T6203/NULLABILITY
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.
43 'name' => 'text255?',
44 'stepAutoKey' => 'text32?',
46 self::CONFIG_KEY_SCHEMA => array(
47 'key_plan' => array(
48 'columns' => array('buildPlanPHID'),
50 'key_stepautokey' => array(
51 'columns' => array('buildPlanPHID', 'stepAutoKey'),
52 'unique' => true,
55 ) + parent::getConfiguration();
58 public function generatePHID() {
59 return PhabricatorPHID::generateNewPHID(
60 HarbormasterBuildStepPHIDType::TYPECONST);
63 public function attachBuildPlan(HarbormasterBuildPlan $plan) {
64 $this->buildPlan = $plan;
65 return $this;
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;
78 return $this;
81 public function getName() {
82 if (strlen($this->name)) {
83 return $this->name;
86 return $this->getStepImplementation()->getName();
89 public function getStepImplementation() {
90 if ($this->implementation === null) {
91 $obj = HarbormasterBuildStepImplementation::requireImplementation(
92 $this->className);
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(
110 $viewer,
111 $buildable,
112 $build,
113 $plan,
114 $this);
118 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
121 public function getApplicationTransactionEditor() {
122 return new HarbormasterBuildStepEditor();
125 public function getApplicationTransactionTemplate() {
126 return new HarbormasterBuildStepTransaction();
130 /* -( PhabricatorPolicyInterface )----------------------------------------- */
133 public function getCapabilities() {
134 return array(
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) {
157 return array();
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;
170 return $this;
173 /* -( PhabricatorConduitResultInterface )---------------------------------- */
176 public function getFieldSpecificationsForConduit() {
177 return array(
178 id(new PhabricatorConduitSearchFieldSpecification())
179 ->setKey('name')
180 ->setType('string')
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')
188 ->setType('phid')
189 ->setDescription(
190 pht(
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);
200 return array(
201 'name' => $name,
202 'description' => array(
203 'raw' => $this->getDescription(),
205 'buildPlanPHID' => $this->getBuildPlanPHID(),
209 public function getConduitSearchAttachments() {
210 return array();