[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DrydockResource extends DrydockDAO 4 implements PhabricatorPolicyInterface { 5 6 protected $id; 7 protected $phid; 8 protected $blueprintPHID; 9 protected $status; 10 11 protected $type; 12 protected $name; 13 protected $attributes = array(); 14 protected $capabilities = array(); 15 protected $ownerPHID; 16 17 private $blueprint; 18 19 public function getConfiguration() { 20 return array( 21 self::CONFIG_AUX_PHID => true, 22 self::CONFIG_SERIALIZATION => array( 23 'attributes' => self::SERIALIZATION_JSON, 24 'capabilities' => self::SERIALIZATION_JSON, 25 ), 26 self::CONFIG_COLUMN_SCHEMA => array( 27 'name' => 'text255', 28 'ownerPHID' => 'phid?', 29 'status' => 'uint32', 30 'type' => 'text64', 31 ), 32 self::CONFIG_KEY_SCHEMA => array( 33 'key_phid' => null, 34 'phid' => array( 35 'columns' => array('phid'), 36 'unique' => true, 37 ), 38 ), 39 ) + parent::getConfiguration(); 40 } 41 42 public function generatePHID() { 43 return PhabricatorPHID::generateNewPHID(DrydockResourcePHIDType::TYPECONST); 44 } 45 46 public function getAttribute($key, $default = null) { 47 return idx($this->attributes, $key, $default); 48 } 49 50 public function getAttributesForTypeSpec(array $attribute_names) { 51 return array_select_keys($this->attributes, $attribute_names); 52 } 53 54 public function setAttribute($key, $value) { 55 $this->attributes[$key] = $value; 56 return $this; 57 } 58 59 public function getCapability($key, $default = null) { 60 return idx($this->capbilities, $key, $default); 61 } 62 63 public function getInterface(DrydockLease $lease, $type) { 64 return $this->getBlueprint()->getInterface($this, $lease, $type); 65 } 66 67 public function getBlueprint() { 68 // TODO: Policy stuff. 69 if (empty($this->blueprint)) { 70 $blueprint = id(new DrydockBlueprint()) 71 ->loadOneWhere('phid = %s', $this->blueprintPHID); 72 $this->blueprint = $blueprint->getImplementation(); 73 } 74 return $this->blueprint; 75 } 76 77 public function closeResource() { 78 $this->openTransaction(); 79 $statuses = array( 80 DrydockLeaseStatus::STATUS_PENDING, 81 DrydockLeaseStatus::STATUS_ACTIVE, 82 ); 83 84 $leases = id(new DrydockLeaseQuery()) 85 ->setViewer(PhabricatorUser::getOmnipotentUser()) 86 ->withResourceIDs(array($this->getID())) 87 ->withStatuses($statuses) 88 ->execute(); 89 90 foreach ($leases as $lease) { 91 switch ($lease->getStatus()) { 92 case DrydockLeaseStatus::STATUS_PENDING: 93 $message = pht('Breaking pending lease (resource closing).'); 94 $lease->setStatus(DrydockLeaseStatus::STATUS_BROKEN); 95 break; 96 case DrydockLeaseStatus::STATUS_ACTIVE: 97 $message = pht('Releasing active lease (resource closing).'); 98 $lease->setStatus(DrydockLeaseStatus::STATUS_RELEASED); 99 break; 100 } 101 DrydockBlueprintImplementation::writeLog($this, $lease, $message); 102 $lease->save(); 103 } 104 105 $this->setStatus(DrydockResourceStatus::STATUS_CLOSED); 106 $this->save(); 107 $this->saveTransaction(); 108 } 109 110 111 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 112 113 114 public function getCapabilities() { 115 return array( 116 PhabricatorPolicyCapability::CAN_VIEW, 117 ); 118 } 119 120 public function getPolicy($capability) { 121 switch ($capability) { 122 case PhabricatorPolicyCapability::CAN_VIEW: 123 return PhabricatorPolicies::getMostOpenPolicy(); 124 } 125 } 126 127 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 128 return false; 129 } 130 131 public function describeAutomaticCapability($capability) { 132 return null; 133 } 134 }
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 |