[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class HarbormasterBuildTarget extends HarbormasterDAO 4 implements PhabricatorPolicyInterface { 5 6 protected $name; 7 protected $buildPHID; 8 protected $buildStepPHID; 9 protected $className; 10 protected $details; 11 protected $variables; 12 protected $targetStatus; 13 protected $dateStarted; 14 protected $dateCompleted; 15 protected $buildGeneration; 16 17 const STATUS_PENDING = 'target/pending'; 18 const STATUS_BUILDING = 'target/building'; 19 const STATUS_WAITING = 'target/waiting'; 20 const STATUS_PASSED = 'target/passed'; 21 const STATUS_FAILED = 'target/failed'; 22 const STATUS_ABORTED = 'target/aborted'; 23 24 private $build = self::ATTACHABLE; 25 private $buildStep = self::ATTACHABLE; 26 private $implementation; 27 28 public static function getBuildTargetStatusName($status) { 29 switch ($status) { 30 case self::STATUS_PENDING: 31 return pht('Pending'); 32 case self::STATUS_BUILDING: 33 return pht('Building'); 34 case self::STATUS_WAITING: 35 return pht('Waiting for Message'); 36 case self::STATUS_PASSED: 37 return pht('Passed'); 38 case self::STATUS_FAILED: 39 return pht('Failed'); 40 case self::STATUS_ABORTED: 41 return pht('Aborted'); 42 default: 43 return pht('Unknown'); 44 } 45 } 46 47 public static function getBuildTargetStatusIcon($status) { 48 switch ($status) { 49 case self::STATUS_PENDING: 50 return PHUIStatusItemView::ICON_OPEN; 51 case self::STATUS_BUILDING: 52 case self::STATUS_WAITING: 53 return PHUIStatusItemView::ICON_RIGHT; 54 case self::STATUS_PASSED: 55 return PHUIStatusItemView::ICON_ACCEPT; 56 case self::STATUS_FAILED: 57 return PHUIStatusItemView::ICON_REJECT; 58 case self::STATUS_ABORTED: 59 return PHUIStatusItemView::ICON_MINUS; 60 default: 61 return PHUIStatusItemView::ICON_QUESTION; 62 } 63 } 64 65 public static function getBuildTargetStatusColor($status) { 66 switch ($status) { 67 case self::STATUS_PENDING: 68 case self::STATUS_BUILDING: 69 case self::STATUS_WAITING: 70 return 'blue'; 71 case self::STATUS_PASSED: 72 return 'green'; 73 case self::STATUS_FAILED: 74 case self::STATUS_ABORTED: 75 return 'red'; 76 default: 77 return 'bluegrey'; 78 } 79 } 80 81 public static function initializeNewBuildTarget( 82 HarbormasterBuild $build, 83 HarbormasterBuildStep $build_step, 84 array $variables) { 85 return id(new HarbormasterBuildTarget()) 86 ->setName($build_step->getName()) 87 ->setBuildPHID($build->getPHID()) 88 ->setBuildStepPHID($build_step->getPHID()) 89 ->setClassName($build_step->getClassName()) 90 ->setDetails($build_step->getDetails()) 91 ->setTargetStatus(self::STATUS_PENDING) 92 ->setVariables($variables) 93 ->setBuildGeneration($build->getBuildGeneration()); 94 } 95 96 public function getConfiguration() { 97 return array( 98 self::CONFIG_AUX_PHID => true, 99 self::CONFIG_SERIALIZATION => array( 100 'details' => self::SERIALIZATION_JSON, 101 'variables' => self::SERIALIZATION_JSON, 102 ), 103 self::CONFIG_COLUMN_SCHEMA => array( 104 'className' => 'text255', 105 'targetStatus' => 'text64', 106 'dateStarted' => 'epoch?', 107 'dateCompleted' => 'epoch?', 108 'buildGeneration' => 'uint32', 109 110 // T6203/NULLABILITY 111 // This should not be nullable. 112 'name' => 'text255?', 113 ), 114 self::CONFIG_KEY_SCHEMA => array( 115 'key_build' => array( 116 'columns' => array('buildPHID', 'buildStepPHID'), 117 ), 118 ), 119 ) + parent::getConfiguration(); 120 } 121 122 public function generatePHID() { 123 return PhabricatorPHID::generateNewPHID( 124 HarbormasterBuildTargetPHIDType::TYPECONST); 125 } 126 127 public function attachBuild(HarbormasterBuild $build) { 128 $this->build = $build; 129 return $this; 130 } 131 132 public function getBuild() { 133 return $this->assertAttached($this->build); 134 } 135 136 public function attachBuildStep(HarbormasterBuildStep $step = null) { 137 $this->buildStep = $step; 138 return $this; 139 } 140 141 public function getBuildStep() { 142 return $this->assertAttached($this->buildStep); 143 } 144 145 public function getDetail($key, $default = null) { 146 return idx($this->details, $key, $default); 147 } 148 149 public function setDetail($key, $value) { 150 $this->details[$key] = $value; 151 return $this; 152 } 153 154 public function getVariables() { 155 return parent::getVariables() + $this->getBuildTargetVariables(); 156 } 157 158 public function getVariable($key, $default = null) { 159 return idx($this->variables, $key, $default); 160 } 161 162 public function setVariable($key, $value) { 163 $this->variables[$key] = $value; 164 return $this; 165 } 166 167 public function getImplementation() { 168 if ($this->implementation === null) { 169 $obj = HarbormasterBuildStepImplementation::requireImplementation( 170 $this->className); 171 $obj->loadSettings($this); 172 $this->implementation = $obj; 173 } 174 175 return $this->implementation; 176 } 177 178 public function getName() { 179 if (strlen($this->name)) { 180 return $this->name; 181 } 182 183 try { 184 return $this->getImplementation()->getName(); 185 } catch (Exception $e) { 186 return $this->getClassName(); 187 } 188 } 189 190 private function getBuildTargetVariables() { 191 return array( 192 'target.phid' => $this->getPHID(), 193 ); 194 } 195 196 197 /* -( Status )------------------------------------------------------------- */ 198 199 200 public function isComplete() { 201 switch ($this->getTargetStatus()) { 202 case self::STATUS_PASSED: 203 case self::STATUS_FAILED: 204 case self::STATUS_ABORTED: 205 return true; 206 } 207 208 return false; 209 } 210 211 212 public function isFailed() { 213 switch ($this->getTargetStatus()) { 214 case self::STATUS_FAILED: 215 return true; 216 } 217 218 return false; 219 } 220 221 222 public function isWaiting() { 223 switch ($this->getTargetStatus()) { 224 case self::STATUS_WAITING: 225 return true; 226 } 227 228 return false; 229 } 230 231 public function isUnderway() { 232 switch ($this->getTargetStatus()) { 233 case self::STATUS_PENDING: 234 case self::STATUS_BUILDING: 235 return true; 236 } 237 238 return false; 239 } 240 241 242 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 243 244 245 public function getCapabilities() { 246 return array( 247 PhabricatorPolicyCapability::CAN_VIEW, 248 ); 249 } 250 251 public function getPolicy($capability) { 252 return $this->getBuild()->getPolicy($capability); 253 } 254 255 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 256 return $this->getBuild()->hasAutomaticCapability( 257 $capability, 258 $viewer); 259 } 260 261 public function describeAutomaticCapability($capability) { 262 return pht('Users must be able to see a build to view its build targets.'); 263 } 264 265 }
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 |