Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/storage/AlmanacBinding.php
<?php | <?php | ||||
final class AlmanacBinding | final class AlmanacBinding | ||||
extends AlmanacDAO | extends AlmanacDAO | ||||
implements | implements | ||||
PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
PhabricatorApplicationTransactionInterface, | PhabricatorApplicationTransactionInterface, | ||||
AlmanacPropertyInterface, | AlmanacPropertyInterface, | ||||
PhabricatorDestructibleInterface, | PhabricatorDestructibleInterface, | ||||
PhabricatorExtendedPolicyInterface, | PhabricatorExtendedPolicyInterface, | ||||
PhabricatorConduitResultInterface { | PhabricatorConduitResultInterface { | ||||
protected $servicePHID; | protected $servicePHID; | ||||
protected $devicePHID; | protected $devicePHID; | ||||
protected $interfacePHID; | protected $interfacePHID; | ||||
protected $mailKey; | |||||
protected $isDisabled; | protected $isDisabled; | ||||
private $service = self::ATTACHABLE; | private $service = self::ATTACHABLE; | ||||
private $device = self::ATTACHABLE; | private $device = self::ATTACHABLE; | ||||
private $interface = self::ATTACHABLE; | private $interface = self::ATTACHABLE; | ||||
private $almanacProperties = self::ATTACHABLE; | private $almanacProperties = self::ATTACHABLE; | ||||
public static function initializeNewBinding(AlmanacService $service) { | public static function initializeNewBinding(AlmanacService $service) { | ||||
return id(new AlmanacBinding()) | return id(new AlmanacBinding()) | ||||
->setServicePHID($service->getPHID()) | ->setServicePHID($service->getPHID()) | ||||
->attachService($service) | ->attachService($service) | ||||
->attachAlmanacProperties(array()) | ->attachAlmanacProperties(array()) | ||||
->setIsDisabled(0); | ->setIsDisabled(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( | ||||
'mailKey' => 'bytes20', | |||||
'isDisabled' => 'bool', | 'isDisabled' => 'bool', | ||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'key_service' => array( | 'key_service' => array( | ||||
'columns' => array('servicePHID', 'interfacePHID'), | 'columns' => array('servicePHID', 'interfacePHID'), | ||||
'unique' => true, | 'unique' => true, | ||||
), | ), | ||||
'key_device' => array( | 'key_device' => array( | ||||
'columns' => array('devicePHID'), | 'columns' => array('devicePHID'), | ||||
), | ), | ||||
'key_interface' => array( | 'key_interface' => array( | ||||
'columns' => array('interfacePHID'), | 'columns' => array('interfacePHID'), | ||||
), | ), | ||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function generatePHID() { | public function getPHIDType() { | ||||
return PhabricatorPHID::generateNewPHID(AlmanacBindingPHIDType::TYPECONST); | return AlmanacBindingPHIDType::TYPECONST; | ||||
} | |||||
public function save() { | |||||
if (!$this->mailKey) { | |||||
$this->mailKey = Filesystem::readRandomCharacters(20); | |||||
} | |||||
return parent::save(); | |||||
} | } | ||||
public function getName() { | public function getName() { | ||||
return pht('Binding %s', $this->getID()); | return pht('Binding %s', $this->getID()); | ||||
} | } | ||||
public function getURI() { | public function getURI() { | ||||
return '/almanac/binding/'.$this->getID().'/'; | return urisprintf( | ||||
'/almanac/binding/%s/', | |||||
$this->getID()); | |||||
} | } | ||||
public function getService() { | public function getService() { | ||||
return $this->assertAttached($this->service); | return $this->assertAttached($this->service); | ||||
} | } | ||||
public function attachService(AlmanacService $service) { | public function attachService(AlmanacService $service) { | ||||
$this->service = $service; | $this->service = $service; | ||||
▲ Show 20 Lines • Show All 186 Lines • Show Last 20 Lines |