Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/storage/AlmanacDevice.php
Show All 11 Lines | implements | ||||
PhabricatorNgramsInterface, | PhabricatorNgramsInterface, | ||||
PhabricatorConduitResultInterface, | PhabricatorConduitResultInterface, | ||||
PhabricatorExtendedPolicyInterface { | PhabricatorExtendedPolicyInterface { | ||||
protected $name; | protected $name; | ||||
protected $nameIndex; | protected $nameIndex; | ||||
protected $viewPolicy; | protected $viewPolicy; | ||||
protected $editPolicy; | protected $editPolicy; | ||||
protected $status; | |||||
protected $isBoundToClusterService; | protected $isBoundToClusterService; | ||||
private $almanacProperties = self::ATTACHABLE; | private $almanacProperties = self::ATTACHABLE; | ||||
public static function initializeNewDevice() { | public static function initializeNewDevice() { | ||||
return id(new AlmanacDevice()) | return id(new AlmanacDevice()) | ||||
->setViewPolicy(PhabricatorPolicies::POLICY_USER) | ->setViewPolicy(PhabricatorPolicies::POLICY_USER) | ||||
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN) | ->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN) | ||||
->setStatus(AlmanacDeviceStatus::ACTIVE) | |||||
->attachAlmanacProperties(array()) | ->attachAlmanacProperties(array()) | ||||
->setIsBoundToClusterService(0); | ->setIsBoundToClusterService(0); | ||||
} | } | ||||
protected function getConfiguration() { | protected function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
'name' => 'text128', | 'name' => 'text128', | ||||
'nameIndex' => 'bytes12', | 'nameIndex' => 'bytes12', | ||||
'status' => 'text32', | |||||
'isBoundToClusterService' => 'bool', | 'isBoundToClusterService' => 'bool', | ||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'key_name' => array( | 'key_name' => array( | ||||
'columns' => array('nameIndex'), | 'columns' => array('nameIndex'), | ||||
'unique' => true, | 'unique' => true, | ||||
), | ), | ||||
'key_nametext' => array( | 'key_nametext' => array( | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | public function rebuildClusterBindingStatus() { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function isClusterDevice() { | public function isClusterDevice() { | ||||
return $this->getIsBoundToClusterService(); | return $this->getIsBoundToClusterService(); | ||||
} | } | ||||
public function getStatusObject() { | |||||
return $this->newStatusObject(); | |||||
} | |||||
private function newStatusObject() { | |||||
return AlmanacDeviceStatus::newStatusFromValue($this->getStatus()); | |||||
} | |||||
public function isDisabled() { | |||||
return $this->getStatusObject()->isDisabled(); | |||||
} | |||||
/* -( AlmanacPropertyInterface )------------------------------------------- */ | /* -( AlmanacPropertyInterface )------------------------------------------- */ | ||||
public function attachAlmanacProperties(array $properties) { | public function attachAlmanacProperties(array $properties) { | ||||
assert_instances_of($properties, 'AlmanacProperty'); | assert_instances_of($properties, 'AlmanacProperty'); | ||||
$this->almanacProperties = mpull($properties, null, 'getFieldName'); | $this->almanacProperties = mpull($properties, null, 'getFieldName'); | ||||
return $this; | return $this; | ||||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | /* -( PhabricatorConduitResultInterface )---------------------------------- */ | ||||
public function getFieldSpecificationsForConduit() { | public function getFieldSpecificationsForConduit() { | ||||
return array( | return array( | ||||
id(new PhabricatorConduitSearchFieldSpecification()) | id(new PhabricatorConduitSearchFieldSpecification()) | ||||
->setKey('name') | ->setKey('name') | ||||
->setType('string') | ->setType('string') | ||||
->setDescription(pht('The name of the device.')), | ->setDescription(pht('The name of the device.')), | ||||
id(new PhabricatorConduitSearchFieldSpecification()) | |||||
->setKey('status') | |||||
->setType('map<string, wild>') | |||||
->setDescription(pht('Device status information.')), | |||||
); | ); | ||||
} | } | ||||
public function getFieldValuesForConduit() { | public function getFieldValuesForConduit() { | ||||
$status = $this->getStatusObject(); | |||||
return array( | return array( | ||||
'name' => $this->getName(), | 'name' => $this->getName(), | ||||
'status' => array( | |||||
'value' => $status->getValue(), | |||||
'name' => $status->getName(), | |||||
), | |||||
); | ); | ||||
} | } | ||||
public function getConduitSearchAttachments() { | public function getConduitSearchAttachments() { | ||||
return array( | return array( | ||||
id(new AlmanacPropertiesSearchEngineAttachment()) | id(new AlmanacPropertiesSearchEngineAttachment()) | ||||
->setAttachmentKey('properties'), | ->setAttachmentKey('properties'), | ||||
); | ); | ||||
} | } | ||||
} | } |