Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/storage/AlmanacDevice.php
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | return array( | ||||
), | ), | ||||
'key_nametext' => array( | 'key_nametext' => array( | ||||
'columns' => array('name'), | 'columns' => array('name'), | ||||
), | ), | ||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function generatePHID() { | public function getPHIDType() { | ||||
return PhabricatorPHID::generateNewPHID(AlmanacDevicePHIDType::TYPECONST); | return AlmanacDevicePHIDType::TYPECONST; | ||||
} | } | ||||
public function save() { | public function save() { | ||||
AlmanacNames::validateName($this->getName()); | AlmanacNames::validateName($this->getName()); | ||||
$this->nameIndex = PhabricatorHash::digestForIndex($this->getName()); | $this->nameIndex = PhabricatorHash::digestForIndex($this->getName()); | ||||
return parent::save(); | return parent::save(); | ||||
} | } | ||||
public function getURI() { | public function getURI() { | ||||
return '/almanac/device/view/'.$this->getName().'/'; | return urisprintf( | ||||
'/almanac/device/view/%s/', | |||||
$this->getName()); | |||||
} | } | ||||
public function rebuildClusterBindingStatus() { | public function rebuildClusterBindingStatus() { | ||||
$services = id(new AlmanacServiceQuery()) | $services = id(new AlmanacServiceQuery()) | ||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
->withDevicePHIDs(array($this->getPHID())) | ->withDevicePHIDs(array($this->getPHID())) | ||||
->execute(); | ->execute(); | ||||
$is_cluster = false; | $is_cluster = false; | ||||
foreach ($services as $service) { | foreach ($services as $service) { | ||||
if ($service->isClusterService()) { | if ($service->isClusterService()) { | ||||
$is_cluster = true; | $is_cluster = true; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if ($is_cluster != $this->getIsBoundToClusterService()) { | if ($is_cluster != $this->getIsBoundToClusterService()) { | ||||
$this->setIsBoundToClusterService((int)$is_cluster); | $this->setIsBoundToClusterService((int)$is_cluster); | ||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | ||||
queryfx( | queryfx( | ||||
$this->establishConnection('w'), | $this->establishConnection('w'), | ||||
'UPDATE %T SET isBoundToClusterService = %d WHERE id = %d', | 'UPDATE %R SET isBoundToClusterService = %d WHERE id = %d', | ||||
$this->getTableName(), | $this, | ||||
$this->getIsBoundToClusterService(), | $this->getIsBoundToClusterService(), | ||||
$this->getID()); | $this->getID()); | ||||
unset($unguarded); | unset($unguarded); | ||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines |