repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/engineextension/AlmanacSearchEngineAttachment.php | src/applications/almanac/engineextension/AlmanacSearchEngineAttachment.php | <?php
abstract class AlmanacSearchEngineAttachment
extends PhabricatorSearchEngineAttachment {
protected function getAlmanacPropertyList($object) {
$builtins = $object->getAlmanacPropertyFieldSpecifications();
$properties = array();
foreach ($object->getAlmanacProperties() as $key => $property) {
$is_builtin = isset($builtins[$key]);
$properties[] = array(
'key' => $key,
'value' => $property->getFieldValue(),
'builtin' => $is_builtin,
);
}
return $properties;
}
protected function getAlmanacBindingDictionary(AlmanacBinding $binding) {
$interface = $binding->getInterface();
return array(
'id' => (int)$binding->getID(),
'phid' => $binding->getPHID(),
'properties' => $this->getAlmanacPropertyList($binding),
'interface' => $this->getAlmanacInterfaceDictionary($interface),
'disabled' => (bool)$binding->getIsDisabled(),
);
}
protected function getAlmanacInterfaceDictionary(
AlmanacInterface $interface) {
return array(
'id' => (int)$interface->getID(),
'phid' => $interface->getPHID(),
'address' => $interface->getAddress(),
'port' => (int)$interface->getPort(),
'device' => $this->getAlmanacDeviceDictionary($interface->getDevice()),
'network' => $this->getAlmanacNetworkDictionary($interface->getNetwork()),
);
}
protected function getAlmanacDeviceDictionary(AlmanacDevice $device) {
return array(
'id' => (int)$device->getID(),
'phid' => $device->getPHID(),
'name' => $device->getName(),
'properties' => $this->getAlmanacPropertyList($device),
'status' => $device->getStatus(),
'disabled' => $device->isDisabled(),
);
}
protected function getAlmanacNetworkDictionary(AlmanacNetwork $network) {
return array(
'id' => (int)$network->getID(),
'phid' => $network->getPHID(),
'name' => $network->getName(),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/engineextension/AlmanacDeletePropertyEditType.php | src/applications/almanac/engineextension/AlmanacDeletePropertyEditType.php | <?php
final class AlmanacDeletePropertyEditType
extends PhabricatorEditType {
public function generateTransactions(
PhabricatorApplicationTransaction $template,
array $spec) {
$value = idx($spec, 'value');
if (!is_array($value)) {
throw new Exception(
pht(
'Transaction value when deleting Almanac properties must be a list '.
'of property names.'));
}
$xactions = array();
foreach ($value as $idx => $property_key) {
if (!is_string($property_key)) {
throw new Exception(
pht(
'When deleting Almanac properties, each property name must '.
'be a string. The value at index "%s" is not a string.',
$idx));
}
$xactions[] = $this->newTransaction($template)
->setMetadataValue('almanac.property', $property_key)
->setNewValue(true);
}
return $xactions;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/engineextension/AlmanacDeletePropertyEditField.php | src/applications/almanac/engineextension/AlmanacDeletePropertyEditField.php | <?php
final class AlmanacDeletePropertyEditField
extends PhabricatorEditField {
protected function newControl() {
return null;
}
protected function newHTTPParameterType() {
return null;
}
protected function newConduitParameterType() {
return new ConduitStringListParameterType();
}
protected function newEditType() {
return new AlmanacDeletePropertyEditType();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacBinding.php | src/applications/almanac/storage/AlmanacBinding.php | <?php
final class AlmanacBinding
extends AlmanacDAO
implements
PhabricatorPolicyInterface,
PhabricatorApplicationTransactionInterface,
AlmanacPropertyInterface,
PhabricatorDestructibleInterface,
PhabricatorExtendedPolicyInterface,
PhabricatorConduitResultInterface {
protected $servicePHID;
protected $devicePHID;
protected $interfacePHID;
protected $isDisabled;
private $service = self::ATTACHABLE;
private $device = self::ATTACHABLE;
private $interface = self::ATTACHABLE;
private $almanacProperties = self::ATTACHABLE;
public static function initializeNewBinding(AlmanacService $service) {
return id(new AlmanacBinding())
->setServicePHID($service->getPHID())
->attachService($service)
->attachAlmanacProperties(array())
->setIsDisabled(0);
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'isDisabled' => 'bool',
),
self::CONFIG_KEY_SCHEMA => array(
'key_service' => array(
'columns' => array('servicePHID', 'interfacePHID'),
'unique' => true,
),
'key_device' => array(
'columns' => array('devicePHID'),
),
'key_interface' => array(
'columns' => array('interfacePHID'),
),
),
) + parent::getConfiguration();
}
public function getPHIDType() {
return AlmanacBindingPHIDType::TYPECONST;
}
public function getName() {
return pht('Binding %s', $this->getID());
}
public function getURI() {
return urisprintf(
'/almanac/binding/%s/',
$this->getID());
}
public function getService() {
return $this->assertAttached($this->service);
}
public function attachService(AlmanacService $service) {
$this->service = $service;
return $this;
}
public function getDevice() {
return $this->assertAttached($this->device);
}
public function attachDevice(AlmanacDevice $device) {
$this->device = $device;
return $this;
}
public function hasInterface() {
return ($this->interface !== self::ATTACHABLE);
}
public function getInterface() {
return $this->assertAttached($this->interface);
}
public function attachInterface(AlmanacInterface $interface) {
$this->interface = $interface;
return $this;
}
/* -( AlmanacPropertyInterface )------------------------------------------- */
public function attachAlmanacProperties(array $properties) {
assert_instances_of($properties, 'AlmanacProperty');
$this->almanacProperties = mpull($properties, null, 'getFieldName');
return $this;
}
public function getAlmanacProperties() {
return $this->assertAttached($this->almanacProperties);
}
public function hasAlmanacProperty($key) {
$this->assertAttached($this->almanacProperties);
return isset($this->almanacProperties[$key]);
}
public function getAlmanacProperty($key) {
return $this->assertAttachedKey($this->almanacProperties, $key);
}
public function getAlmanacPropertyValue($key, $default = null) {
if ($this->hasAlmanacProperty($key)) {
return $this->getAlmanacProperty($key)->getFieldValue();
} else {
return $default;
}
}
public function getAlmanacPropertyFieldSpecifications() {
return $this->getService()->getBindingFieldSpecifications($this);
}
public function newAlmanacPropertyEditEngine() {
return new AlmanacBindingPropertyEditEngine();
}
public function getAlmanacPropertySetTransactionType() {
return AlmanacBindingSetPropertyTransaction::TRANSACTIONTYPE;
}
public function getAlmanacPropertyDeleteTransactionType() {
return AlmanacBindingDeletePropertyTransaction::TRANSACTIONTYPE;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
return $this->getService()->getPolicy($capability);
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return $this->getService()->hasAutomaticCapability($capability, $viewer);
}
public function describeAutomaticCapability($capability) {
$notes = array(
pht('A binding inherits the policies of its service.'),
pht(
'To view a binding, you must also be able to view its device and '.
'interface.'),
);
return $notes;
}
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_EDIT:
if ($this->getService()->isClusterService()) {
return array(
array(
new PhabricatorAlmanacApplication(),
AlmanacManageClusterServicesCapability::CAPABILITY,
),
);
}
break;
}
return array();
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new AlmanacBindingEditor();
}
public function getApplicationTransactionTemplate() {
return new AlmanacBindingTransaction();
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$this->delete();
}
/* -( PhabricatorConduitResultInterface )---------------------------------- */
public function getFieldSpecificationsForConduit() {
return array(
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('servicePHID')
->setType('phid')
->setDescription(pht('The bound service.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('devicePHID')
->setType('phid')
->setDescription(pht('The device the service is bound to.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('interfacePHID')
->setType('phid')
->setDescription(pht('The interface the service is bound to.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('disabled')
->setType('bool')
->setDescription(pht('Interface status.')),
);
}
public function getFieldValuesForConduit() {
return array(
'servicePHID' => $this->getServicePHID(),
'devicePHID' => $this->getDevicePHID(),
'interfacePHID' => $this->getInterfacePHID(),
'disabled' => (bool)$this->getIsDisabled(),
);
}
public function getConduitSearchAttachments() {
return array(
id(new AlmanacPropertiesSearchEngineAttachment())
->setAttachmentKey('properties'),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacModularTransaction.php | src/applications/almanac/storage/AlmanacModularTransaction.php | <?php
abstract class AlmanacModularTransaction
extends PhabricatorModularTransaction {
public function getApplicationName() {
return 'almanac';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacBindingTransaction.php | src/applications/almanac/storage/AlmanacBindingTransaction.php | <?php
final class AlmanacBindingTransaction
extends AlmanacModularTransaction {
public function getApplicationTransactionType() {
return AlmanacBindingPHIDType::TYPECONST;
}
public function getBaseTransactionClass() {
return 'AlmanacBindingTransactionType';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacNetworkTransaction.php | src/applications/almanac/storage/AlmanacNetworkTransaction.php | <?php
final class AlmanacNetworkTransaction
extends AlmanacModularTransaction {
public function getApplicationTransactionType() {
return AlmanacNetworkPHIDType::TYPECONST;
}
public function getBaseTransactionClass() {
return 'AlmanacNetworkTransactionType';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacProperty.php | src/applications/almanac/storage/AlmanacProperty.php | <?php
final class AlmanacProperty
extends AlmanacDAO
implements PhabricatorPolicyInterface {
protected $objectPHID;
protected $fieldIndex;
protected $fieldName;
protected $fieldValue;
private $object = self::ATTACHABLE;
protected function getConfiguration() {
return array(
self::CONFIG_TIMESTAMPS => false,
self::CONFIG_SERIALIZATION => array(
'fieldValue' => self::SERIALIZATION_JSON,
),
self::CONFIG_COLUMN_SCHEMA => array(
'fieldIndex' => 'bytes12',
'fieldName' => 'text128',
),
self::CONFIG_KEY_SCHEMA => array(
'objectPHID' => array(
'columns' => array('objectPHID', 'fieldIndex'),
'unique' => true,
),
),
) + parent::getConfiguration();
}
public function getObject() {
return $this->assertAttached($this->object);
}
public function attachObject(PhabricatorLiskDAO $object) {
$this->object = $object;
return $this;
}
public static function newPropertyUpdateTransactions(
AlmanacPropertyInterface $object,
array $properties,
$only_builtins = false) {
$template = $object->getApplicationTransactionTemplate();
$builtins = $object->getAlmanacPropertyFieldSpecifications();
$xactions = array();
foreach ($properties as $name => $property) {
if ($only_builtins && empty($builtins[$name])) {
continue;
}
$xactions[] = id(clone $template)
->setTransactionType($object->getAlmanacPropertySetTransactionType())
->setMetadataValue('almanac.property', $name)
->setNewValue($property);
}
return $xactions;
}
public static function newPropertyRemoveTransactions(
AlmanacPropertyInterface $object,
array $properties) {
$template = $object->getApplicationTransactionTemplate();
$xactions = array();
foreach ($properties as $property) {
$xactions[] = id(clone $template)
->setTransactionType($object->getAlmanacPropertyDeleteTransactionType())
->setMetadataValue('almanac.property', $property)
->setNewValue(null);
}
return $xactions;
}
public function save() {
$hash = PhabricatorHash::digestForIndex($this->getFieldName());
$this->setFieldIndex($hash);
return parent::save();
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
return $this->getObject()->getPolicy($capability);
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return $this->getObject()->hasAutomaticCapability($capability, $viewer);
}
public function describeAutomaticCapability($capability) {
return pht('Properties inherit the policies of their object.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacDeviceNameNgrams.php | src/applications/almanac/storage/AlmanacDeviceNameNgrams.php | <?php
final class AlmanacDeviceNameNgrams
extends PhabricatorSearchNgrams {
public function getNgramKey() {
return 'devicename';
}
public function getColumnName() {
return 'name';
}
public function getApplicationName() {
return 'almanac';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacInterfaceTransaction.php | src/applications/almanac/storage/AlmanacInterfaceTransaction.php | <?php
final class AlmanacInterfaceTransaction
extends AlmanacModularTransaction {
public function getApplicationTransactionType() {
return AlmanacInterfacePHIDType::TYPECONST;
}
public function getBaseTransactionClass() {
return 'AlmanacInterfaceTransactionType';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacSchemaSpec.php | src/applications/almanac/storage/AlmanacSchemaSpec.php | <?php
final class AlmanacSchemaSpec
extends PhabricatorConfigSchemaSpec {
public function buildSchemata() {
$this->buildEdgeSchemata(new AlmanacService());
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacDevice.php | src/applications/almanac/storage/AlmanacDevice.php | <?php
final class AlmanacDevice
extends AlmanacDAO
implements
PhabricatorPolicyInterface,
PhabricatorApplicationTransactionInterface,
PhabricatorProjectInterface,
PhabricatorSSHPublicKeyInterface,
AlmanacPropertyInterface,
PhabricatorDestructibleInterface,
PhabricatorNgramsInterface,
PhabricatorConduitResultInterface,
PhabricatorExtendedPolicyInterface {
protected $name;
protected $nameIndex;
protected $viewPolicy;
protected $editPolicy;
protected $status;
protected $isBoundToClusterService;
private $almanacProperties = self::ATTACHABLE;
public static function initializeNewDevice() {
return id(new AlmanacDevice())
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN)
->setStatus(AlmanacDeviceStatus::ACTIVE)
->attachAlmanacProperties(array())
->setIsBoundToClusterService(0);
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text128',
'nameIndex' => 'bytes12',
'status' => 'text32',
'isBoundToClusterService' => 'bool',
),
self::CONFIG_KEY_SCHEMA => array(
'key_name' => array(
'columns' => array('nameIndex'),
'unique' => true,
),
'key_nametext' => array(
'columns' => array('name'),
),
),
) + parent::getConfiguration();
}
public function getPHIDType() {
return AlmanacDevicePHIDType::TYPECONST;
}
public function save() {
AlmanacNames::validateName($this->getName());
$this->nameIndex = PhabricatorHash::digestForIndex($this->getName());
return parent::save();
}
public function getURI() {
return urisprintf(
'/almanac/device/view/%s/',
$this->getName());
}
public function rebuildClusterBindingStatus() {
$services = id(new AlmanacServiceQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withDevicePHIDs(array($this->getPHID()))
->execute();
$is_cluster = false;
foreach ($services as $service) {
if ($service->isClusterService()) {
$is_cluster = true;
break;
}
}
if ($is_cluster != $this->getIsBoundToClusterService()) {
$this->setIsBoundToClusterService((int)$is_cluster);
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
queryfx(
$this->establishConnection('w'),
'UPDATE %R SET isBoundToClusterService = %d WHERE id = %d',
$this,
$this->getIsBoundToClusterService(),
$this->getID());
unset($unguarded);
}
return $this;
}
public function isClusterDevice() {
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 )------------------------------------------- */
public function attachAlmanacProperties(array $properties) {
assert_instances_of($properties, 'AlmanacProperty');
$this->almanacProperties = mpull($properties, null, 'getFieldName');
return $this;
}
public function getAlmanacProperties() {
return $this->assertAttached($this->almanacProperties);
}
public function hasAlmanacProperty($key) {
$this->assertAttached($this->almanacProperties);
return isset($this->almanacProperties[$key]);
}
public function getAlmanacProperty($key) {
return $this->assertAttachedKey($this->almanacProperties, $key);
}
public function getAlmanacPropertyValue($key, $default = null) {
if ($this->hasAlmanacProperty($key)) {
return $this->getAlmanacProperty($key)->getFieldValue();
} else {
return $default;
}
}
public function getAlmanacPropertyFieldSpecifications() {
return array();
}
public function newAlmanacPropertyEditEngine() {
return new AlmanacDevicePropertyEditEngine();
}
public function getAlmanacPropertySetTransactionType() {
return AlmanacDeviceSetPropertyTransaction::TRANSACTIONTYPE;
}
public function getAlmanacPropertyDeleteTransactionType() {
return AlmanacDeviceDeletePropertyTransaction::TRANSACTIONTYPE;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getViewPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return $this->getEditPolicy();
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_EDIT:
if ($this->isClusterDevice()) {
return array(
array(
new PhabricatorAlmanacApplication(),
AlmanacManageClusterServicesCapability::CAPABILITY,
),
);
}
break;
}
return array();
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new AlmanacDeviceEditor();
}
public function getApplicationTransactionTemplate() {
return new AlmanacDeviceTransaction();
}
/* -( PhabricatorSSHPublicKeyInterface )----------------------------------- */
public function getSSHPublicKeyManagementURI(PhabricatorUser $viewer) {
return $this->getURI();
}
public function getSSHKeyDefaultName() {
return $this->getName();
}
public function getSSHKeyNotifyPHIDs() {
// Devices don't currently have anyone useful to notify about SSH key
// edits, and they're usually a difficult vector to attack since you need
// access to a cluster host. However, it would be nice to make them
// subscribable at some point.
return array();
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$interfaces = id(new AlmanacInterfaceQuery())
->setViewer($engine->getViewer())
->withDevicePHIDs(array($this->getPHID()))
->execute();
foreach ($interfaces as $interface) {
$engine->destroyObject($interface);
}
$this->delete();
}
/* -( PhabricatorNgramsInterface )----------------------------------------- */
public function newNgrams() {
return array(
id(new AlmanacDeviceNameNgrams())
->setValue($this->getName()),
);
}
/* -( PhabricatorConduitResultInterface )---------------------------------- */
public function getFieldSpecificationsForConduit() {
return array(
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('name')
->setType('string')
->setDescription(pht('The name of the device.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('status')
->setType('map<string, wild>')
->setDescription(pht('Device status information.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('disabled')
->setType('bool')
->setDescription(pht('True if device is disabled.')),
);
}
public function getFieldValuesForConduit() {
$status = $this->getStatusObject();
return array(
'name' => $this->getName(),
'status' => array(
'value' => $status->getValue(),
'name' => $status->getName(),
),
'disabled' => $this->isDisabled(),
);
}
public function getConduitSearchAttachments() {
return array(
id(new AlmanacPropertiesSearchEngineAttachment())
->setAttachmentKey('properties'),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacNamespaceTransaction.php | src/applications/almanac/storage/AlmanacNamespaceTransaction.php | <?php
final class AlmanacNamespaceTransaction
extends AlmanacModularTransaction {
public function getApplicationTransactionType() {
return AlmanacNamespacePHIDType::TYPECONST;
}
public function getBaseTransactionClass() {
return 'AlmanacNamespaceTransactionType';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacNamespace.php | src/applications/almanac/storage/AlmanacNamespace.php | <?php
final class AlmanacNamespace
extends AlmanacDAO
implements
PhabricatorPolicyInterface,
PhabricatorApplicationTransactionInterface,
PhabricatorProjectInterface,
PhabricatorDestructibleInterface,
PhabricatorNgramsInterface,
PhabricatorConduitResultInterface {
protected $name;
protected $nameIndex;
protected $viewPolicy;
protected $editPolicy;
public static function initializeNewNamespace() {
return id(new self())
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN);
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text128',
'nameIndex' => 'bytes12',
),
self::CONFIG_KEY_SCHEMA => array(
'key_nameindex' => array(
'columns' => array('nameIndex'),
'unique' => true,
),
'key_name' => array(
'columns' => array('name'),
),
),
) + parent::getConfiguration();
}
public function getPHIDType() {
return AlmanacNamespacePHIDType::TYPECONST;
}
public function save() {
AlmanacNames::validateName($this->getName());
$this->nameIndex = PhabricatorHash::digestForIndex($this->getName());
return parent::save();
}
public function getURI() {
return urisprintf(
'/almanac/namespace/view/%s/',
$this->getName());
}
public function getNameLength() {
return strlen($this->getName());
}
/**
* Load the namespace which prevents use of an Almanac name, if one exists.
*/
public static function loadRestrictedNamespace(
PhabricatorUser $viewer,
$name) {
// For a name like "x.y.z", produce a list of controlling namespaces like
// ("z", "y.x", "x.y.z").
$names = array();
$parts = explode('.', $name);
for ($ii = 0; $ii < count($parts); $ii++) {
$names[] = implode('.', array_slice($parts, -($ii + 1)));
}
// Load all the possible controlling namespaces.
$namespaces = id(new AlmanacNamespaceQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withNames($names)
->execute();
if (!$namespaces) {
return null;
}
// Find the "nearest" (longest) namespace that exists. If both
// "sub.domain.com" and "domain.com" exist, we only care about the policy
// on the former.
$namespaces = msort($namespaces, 'getNameLength');
$namespace = last($namespaces);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$namespace,
PhabricatorPolicyCapability::CAN_EDIT);
if ($can_edit) {
return null;
}
return $namespace;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getViewPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return $this->getEditPolicy();
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new AlmanacNamespaceEditor();
}
public function getApplicationTransactionTemplate() {
return new AlmanacNamespaceTransaction();
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$this->delete();
}
/* -( PhabricatorNgramsInterface )----------------------------------------- */
public function newNgrams() {
return array(
id(new AlmanacNamespaceNameNgrams())
->setValue($this->getName()),
);
}
/* -( PhabricatorConduitResultInterface )---------------------------------- */
public function getFieldSpecificationsForConduit() {
return array(
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('name')
->setType('string')
->setDescription(pht('The name of the namespace.')),
);
}
public function getFieldValuesForConduit() {
return array(
'name' => $this->getName(),
);
}
public function getConduitSearchAttachments() {
return array();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacService.php | src/applications/almanac/storage/AlmanacService.php | <?php
final class AlmanacService
extends AlmanacDAO
implements
PhabricatorPolicyInterface,
PhabricatorApplicationTransactionInterface,
PhabricatorProjectInterface,
AlmanacPropertyInterface,
PhabricatorDestructibleInterface,
PhabricatorNgramsInterface,
PhabricatorConduitResultInterface,
PhabricatorExtendedPolicyInterface {
protected $name;
protected $nameIndex;
protected $viewPolicy;
protected $editPolicy;
protected $serviceType;
private $almanacProperties = self::ATTACHABLE;
private $bindings = self::ATTACHABLE;
private $activeBindings = self::ATTACHABLE;
private $serviceImplementation = self::ATTACHABLE;
public static function initializeNewService($type) {
$type_map = AlmanacServiceType::getAllServiceTypes();
$implementation = idx($type_map, $type);
if (!$implementation) {
throw new Exception(
pht(
'No Almanac service type "%s" exists!',
$type));
}
return id(new AlmanacService())
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN)
->attachAlmanacProperties(array())
->setServiceType($type)
->attachServiceImplementation($implementation);
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text128',
'nameIndex' => 'bytes12',
'serviceType' => 'text64',
),
self::CONFIG_KEY_SCHEMA => array(
'key_name' => array(
'columns' => array('nameIndex'),
'unique' => true,
),
'key_nametext' => array(
'columns' => array('name'),
),
'key_servicetype' => array(
'columns' => array('serviceType'),
),
),
) + parent::getConfiguration();
}
public function getPHIDType() {
return AlmanacServicePHIDType::TYPECONST;
}
public function save() {
AlmanacNames::validateName($this->getName());
$this->nameIndex = PhabricatorHash::digestForIndex($this->getName());
return parent::save();
}
public function getURI() {
return '/almanac/service/view/'.$this->getName().'/';
}
public function getBindings() {
return $this->assertAttached($this->bindings);
}
public function getActiveBindings() {
return $this->assertAttached($this->activeBindings);
}
public function attachBindings(array $bindings) {
$active_bindings = array();
foreach ($bindings as $key => $binding) {
// Filter out disabled bindings.
if ($binding->getIsDisabled()) {
continue;
}
// Filter out bindings to disabled devices.
if ($binding->getDevice()->isDisabled()) {
continue;
}
$active_bindings[$key] = $binding;
}
$this->attachActiveBindings($active_bindings);
$this->bindings = $bindings;
return $this;
}
public function attachActiveBindings(array $bindings) {
$this->activeBindings = $bindings;
return $this;
}
public function getServiceImplementation() {
return $this->assertAttached($this->serviceImplementation);
}
public function attachServiceImplementation(AlmanacServiceType $type) {
$this->serviceImplementation = $type;
return $this;
}
public function isClusterService() {
return $this->getServiceImplementation()->isClusterServiceType();
}
/* -( AlmanacPropertyInterface )------------------------------------------- */
public function attachAlmanacProperties(array $properties) {
assert_instances_of($properties, 'AlmanacProperty');
$this->almanacProperties = mpull($properties, null, 'getFieldName');
return $this;
}
public function getAlmanacProperties() {
return $this->assertAttached($this->almanacProperties);
}
public function hasAlmanacProperty($key) {
$this->assertAttached($this->almanacProperties);
return isset($this->almanacProperties[$key]);
}
public function getAlmanacProperty($key) {
return $this->assertAttachedKey($this->almanacProperties, $key);
}
public function getAlmanacPropertyValue($key, $default = null) {
if ($this->hasAlmanacProperty($key)) {
return $this->getAlmanacProperty($key)->getFieldValue();
} else {
return $default;
}
}
public function getAlmanacPropertyFieldSpecifications() {
return $this->getServiceImplementation()->getFieldSpecifications();
}
public function getBindingFieldSpecifications(AlmanacBinding $binding) {
$impl = $this->getServiceImplementation();
return $impl->getBindingFieldSpecifications($binding);
}
public function newAlmanacPropertyEditEngine() {
return new AlmanacServicePropertyEditEngine();
}
public function getAlmanacPropertySetTransactionType() {
return AlmanacServiceSetPropertyTransaction::TRANSACTIONTYPE;
}
public function getAlmanacPropertyDeleteTransactionType() {
return AlmanacServiceDeletePropertyTransaction::TRANSACTIONTYPE;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getViewPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return $this->getEditPolicy();
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_EDIT:
if ($this->isClusterService()) {
return array(
array(
new PhabricatorAlmanacApplication(),
AlmanacManageClusterServicesCapability::CAPABILITY,
),
);
}
break;
}
return array();
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new AlmanacServiceEditor();
}
public function getApplicationTransactionTemplate() {
return new AlmanacServiceTransaction();
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$bindings = id(new AlmanacBindingQuery())
->setViewer($engine->getViewer())
->withServicePHIDs(array($this->getPHID()))
->execute();
foreach ($bindings as $binding) {
$engine->destroyObject($binding);
}
$this->delete();
}
/* -( PhabricatorNgramsInterface )----------------------------------------- */
public function newNgrams() {
return array(
id(new AlmanacServiceNameNgrams())
->setValue($this->getName()),
);
}
/* -( PhabricatorConduitResultInterface )---------------------------------- */
public function getFieldSpecificationsForConduit() {
return array(
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('name')
->setType('string')
->setDescription(pht('The name of the service.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('serviceType')
->setType('string')
->setDescription(pht('The service type constant.')),
);
}
public function getFieldValuesForConduit() {
return array(
'name' => $this->getName(),
'serviceType' => $this->getServiceType(),
);
}
public function getConduitSearchAttachments() {
return array(
id(new AlmanacPropertiesSearchEngineAttachment())
->setAttachmentKey('properties'),
id(new AlmanacBindingsSearchEngineAttachment())
->setAttachmentKey('bindings'),
id(new AlmanacBindingsSearchEngineAttachment())
->setIsActive(true)
->setAttachmentKey('activeBindings'),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacNamespaceNameNgrams.php | src/applications/almanac/storage/AlmanacNamespaceNameNgrams.php | <?php
final class AlmanacNamespaceNameNgrams
extends PhabricatorSearchNgrams {
public function getNgramKey() {
return 'namespacename';
}
public function getColumnName() {
return 'name';
}
public function getApplicationName() {
return 'almanac';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacServiceNameNgrams.php | src/applications/almanac/storage/AlmanacServiceNameNgrams.php | <?php
final class AlmanacServiceNameNgrams
extends PhabricatorSearchNgrams {
public function getNgramKey() {
return 'servicename';
}
public function getColumnName() {
return 'name';
}
public function getApplicationName() {
return 'almanac';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacNetwork.php | src/applications/almanac/storage/AlmanacNetwork.php | <?php
final class AlmanacNetwork
extends AlmanacDAO
implements
PhabricatorApplicationTransactionInterface,
PhabricatorPolicyInterface,
PhabricatorDestructibleInterface,
PhabricatorNgramsInterface,
PhabricatorConduitResultInterface {
protected $name;
protected $viewPolicy;
protected $editPolicy;
public static function initializeNewNetwork() {
return id(new AlmanacNetwork())
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN);
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'sort128',
),
self::CONFIG_KEY_SCHEMA => array(
'key_name' => array(
'columns' => array('name'),
'unique' => true,
),
),
) + parent::getConfiguration();
}
public function getPHIDType() {
return AlmanacNetworkPHIDType::TYPECONST;
}
public function getURI() {
return urisprintf(
'/almanac/network/%s/',
$this->getID());
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new AlmanacNetworkEditor();
}
public function getApplicationTransactionTemplate() {
return new AlmanacNetworkTransaction();
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getViewPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return $this->getEditPolicy();
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$interfaces = id(new AlmanacInterfaceQuery())
->setViewer($engine->getViewer())
->withNetworkPHIDs(array($this->getPHID()))
->execute();
foreach ($interfaces as $interface) {
$engine->destroyObject($interface);
}
$this->delete();
}
/* -( PhabricatorNgramsInterface )----------------------------------------- */
public function newNgrams() {
return array(
id(new AlmanacNetworkNameNgrams())
->setValue($this->getName()),
);
}
/* -( PhabricatorConduitResultInterface )---------------------------------- */
public function getFieldSpecificationsForConduit() {
return array(
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('name')
->setType('string')
->setDescription(pht('The name of the network.')),
);
}
public function getFieldValuesForConduit() {
return array(
'name' => $this->getName(),
);
}
public function getConduitSearchAttachments() {
return array();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacDeviceTransaction.php | src/applications/almanac/storage/AlmanacDeviceTransaction.php | <?php
final class AlmanacDeviceTransaction
extends AlmanacModularTransaction {
public function getApplicationTransactionType() {
return AlmanacDevicePHIDType::TYPECONST;
}
public function getBaseTransactionClass() {
return 'AlmanacDeviceTransactionType';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacNetworkNameNgrams.php | src/applications/almanac/storage/AlmanacNetworkNameNgrams.php | <?php
final class AlmanacNetworkNameNgrams
extends PhabricatorSearchNgrams {
public function getNgramKey() {
return 'networkname';
}
public function getColumnName() {
return 'name';
}
public function getApplicationName() {
return 'almanac';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacServiceTransaction.php | src/applications/almanac/storage/AlmanacServiceTransaction.php | <?php
final class AlmanacServiceTransaction
extends AlmanacModularTransaction {
public function getApplicationTransactionType() {
return AlmanacServicePHIDType::TYPECONST;
}
public function getBaseTransactionClass() {
return 'AlmanacServiceTransactionType';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacInterface.php | src/applications/almanac/storage/AlmanacInterface.php | <?php
final class AlmanacInterface
extends AlmanacDAO
implements
PhabricatorPolicyInterface,
PhabricatorDestructibleInterface,
PhabricatorExtendedPolicyInterface,
PhabricatorApplicationTransactionInterface,
PhabricatorConduitResultInterface {
protected $devicePHID;
protected $networkPHID;
protected $address;
protected $port;
private $device = self::ATTACHABLE;
private $network = self::ATTACHABLE;
public static function initializeNewInterface() {
return id(new AlmanacInterface());
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'address' => 'text64',
'port' => 'uint32',
),
self::CONFIG_KEY_SCHEMA => array(
'key_location' => array(
'columns' => array('networkPHID', 'address', 'port'),
),
'key_device' => array(
'columns' => array('devicePHID'),
),
'key_unique' => array(
'columns' => array('devicePHID', 'networkPHID', 'address', 'port'),
'unique' => true,
),
),
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
AlmanacInterfacePHIDType::TYPECONST);
}
public function getDevice() {
return $this->assertAttached($this->device);
}
public function attachDevice(AlmanacDevice $device) {
$this->device = $device;
return $this;
}
public function getNetwork() {
return $this->assertAttached($this->network);
}
public function attachNetwork(AlmanacNetwork $network) {
$this->network = $network;
return $this;
}
public function toAddress() {
return AlmanacAddress::newFromParts(
$this->getNetworkPHID(),
$this->getAddress(),
$this->getPort());
}
public function getAddressHash() {
return $this->toAddress()->toHash();
}
public function renderDisplayAddress() {
return $this->getAddress().':'.$this->getPort();
}
public function loadIsInUse() {
$binding = id(new AlmanacBindingQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withInterfacePHIDs(array($this->getPHID()))
->setLimit(1)
->executeOne();
return (bool)$binding;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
return $this->getDevice()->getPolicy($capability);
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return $this->getDevice()->hasAutomaticCapability($capability, $viewer);
}
public function describeAutomaticCapability($capability) {
$notes = array(
pht('An interface inherits the policies of the device it belongs to.'),
pht(
'You must be able to view the network an interface resides on to '.
'view the interface.'),
);
return $notes;
}
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_EDIT:
if ($this->getDevice()->isClusterDevice()) {
return array(
array(
new PhabricatorAlmanacApplication(),
AlmanacManageClusterServicesCapability::CAPABILITY,
),
);
}
break;
}
return array();
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$bindings = id(new AlmanacBindingQuery())
->setViewer($engine->getViewer())
->withInterfacePHIDs(array($this->getPHID()))
->execute();
foreach ($bindings as $binding) {
$engine->destroyObject($binding);
}
$this->delete();
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new AlmanacInterfaceEditor();
}
public function getApplicationTransactionTemplate() {
return new AlmanacInterfaceTransaction();
}
/* -( PhabricatorConduitResultInterface )---------------------------------- */
public function getFieldSpecificationsForConduit() {
return array(
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('devicePHID')
->setType('phid')
->setDescription(pht('The device the interface is on.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('networkPHID')
->setType('phid')
->setDescription(pht('The network the interface is part of.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('address')
->setType('string')
->setDescription(pht('The address of the interface.')),
id(new PhabricatorConduitSearchFieldSpecification())
->setKey('port')
->setType('int')
->setDescription(pht('The port number of the interface.')),
);
}
public function getFieldValuesForConduit() {
return array(
'devicePHID' => $this->getDevicePHID(),
'networkPHID' => $this->getNetworkPHID(),
'address' => (string)$this->getAddress(),
'port' => (int)$this->getPort(),
);
}
public function getConduitSearchAttachments() {
return array();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/storage/AlmanacDAO.php | src/applications/almanac/storage/AlmanacDAO.php | <?php
abstract class AlmanacDAO extends PhabricatorLiskDAO {
public function getApplicationName() {
return 'almanac';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/management/AlmanacManagementWorkflow.php | src/applications/almanac/management/AlmanacManagementWorkflow.php | <?php
abstract class AlmanacManagementWorkflow
extends PhabricatorManagementWorkflow {
protected function loadServices(array $names) {
if (!$names) {
return array();
}
$services = id(new AlmanacServiceQuery())
->setViewer($this->getViewer())
->withNames($names)
->execute();
$services = mpull($services, null, 'getName');
foreach ($names as $name) {
if (empty($services[$name])) {
throw new PhutilArgumentUsageException(
pht(
'Service "%s" does not exist or could not be loaded!',
$name));
}
}
return $services;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/management/AlmanacManagementRegisterWorkflow.php | src/applications/almanac/management/AlmanacManagementRegisterWorkflow.php | <?php
final class AlmanacManagementRegisterWorkflow
extends AlmanacManagementWorkflow {
protected function didConstruct() {
$this
->setName('register')
->setSynopsis(pht('Register this host as an Almanac device.'))
->setArguments(
array(
array(
'name' => 'device',
'param' => 'name',
'help' => pht('Almanac device name to register.'),
),
array(
'name' => 'private-key',
'param' => 'key',
'help' => pht('Path to a private key for the host.'),
),
array(
'name' => 'identify-as',
'param' => 'name',
'help' => pht(
'Specify an alternate host identity. This is an advanced '.
'feature which allows a pool of devices to share credentials.'),
),
array(
'name' => 'force',
'help' => pht(
'Register this host even if keys already exist on disk.'),
),
));
}
public function execute(PhutilArgumentParser $args) {
$viewer = $this->getViewer();
$device_name = $args->getArg('device');
if (!strlen($device_name)) {
throw new PhutilArgumentUsageException(
pht('Specify a device with --device.'));
}
$device = id(new AlmanacDeviceQuery())
->setViewer($viewer)
->withNames(array($device_name))
->executeOne();
if (!$device) {
throw new PhutilArgumentUsageException(
pht('No such device "%s" exists!', $device_name));
}
$identify_as = $args->getArg('identify-as');
$raw_device = $device_name;
if (strlen($identify_as)) {
$raw_device = $identify_as;
}
$identity_device = id(new AlmanacDeviceQuery())
->setViewer($viewer)
->withNames(array($raw_device))
->executeOne();
if (!$identity_device) {
throw new PhutilArgumentUsageException(
pht(
'No such device "%s" exists!', $raw_device));
}
$private_key_path = $args->getArg('private-key');
if (!strlen($private_key_path)) {
throw new PhutilArgumentUsageException(
pht('Specify a private key with --private-key.'));
}
if (!Filesystem::pathExists($private_key_path)) {
throw new PhutilArgumentUsageException(
pht('No private key exists at path "%s"!', $private_key_path));
}
$raw_private_key = Filesystem::readFile($private_key_path);
$phd_user = PhabricatorEnv::getEnvConfig('phd.user');
if (!$phd_user) {
throw new PhutilArgumentUsageException(
pht(
'Config option "phd.user" is not set. You must set this option '.
'so the private key can be stored with the correct permissions.'));
}
$tmp = new TempFile();
list($err) = exec_manual('chown %s %s', $phd_user, $tmp);
if ($err) {
throw new PhutilArgumentUsageException(
pht(
'Unable to change ownership of an identity file to daemon user '.
'"%s". Run this command as %s or root.',
$phd_user,
$phd_user));
}
$stored_public_path = AlmanacKeys::getKeyPath('device.pub');
$stored_private_path = AlmanacKeys::getKeyPath('device.key');
$stored_device_path = AlmanacKeys::getKeyPath('device.id');
if (!$args->getArg('force')) {
if (Filesystem::pathExists($stored_public_path)) {
throw new PhutilArgumentUsageException(
pht(
'This host already has a registered public key ("%s"). '.
'Remove this key before registering the host, or use '.
'--force to overwrite it.',
Filesystem::readablePath($stored_public_path)));
}
if (Filesystem::pathExists($stored_private_path)) {
throw new PhutilArgumentUsageException(
pht(
'This host already has a registered private key ("%s"). '.
'Remove this key before registering the host, or use '.
'--force to overwrite it.',
Filesystem::readablePath($stored_private_path)));
}
}
// NOTE: We're writing the private key here so we can change permissions
// on it without causing weird side effects to the file specified with
// the `--private-key` flag. The file needs to have restrictive permissions
// before `ssh-keygen` will willingly operate on it.
$tmp_private = new TempFile();
Filesystem::changePermissions($tmp_private, 0600);
execx('chown %s %s', $phd_user, $tmp_private);
Filesystem::writeFile($tmp_private, $raw_private_key);
list($raw_public_key) = execx('ssh-keygen -y -f %s', $tmp_private);
$key_object = PhabricatorAuthSSHPublicKey::newFromRawKey($raw_public_key);
$public_key = id(new PhabricatorAuthSSHKeyQuery())
->setViewer($this->getViewer())
->withKeys(array($key_object))
->withIsActive(true)
->executeOne();
if (!$public_key) {
throw new PhutilArgumentUsageException(
pht(
'The public key corresponding to the given private key is unknown. '.
'Associate the public key with an Almanac device in the web '.
'interface before registering hosts with it.'));
}
if ($public_key->getObjectPHID() !== $device->getPHID()) {
$public_phid = $public_key->getObjectPHID();
$public_handles = $viewer->loadHandles(array($public_phid));
$public_handle = $public_handles[$public_phid];
throw new PhutilArgumentUsageException(
pht(
'The public key corresponding to the given private key is already '.
'associated with an object ("%s") other than the specified '.
'device ("%s"). You can not use a single private key to identify '.
'multiple devices or users.',
$public_handle->getFullName(),
$device->getName()));
}
if (!$public_key->getIsTrusted()) {
throw new PhutilArgumentUsageException(
pht(
'The public key corresponding to the given private key is '.
'properly associated with the device, but is not yet trusted. '.
'Trust this key before registering devices with it.'));
}
echo tsprintf(
"%s\n",
pht('Installing public key...'));
$tmp_public = new TempFile();
Filesystem::changePermissions($tmp_public, 0600);
execx('chown %s %s', $phd_user, $tmp_public);
Filesystem::writeFile($tmp_public, $raw_public_key);
execx('mv -f %s %s', $tmp_public, $stored_public_path);
echo tsprintf(
"%s\n",
pht('Installing private key...'));
execx('mv -f %s %s', $tmp_private, $stored_private_path);
echo tsprintf(
"%s\n",
pht('Installing device %s...', $raw_device));
// The permissions on this file are more open because the webserver also
// needs to read it.
$tmp_device = new TempFile();
Filesystem::changePermissions($tmp_device, 0644);
execx('chown %s %s', $phd_user, $tmp_device);
Filesystem::writeFile($tmp_device, $raw_device);
execx('mv -f %s %s', $tmp_device, $stored_device_path);
echo tsprintf(
"**<bg:green> %s </bg>** %s\n",
pht('HOST REGISTERED'),
pht(
'This host has been registered as "%s" and a trusted keypair '.
'has been installed.',
$raw_device));
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/management/AlmanacManagementUntrustKeyWorkflow.php | src/applications/almanac/management/AlmanacManagementUntrustKeyWorkflow.php | <?php
final class AlmanacManagementUntrustKeyWorkflow
extends AlmanacManagementWorkflow {
protected function didConstruct() {
$this
->setName('untrust-key')
->setSynopsis(pht('Revoke trust of a public key.'))
->setArguments(
array(
array(
'name' => 'id',
'param' => 'id',
'help' => pht('ID of the key to revoke trust for.'),
),
));
}
public function execute(PhutilArgumentParser $args) {
$console = PhutilConsole::getConsole();
$id = $args->getArg('id');
if (!$id) {
throw new PhutilArgumentUsageException(
pht('Specify a public key to revoke trust for with --id.'));
}
$key = id(new PhabricatorAuthSSHKeyQuery())
->setViewer($this->getViewer())
->withIDs(array($id))
->executeOne();
if (!$key) {
throw new PhutilArgumentUsageException(
pht('No public key exists with ID "%s".', $id));
}
if (!$key->getIsTrusted()) {
throw new PhutilArgumentUsageException(
pht('Public key with ID %s is not trusted.', $id));
}
$key->setIsTrusted(0);
$key->save();
PhabricatorAuthSSHKeyQuery::deleteSSHKeyCache();
$console->writeOut(
"**<bg:green> %s </bg>** %s\n",
pht('TRUST REVOKED'),
pht('Trust has been revoked for public key %s.', $id));
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/management/AlmanacManagementTrustKeyWorkflow.php | src/applications/almanac/management/AlmanacManagementTrustKeyWorkflow.php | <?php
final class AlmanacManagementTrustKeyWorkflow
extends AlmanacManagementWorkflow {
protected function didConstruct() {
$this
->setName('trust-key')
->setSynopsis(pht('Mark a public key as trusted.'))
->setArguments(
array(
array(
'name' => 'id',
'param' => 'id',
'help' => pht('ID of the key to trust.'),
),
));
}
public function execute(PhutilArgumentParser $args) {
$console = PhutilConsole::getConsole();
$id = $args->getArg('id');
if (!$id) {
throw new PhutilArgumentUsageException(
pht('Specify a public key to trust with --id.'));
}
$key = id(new PhabricatorAuthSSHKeyQuery())
->setViewer($this->getViewer())
->withIDs(array($id))
->executeOne();
if (!$key) {
throw new PhutilArgumentUsageException(
pht('No public key exists with ID "%s".', $id));
}
if (!$key->getIsActive()) {
throw new PhutilArgumentUsageException(
pht('Public key "%s" is not an active key.', $id));
}
if ($key->getIsTrusted()) {
throw new PhutilArgumentUsageException(
pht('Public key with ID %s is already trusted.', $id));
}
if (!($key->getObject() instanceof AlmanacDevice)) {
throw new PhutilArgumentUsageException(
pht('You can only trust keys associated with Almanac devices.'));
}
$handle = id(new PhabricatorHandleQuery())
->setViewer($this->getViewer())
->withPHIDs(array($key->getObject()->getPHID()))
->executeOne();
$console->writeOut(
"**<bg:red> %s </bg>**\n\n%s\n\n%s\n\n%s",
pht('IMPORTANT!'),
phutil_console_wrap(
pht(
'Trusting a public key gives anyone holding the corresponding '.
'private key complete, unrestricted access to all data. The '.
'private key will be able to sign requests that bypass policy and '.
'security checks.')),
phutil_console_wrap(
pht(
'This is an advanced feature which should normally be used only '.
'when building a cluster. This feature is very dangerous if '.
'misused.')),
pht('This key is associated with device "%s".', $handle->getName()));
$prompt = pht(
'Really trust this key?');
if (!phutil_console_confirm($prompt)) {
throw new PhutilArgumentUsageException(
pht('User aborted workflow.'));
}
$key->setIsTrusted(1);
$key->save();
PhabricatorAuthSSHKeyQuery::deleteSSHKeyCache();
$console->writeOut(
"**<bg:green> %s </bg>** %s\n",
pht('TRUSTED'),
pht('Key %s has been marked as trusted.', $id));
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/util/AlmanacNames.php | src/applications/almanac/util/AlmanacNames.php | <?php
final class AlmanacNames extends Phobject {
public static function validateName($name) {
if (strlen($name) < 3) {
throw new Exception(
pht(
'Almanac service, device, property, network and namespace names '.
'must be at least 3 characters long.'));
}
if (strlen($name) > 100) {
throw new Exception(
pht(
'Almanac service, device, property, network and namespace names '.
'may not be more than 100 characters long.'));
}
if (!preg_match('/^[a-z0-9.-]+\z/', $name)) {
throw new Exception(
pht(
'Almanac service, device, property, network and namespace names '.
'may only contain lowercase letters, numbers, hyphens, and '.
'periods.'));
}
if (preg_match('/(^|\\.)\d+(\z|\\.)/', $name)) {
throw new Exception(
pht(
'Almanac service, device, network, property and namespace names '.
'may not have any segments containing only digits.'));
}
if (preg_match('/\.\./', $name)) {
throw new Exception(
pht(
'Almanac service, device, property, network and namespace names '.
'may not contain multiple consecutive periods.'));
}
if (preg_match('/\\.-|-\\./', $name)) {
throw new Exception(
pht(
'Almanac service, device, property, network and namespace names '.
'may not contain hyphens adjacent to periods.'));
}
if (preg_match('/--/', $name)) {
throw new Exception(
pht(
'Almanac service, device, property, network and namespace names '.
'may not contain multiple consecutive hyphens.'));
}
if (!preg_match('/^[a-z0-9].*[a-z0-9]\z/', $name)) {
throw new Exception(
pht(
'Almanac service, device, property, network and namespace names '.
'must begin and end with a letter or number.'));
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/util/AlmanacAddress.php | src/applications/almanac/util/AlmanacAddress.php | <?php
final class AlmanacAddress extends Phobject {
private $networkPHID;
private $address;
private $port;
private function __construct() {
// <private>
}
public function getNetworkPHID() {
return $this->networkPHID;
}
public function getAddress() {
return $this->address;
}
public function getPort() {
return $this->port;
}
public static function newFromDictionary(array $dictionary) {
return self::newFromParts(
$dictionary['networkPHID'],
$dictionary['address'],
$dictionary['port']);
}
public static function newFromParts($network_phid, $address, $port) {
$addr = new AlmanacAddress();
$addr->networkPHID = $network_phid;
$addr->address = $address;
$addr->port = (int)$port;
return $addr;
}
public function toDictionary() {
return array(
'networkPHID' => $this->getNetworkPHID(),
'address' => $this->getAddress(),
'port' => $this->getPort(),
);
}
public function toHash() {
return PhabricatorHash::digestForIndex(json_encode($this->toDictionary()));
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/util/AlmanacKeys.php | src/applications/almanac/util/AlmanacKeys.php | <?php
final class AlmanacKeys extends Phobject {
public static function getKeyPath($key_name) {
$root = dirname(phutil_get_library_root('phabricator'));
$keys = $root.'/conf/keys/';
return $keys.ltrim($key_name, '/');
}
public static function getDeviceID() {
// While running unit tests, ignore any configured device identity.
try {
PhabricatorTestCase::assertExecutingUnitTests();
return null;
} catch (Exception $ex) {
// Continue normally.
}
$device_id_path = self::getKeyPath('device.id');
if (Filesystem::pathExists($device_id_path)) {
return trim(Filesystem::readFile($device_id_path));
}
return null;
}
public static function getLiveDevice() {
$device_id = self::getDeviceID();
if (!$device_id) {
return null;
}
$cache = PhabricatorCaches::getRequestCache();
$cache_key = 'almanac.device.self';
$device = $cache->getKey($cache_key);
if (!$device) {
$viewer = PhabricatorUser::getOmnipotentUser();
$device = id(new AlmanacDeviceQuery())
->setViewer($viewer)
->withNames(array($device_id))
->executeOne();
if (!$device) {
throw new Exception(
pht(
'This host has device ID "%s", but there is no corresponding '.
'device record in Almanac.',
$device_id));
}
$cache->setKey($cache_key, $device);
}
return $device;
}
public static function getClusterSSHUser() {
$username = PhabricatorEnv::getEnvConfig('diffusion.ssh-user');
if ($username !== null && strlen($username)) {
return $username;
}
return null;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/util/__tests__/AlmanacNamesTestCase.php | src/applications/almanac/util/__tests__/AlmanacNamesTestCase.php | <?php
final class AlmanacNamesTestCase extends PhabricatorTestCase {
public function testServiceOrDeviceNames() {
$map = array(
'' => false,
'a' => false,
'ab' => false,
'...' => false,
'ab.' => false,
'.ab' => false,
'A-B' => false,
'A!B' => false,
'A.B' => false,
'a..b' => false,
'1.2' => false,
'127.0.0.1' => false,
'1.b' => false,
'a.1' => false,
'a.1.b' => false,
'-.a' => false,
'-a.b' => false,
'a-.b' => false,
'a.-' => false,
'a.-b' => false,
'a.b-' => false,
'-.-' => false,
'a--b' => false,
'abc' => true,
'a.b' => true,
'db.companyname.instance' => true,
'web002.useast.example.com' => true,
'master.example-corp.com' => true,
// Maximum length is 100.
str_repeat('a', 100) => true,
str_repeat('a', 101) => false,
);
foreach ($map as $input => $expect) {
$caught = null;
try {
AlmanacNames::validateName($input);
} catch (Exception $ex) {
$caught = $ex;
}
$this->assertEqual(
$expect,
!($caught instanceof Exception),
$input);
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacNamespaceSearchEngine.php | src/applications/almanac/query/AlmanacNamespaceSearchEngine.php | <?php
final class AlmanacNamespaceSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Almanac Namespaces');
}
public function getApplicationClassName() {
return 'PhabricatorAlmanacApplication';
}
public function newQuery() {
return new AlmanacNamespaceQuery();
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('match')
->setDescription(pht('Search for namespaces by name substring.')),
);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['match'] !== null) {
$query->withNameNgrams($map['match']);
}
return $query;
}
protected function getURI($path) {
return '/almanac/namespace/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Namespaces'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $namespaces,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($namespaces, 'AlmanacNamespace');
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($namespaces as $namespace) {
$id = $namespace->getID();
$item = id(new PHUIObjectItemView())
->setObjectName(pht('Namespace %d', $id))
->setHeader($namespace->getName())
->setHref($this->getApplicationURI("namespace/{$id}/"))
->setObject($namespace);
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No Almanac namespaces found.'));
return $result;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacNamespaceTransactionQuery.php | src/applications/almanac/query/AlmanacNamespaceTransactionQuery.php | <?php
final class AlmanacNamespaceTransactionQuery
extends PhabricatorApplicationTransactionQuery {
public function getTemplateApplicationTransaction() {
return new AlmanacNamespaceTransaction();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacServiceTransactionQuery.php | src/applications/almanac/query/AlmanacServiceTransactionQuery.php | <?php
final class AlmanacServiceTransactionQuery
extends PhabricatorApplicationTransactionQuery {
public function getTemplateApplicationTransaction() {
return new AlmanacServiceTransaction();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacBindingSearchEngine.php | src/applications/almanac/query/AlmanacBindingSearchEngine.php | <?php
final class AlmanacBindingSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Almanac Bindings');
}
public function getApplicationClassName() {
return 'PhabricatorAlmanacApplication';
}
public function newQuery() {
return new AlmanacBindingQuery();
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorPHIDsSearchField())
->setLabel(pht('Services'))
->setKey('servicePHIDs')
->setAliases(array('service', 'servicePHID', 'services'))
->setDescription(pht('Search for bindings on particular services.')),
id(new PhabricatorPHIDsSearchField())
->setLabel(pht('Devices'))
->setKey('devicePHIDs')
->setAliases(array('device', 'devicePHID', 'devices'))
->setDescription(pht('Search for bindings on particular devices.')),
);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['servicePHIDs']) {
$query->withServicePHIDs($map['servicePHIDs']);
}
if ($map['devicePHIDs']) {
$query->withDevicePHIDs($map['devicePHIDs']);
}
return $query;
}
protected function getURI($path) {
return '/almanac/binding/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Bindings'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $devices,
PhabricatorSavedQuery $query,
array $handles) {
// For now, this SearchEngine just supports API access via Conduit.
throw new PhutilMethodNotImplementedException();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacNetworkSearchEngine.php | src/applications/almanac/query/AlmanacNetworkSearchEngine.php | <?php
final class AlmanacNetworkSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Almanac Networks');
}
public function getApplicationClassName() {
return 'PhabricatorAlmanacApplication';
}
public function newQuery() {
return new AlmanacNetworkQuery();
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('match')
->setDescription(pht('Search for networks by name substring.')),
);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['match'] !== null) {
$query->withNameNgrams($map['match']);
}
return $query;
}
protected function getURI($path) {
return '/almanac/network/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Networks'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $networks,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($networks, 'AlmanacNetwork');
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($networks as $network) {
$id = $network->getID();
$item = id(new PHUIObjectItemView())
->setObjectName(pht('Network %d', $id))
->setHeader($network->getName())
->setHref($this->getApplicationURI("network/{$id}/"))
->setObject($network);
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No Almanac Networks found.'));
return $result;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacServiceSearchEngine.php | src/applications/almanac/query/AlmanacServiceSearchEngine.php | <?php
final class AlmanacServiceSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Almanac Services');
}
public function getApplicationClassName() {
return 'PhabricatorAlmanacApplication';
}
public function newQuery() {
return new AlmanacServiceQuery();
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['match'] !== null) {
$query->withNameNgrams($map['match']);
}
if ($map['names']) {
$query->withNames($map['names']);
}
if ($map['devicePHIDs']) {
$query->withDevicePHIDs($map['devicePHIDs']);
}
if ($map['serviceTypes']) {
$query->withServiceTypes($map['serviceTypes']);
}
return $query;
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('match')
->setDescription(pht('Search for services by name substring.')),
id(new PhabricatorSearchStringListField())
->setLabel(pht('Exact Names'))
->setKey('names')
->setDescription(pht('Search for services with specific names.')),
id(new PhabricatorSearchDatasourceField())
->setLabel(pht('Service Types'))
->setKey('serviceTypes')
->setDescription(pht('Find services by type.'))
->setDatasource(id(new AlmanacServiceTypeDatasource())),
id(new PhabricatorPHIDsSearchField())
->setLabel(pht('Devices'))
->setKey('devicePHIDs')
->setDescription(
pht('Search for services bound to particular devices.')),
);
}
protected function getURI($path) {
return '/almanac/service/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Services'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $services,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($services, 'AlmanacService');
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($services as $service) {
$item = id(new PHUIObjectItemView())
->setObjectName(pht('Service %d', $service->getID()))
->setHeader($service->getName())
->setHref($service->getURI())
->setObject($service)
->addIcon(
$service->getServiceImplementation()->getServiceTypeIcon(),
$service->getServiceImplementation()->getServiceTypeShortName());
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No Almanac Services found.'));
return $result;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacNamespaceQuery.php | src/applications/almanac/query/AlmanacNamespaceQuery.php | <?php
final class AlmanacNamespaceQuery
extends AlmanacQuery {
private $ids;
private $phids;
private $names;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withNames(array $names) {
$this->names = $names;
return $this;
}
public function withNameNgrams($ngrams) {
return $this->withNgramsConstraint(
new AlmanacNamespaceNameNgrams(),
$ngrams);
}
public function newResultObject() {
return new AlmanacNamespace();
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'namespace.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'namespace.phid IN (%Ls)',
$this->phids);
}
if ($this->names !== null) {
$where[] = qsprintf(
$conn,
'namespace.name IN (%Ls)',
$this->names);
}
return $where;
}
protected function getPrimaryTableAlias() {
return 'namespace';
}
public function getOrderableColumns() {
return parent::getOrderableColumns() + array(
'name' => array(
'table' => $this->getPrimaryTableAlias(),
'column' => 'name',
'type' => 'string',
'unique' => true,
'reverse' => true,
),
);
}
protected function newPagingMapFromPartialObject($object) {
return array(
'id' => (int)$object->getID(),
'name' => $object->getName(),
);
}
public function getBuiltinOrders() {
return array(
'name' => array(
'vector' => array('name'),
'name' => pht('Namespace Name'),
),
) + parent::getBuiltinOrders();
}
public function getQueryApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacDeviceTransactionQuery.php | src/applications/almanac/query/AlmanacDeviceTransactionQuery.php | <?php
final class AlmanacDeviceTransactionQuery
extends PhabricatorApplicationTransactionQuery {
public function getTemplateApplicationTransaction() {
return new AlmanacDeviceTransaction();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacNetworkTransactionQuery.php | src/applications/almanac/query/AlmanacNetworkTransactionQuery.php | <?php
final class AlmanacNetworkTransactionQuery
extends PhabricatorApplicationTransactionQuery {
public function getTemplateApplicationTransaction() {
return new AlmanacNetworkTransaction();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacDeviceQuery.php | src/applications/almanac/query/AlmanacDeviceQuery.php | <?php
final class AlmanacDeviceQuery
extends AlmanacQuery {
private $ids;
private $phids;
private $names;
private $namePrefix;
private $nameSuffix;
private $isClusterDevice;
private $statuses;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withNames(array $names) {
$this->names = $names;
return $this;
}
public function withNamePrefix($prefix) {
$this->namePrefix = $prefix;
return $this;
}
public function withNameSuffix($suffix) {
$this->nameSuffix = $suffix;
return $this;
}
public function withStatuses(array $statuses) {
$this->statuses = $statuses;
return $this;
}
public function withNameNgrams($ngrams) {
return $this->withNgramsConstraint(
new AlmanacDeviceNameNgrams(),
$ngrams);
}
public function withIsClusterDevice($is_cluster_device) {
$this->isClusterDevice = $is_cluster_device;
return $this;
}
public function newResultObject() {
return new AlmanacDevice();
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'device.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'device.phid IN (%Ls)',
$this->phids);
}
if ($this->names !== null) {
$hashes = array();
foreach ($this->names as $name) {
$hashes[] = PhabricatorHash::digestForIndex($name);
}
$where[] = qsprintf(
$conn,
'device.nameIndex IN (%Ls)',
$hashes);
}
if ($this->namePrefix !== null) {
$where[] = qsprintf(
$conn,
'device.name LIKE %>',
$this->namePrefix);
}
if ($this->nameSuffix !== null) {
$where[] = qsprintf(
$conn,
'device.name LIKE %<',
$this->nameSuffix);
}
if ($this->isClusterDevice !== null) {
$where[] = qsprintf(
$conn,
'device.isBoundToClusterService = %d',
(int)$this->isClusterDevice);
}
if ($this->statuses !== null) {
$where[] = qsprintf(
$conn,
'device.status IN (%Ls)',
$this->statuses);
}
return $where;
}
protected function getPrimaryTableAlias() {
return 'device';
}
public function getOrderableColumns() {
return parent::getOrderableColumns() + array(
'name' => array(
'table' => $this->getPrimaryTableAlias(),
'column' => 'name',
'type' => 'string',
'unique' => true,
'reverse' => true,
),
);
}
protected function newPagingMapFromPartialObject($object) {
return array(
'id' => (int)$object->getID(),
'name' => $object->getName(),
);
}
public function getBuiltinOrders() {
return array(
'name' => array(
'vector' => array('name'),
'name' => pht('Device Name'),
),
) + parent::getBuiltinOrders();
}
public function getQueryApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacDeviceSearchEngine.php | src/applications/almanac/query/AlmanacDeviceSearchEngine.php | <?php
final class AlmanacDeviceSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Almanac Devices');
}
public function getApplicationClassName() {
return 'PhabricatorAlmanacApplication';
}
public function newQuery() {
return new AlmanacDeviceQuery();
}
protected function buildCustomSearchFields() {
$status_options = AlmanacDeviceStatus::getStatusMap();
$status_options = mpull($status_options, 'getName');
return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('match')
->setDescription(pht('Search for devices by name substring.')),
id(new PhabricatorSearchStringListField())
->setLabel(pht('Exact Names'))
->setKey('names')
->setDescription(pht('Search for devices with specific names.')),
id(new PhabricatorSearchCheckboxesField())
->setLabel(pht('Statuses'))
->setKey('statuses')
->setDescription(pht('Search for devices with given statuses.'))
->setOptions($status_options),
id(new PhabricatorSearchThreeStateField())
->setLabel(pht('Cluster Device'))
->setKey('isClusterDevice')
->setOptions(
pht('Both Cluster and Non-cluster Devices'),
pht('Cluster Devices Only'),
pht('Non-cluster Devices Only')),
);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['match'] !== null) {
$query->withNameNgrams($map['match']);
}
if ($map['names']) {
$query->withNames($map['names']);
}
if ($map['isClusterDevice'] !== null) {
$query->withIsClusterDevice($map['isClusterDevice']);
}
if ($map['statuses']) {
$query->withStatuses($map['statuses']);
}
return $query;
}
protected function getURI($path) {
return '/almanac/device/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'active' => pht('Active Devices'),
'all' => pht('All Devices'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'active':
$active_statuses = AlmanacDeviceStatus::getActiveStatusList();
return $query->setParameter('statuses', $active_statuses);
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $devices,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($devices, 'AlmanacDevice');
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($devices as $device) {
$item = id(new PHUIObjectItemView())
->setObjectName(pht('Device %d', $device->getID()))
->setHeader($device->getName())
->setHref($device->getURI())
->setObject($device);
if ($device->isClusterDevice()) {
$item->addIcon('fa-sitemap', pht('Cluster Device'));
}
if ($device->isDisabled()) {
$item->setDisabled(true);
}
$status = $device->getStatusObject();
$icon_icon = $status->getIconIcon();
$icon_color = $status->getIconColor();
$icon_label = $status->getName();
$item->setStatusIcon(
"{$icon_icon} {$icon_color}",
$icon_label);
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No Almanac Devices found.'));
return $result;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacBindingQuery.php | src/applications/almanac/query/AlmanacBindingQuery.php | <?php
final class AlmanacBindingQuery
extends AlmanacQuery {
private $ids;
private $phids;
private $servicePHIDs;
private $devicePHIDs;
private $interfacePHIDs;
private $isActive;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withServicePHIDs(array $phids) {
$this->servicePHIDs = $phids;
return $this;
}
public function withDevicePHIDs(array $phids) {
$this->devicePHIDs = $phids;
return $this;
}
public function withInterfacePHIDs(array $phids) {
$this->interfacePHIDs = $phids;
return $this;
}
public function withIsActive($active) {
$this->isActive = $active;
return $this;
}
public function newResultObject() {
return new AlmanacBinding();
}
protected function willFilterPage(array $bindings) {
$service_phids = mpull($bindings, 'getServicePHID');
$device_phids = mpull($bindings, 'getDevicePHID');
$interface_phids = mpull($bindings, 'getInterfacePHID');
$services = id(new AlmanacServiceQuery())
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($service_phids)
->needProperties($this->getNeedProperties())
->execute();
$services = mpull($services, null, 'getPHID');
$devices = id(new AlmanacDeviceQuery())
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($device_phids)
->needProperties($this->getNeedProperties())
->execute();
$devices = mpull($devices, null, 'getPHID');
$interfaces = id(new AlmanacInterfaceQuery())
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($interface_phids)
->needProperties($this->getNeedProperties())
->execute();
$interfaces = mpull($interfaces, null, 'getPHID');
foreach ($bindings as $key => $binding) {
$service = idx($services, $binding->getServicePHID());
$device = idx($devices, $binding->getDevicePHID());
$interface = idx($interfaces, $binding->getInterfacePHID());
if (!$service || !$device || !$interface) {
$this->didRejectResult($binding);
unset($bindings[$key]);
continue;
}
$binding->attachService($service);
$binding->attachDevice($device);
$binding->attachInterface($interface);
}
return $bindings;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'binding.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'binding.phid IN (%Ls)',
$this->phids);
}
if ($this->servicePHIDs !== null) {
$where[] = qsprintf(
$conn,
'binding.servicePHID IN (%Ls)',
$this->servicePHIDs);
}
if ($this->devicePHIDs !== null) {
$where[] = qsprintf(
$conn,
'binding.devicePHID IN (%Ls)',
$this->devicePHIDs);
}
if ($this->interfacePHIDs !== null) {
$where[] = qsprintf(
$conn,
'binding.interfacePHID IN (%Ls)',
$this->interfacePHIDs);
}
if ($this->isActive !== null) {
if ($this->isActive) {
$where[] = qsprintf(
$conn,
'(binding.isDisabled = 0) AND (device.status IN (%Ls))',
AlmanacDeviceStatus::getActiveStatusList());
} else {
$where[] = qsprintf(
$conn,
'(binding.isDisabled = 1) OR (device.status IN (%Ls))',
AlmanacDeviceStatus::getDisabledStatusList());
}
}
return $where;
}
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
$joins = parent::buildJoinClauseParts($conn);
if ($this->shouldJoinDeviceTable()) {
$device_table = new AlmanacDevice();
$joins[] = qsprintf(
$conn,
'JOIN %R device ON binding.devicePHID = device.phid',
$device_table);
}
return $joins;
}
private function shouldJoinDeviceTable() {
if ($this->isActive !== null) {
return true;
}
return false;
}
protected function getPrimaryTableAlias() {
return 'binding';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacBindingTransactionQuery.php | src/applications/almanac/query/AlmanacBindingTransactionQuery.php | <?php
final class AlmanacBindingTransactionQuery
extends PhabricatorApplicationTransactionQuery {
public function getTemplateApplicationTransaction() {
return new AlmanacBindingTransaction();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacInterfaceSearchEngine.php | src/applications/almanac/query/AlmanacInterfaceSearchEngine.php | <?php
final class AlmanacInterfaceSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Almanac Interfaces');
}
public function getApplicationClassName() {
return 'PhabricatorAlmanacApplication';
}
public function newQuery() {
return new AlmanacInterfaceQuery();
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorPHIDsSearchField())
->setLabel(pht('Devices'))
->setKey('devicePHIDs')
->setAliases(array('device', 'devicePHID', 'devices'))
->setDescription(pht('Search for interfaces on particular devices.')),
);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['devicePHIDs']) {
$query->withDevicePHIDs($map['devicePHIDs']);
}
return $query;
}
protected function getURI($path) {
return '/almanac/interface/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Interfaces'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $devices,
PhabricatorSavedQuery $query,
array $handles) {
// For now, this SearchEngine just supports API access via Conduit.
throw new PhutilMethodNotImplementedException();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacQuery.php | src/applications/almanac/query/AlmanacQuery.php | <?php
abstract class AlmanacQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $needProperties;
public function needProperties($need_properties) {
$this->needProperties = $need_properties;
return $this;
}
protected function getNeedProperties() {
return $this->needProperties;
}
protected function didFilterPage(array $objects) {
$has_properties = (head($objects) instanceof AlmanacPropertyInterface);
if ($has_properties && $this->needProperties) {
$property_query = id(new AlmanacPropertyQuery())
->setViewer($this->getViewer())
->setParentQuery($this)
->withObjects($objects);
$properties = $property_query->execute();
$properties = mgroup($properties, 'getObjectPHID');
foreach ($objects as $object) {
$object_properties = idx($properties, $object->getPHID(), array());
$object_properties = mpull($object_properties, null, 'getFieldName');
// Create synthetic properties for defaults on the object itself.
$specs = $object->getAlmanacPropertyFieldSpecifications();
foreach ($specs as $key => $spec) {
if (empty($object_properties[$key])) {
$default_value = $spec->getValueForTransaction();
$object_properties[$key] = id(new AlmanacProperty())
->setObjectPHID($object->getPHID())
->setFieldName($key)
->setFieldValue($default_value);
}
}
foreach ($object_properties as $property) {
$property->attachObject($object);
}
$object->attachAlmanacProperties($object_properties);
}
}
return $objects;
}
public function getQueryApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacPropertyQuery.php | src/applications/almanac/query/AlmanacPropertyQuery.php | <?php
final class AlmanacPropertyQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $objectPHIDs;
private $objects;
private $names;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withObjectPHIDs(array $phids) {
$this->objectPHIDs = $phids;
return $this;
}
public function withObjects(array $objects) {
$this->objects = mpull($objects, null, 'getPHID');
$this->objectPHIDs = array_keys($this->objects);
return $this;
}
public function withNames(array $names) {
$this->names = $names;
return $this;
}
public function newResultObject() {
return new AlmanacProperty();
}
protected function willFilterPage(array $properties) {
$object_phids = mpull($properties, 'getObjectPHID');
$object_phids = array_fuse($object_phids);
if ($this->objects !== null) {
$object_phids = array_diff_key($object_phids, $this->objects);
}
if ($object_phids) {
$objects = id(new PhabricatorObjectQuery())
->setViewer($this->getViewer())
->setParentQuery($this)
->withPHIDs($object_phids)
->execute();
$objects = mpull($objects, null, 'getPHID');
} else {
$objects = array();
}
$objects += $this->objects;
foreach ($properties as $key => $property) {
$object = idx($objects, $property->getObjectPHID());
if (!$object) {
unset($properties[$key]);
continue;
}
$property->attachObject($object);
}
return $properties;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'id IN (%Ld)',
$this->ids);
}
if ($this->objectPHIDs !== null) {
$where[] = qsprintf(
$conn,
'objectPHID IN (%Ls)',
$this->objectPHIDs);
}
if ($this->names !== null) {
$hashes = array();
foreach ($this->names as $name) {
$hashes[] = PhabricatorHash::digestForIndex($name);
}
$where[] = qsprintf(
$conn,
'fieldIndex IN (%Ls)',
$hashes);
}
return $where;
}
public function getQueryApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacInterfaceQuery.php | src/applications/almanac/query/AlmanacInterfaceQuery.php | <?php
final class AlmanacInterfaceQuery
extends AlmanacQuery {
private $ids;
private $phids;
private $networkPHIDs;
private $devicePHIDs;
private $addresses;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withNetworkPHIDs(array $phids) {
$this->networkPHIDs = $phids;
return $this;
}
public function withDevicePHIDs(array $phids) {
$this->devicePHIDs = $phids;
return $this;
}
public function withAddresses(array $addresses) {
$this->addresses = $addresses;
return $this;
}
public function newResultObject() {
return new AlmanacInterface();
}
protected function willFilterPage(array $interfaces) {
$network_phids = mpull($interfaces, 'getNetworkPHID');
$device_phids = mpull($interfaces, 'getDevicePHID');
$networks = id(new AlmanacNetworkQuery())
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($network_phids)
->needProperties($this->getNeedProperties())
->execute();
$networks = mpull($networks, null, 'getPHID');
$devices = id(new AlmanacDeviceQuery())
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($device_phids)
->needProperties($this->getNeedProperties())
->execute();
$devices = mpull($devices, null, 'getPHID');
foreach ($interfaces as $key => $interface) {
$network = idx($networks, $interface->getNetworkPHID());
$device = idx($devices, $interface->getDevicePHID());
if (!$network || !$device) {
$this->didRejectResult($interface);
unset($interfaces[$key]);
continue;
}
$interface->attachNetwork($network);
$interface->attachDevice($device);
}
return $interfaces;
}
protected function buildSelectClauseParts(AphrontDatabaseConnection $conn) {
$select = parent::buildSelectClauseParts($conn);
if ($this->shouldJoinDeviceTable()) {
$select[] = qsprintf($conn, 'device.name');
}
return $select;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'interface.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'interface.phid IN (%Ls)',
$this->phids);
}
if ($this->networkPHIDs !== null) {
$where[] = qsprintf(
$conn,
'interface.networkPHID IN (%Ls)',
$this->networkPHIDs);
}
if ($this->devicePHIDs !== null) {
$where[] = qsprintf(
$conn,
'interface.devicePHID IN (%Ls)',
$this->devicePHIDs);
}
if ($this->addresses !== null) {
$parts = array();
foreach ($this->addresses as $address) {
$parts[] = qsprintf(
$conn,
'(interface.networkPHID = %s '.
'AND interface.address = %s '.
'AND interface.port = %d)',
$address->getNetworkPHID(),
$address->getAddress(),
$address->getPort());
}
$where[] = qsprintf($conn, '%LO', $parts);
}
return $where;
}
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
$joins = parent::buildJoinClauseParts($conn);
if ($this->shouldJoinDeviceTable()) {
$joins[] = qsprintf(
$conn,
'JOIN %T device ON device.phid = interface.devicePHID',
id(new AlmanacDevice())->getTableName());
}
return $joins;
}
protected function shouldGroupQueryResultRows() {
if ($this->shouldJoinDeviceTable()) {
return true;
}
return parent::shouldGroupQueryResultRows();
}
private function shouldJoinDeviceTable() {
$vector = $this->getOrderVector();
if ($vector->containsKey('name')) {
return true;
}
return false;
}
protected function getPrimaryTableAlias() {
return 'interface';
}
public function getQueryApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
public function getBuiltinOrders() {
return array(
'name' => array(
'vector' => array('name', 'id'),
'name' => pht('Device Name'),
),
) + parent::getBuiltinOrders();
}
public function getOrderableColumns() {
return parent::getOrderableColumns() + array(
'name' => array(
'table' => 'device',
'column' => 'name',
'type' => 'string',
'reverse' => true,
),
);
}
protected function newPagingMapFromCursorObject(
PhabricatorQueryCursor $cursor,
array $keys) {
$interface = $cursor->getObject();
return array(
'id' => (int)$interface->getID(),
'name' => $cursor->getRawRowProperty('device.name'),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacNetworkQuery.php | src/applications/almanac/query/AlmanacNetworkQuery.php | <?php
final class AlmanacNetworkQuery
extends AlmanacQuery {
private $ids;
private $phids;
private $names;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function newResultObject() {
return new AlmanacNetwork();
}
public function withNames(array $names) {
$this->names = $names;
return $this;
}
public function withNameNgrams($ngrams) {
return $this->withNgramsConstraint(
new AlmanacNetworkNameNgrams(),
$ngrams);
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'network.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'network.phid IN (%Ls)',
$this->phids);
}
if ($this->names !== null) {
$where[] = qsprintf(
$conn,
'network.name IN (%Ls)',
$this->names);
}
return $where;
}
protected function getPrimaryTableAlias() {
return 'network';
}
public function getQueryApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacServiceQuery.php | src/applications/almanac/query/AlmanacServiceQuery.php | <?php
final class AlmanacServiceQuery
extends AlmanacQuery {
private $ids;
private $phids;
private $names;
private $serviceTypes;
private $devicePHIDs;
private $namePrefix;
private $nameSuffix;
private $needBindings;
private $needActiveBindings;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withNames(array $names) {
$this->names = $names;
return $this;
}
public function withServiceTypes(array $types) {
$this->serviceTypes = $types;
return $this;
}
public function withDevicePHIDs(array $phids) {
$this->devicePHIDs = $phids;
return $this;
}
public function withNamePrefix($prefix) {
$this->namePrefix = $prefix;
return $this;
}
public function withNameSuffix($suffix) {
$this->nameSuffix = $suffix;
return $this;
}
public function withNameNgrams($ngrams) {
return $this->withNgramsConstraint(
new AlmanacServiceNameNgrams(),
$ngrams);
}
public function needBindings($need_bindings) {
$this->needBindings = $need_bindings;
return $this;
}
public function needActiveBindings($need_active) {
$this->needActiveBindings = $need_active;
return $this;
}
public function newResultObject() {
return new AlmanacService();
}
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
$joins = parent::buildJoinClauseParts($conn);
if ($this->shouldJoinBindingTable()) {
$joins[] = qsprintf(
$conn,
'JOIN %T binding ON service.phid = binding.servicePHID',
id(new AlmanacBinding())->getTableName());
}
return $joins;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'service.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'service.phid IN (%Ls)',
$this->phids);
}
if ($this->names !== null) {
$hashes = array();
foreach ($this->names as $name) {
$hashes[] = PhabricatorHash::digestForIndex($name);
}
$where[] = qsprintf(
$conn,
'service.nameIndex IN (%Ls)',
$hashes);
}
if ($this->serviceTypes !== null) {
$where[] = qsprintf(
$conn,
'service.serviceType IN (%Ls)',
$this->serviceTypes);
}
if ($this->devicePHIDs !== null) {
$where[] = qsprintf(
$conn,
'binding.devicePHID IN (%Ls)',
$this->devicePHIDs);
}
if ($this->namePrefix !== null) {
$where[] = qsprintf(
$conn,
'service.name LIKE %>',
$this->namePrefix);
}
if ($this->nameSuffix !== null) {
$where[] = qsprintf(
$conn,
'service.name LIKE %<',
$this->nameSuffix);
}
return $where;
}
protected function willFilterPage(array $services) {
$service_map = AlmanacServiceType::getAllServiceTypes();
foreach ($services as $key => $service) {
$implementation = idx($service_map, $service->getServiceType());
if (!$implementation) {
$this->didRejectResult($service);
unset($services[$key]);
continue;
}
$implementation = clone $implementation;
$service->attachServiceImplementation($implementation);
}
return $services;
}
protected function didFilterPage(array $services) {
$need_all = $this->needBindings;
$need_active = $this->needActiveBindings;
$need_any = ($need_all || $need_active);
$only_active = ($need_active && !$need_all);
if ($need_any) {
$service_phids = mpull($services, 'getPHID');
$bindings_query = id(new AlmanacBindingQuery())
->setViewer($this->getViewer())
->withServicePHIDs($service_phids)
->needProperties($this->getNeedProperties());
if ($only_active) {
$bindings_query->withIsActive(true);
}
$bindings = $bindings_query->execute();
$bindings = mgroup($bindings, 'getServicePHID');
foreach ($services as $service) {
$service_bindings = idx($bindings, $service->getPHID(), array());
if ($only_active) {
$service->attachActiveBindings($service_bindings);
} else {
$service->attachBindings($service_bindings);
}
}
}
return parent::didFilterPage($services);
}
private function shouldJoinBindingTable() {
return ($this->devicePHIDs !== null);
}
protected function shouldGroupQueryResultRows() {
if ($this->shouldJoinBindingTable()) {
return true;
}
return parent::shouldGroupQueryResultRows();
}
protected function getPrimaryTableAlias() {
return 'service';
}
public function getOrderableColumns() {
return parent::getOrderableColumns() + array(
'name' => array(
'table' => $this->getPrimaryTableAlias(),
'column' => 'name',
'type' => 'string',
'unique' => true,
'reverse' => true,
),
);
}
protected function newPagingMapFromPartialObject($object) {
return array(
'id' => (int)$object->getID(),
'name' => $object->getName(),
);
}
public function getBuiltinOrders() {
return array(
'name' => array(
'vector' => array('name'),
'name' => pht('Service Name'),
),
) + parent::getBuiltinOrders();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/query/AlmanacInterfaceTransactionQuery.php | src/applications/almanac/query/AlmanacInterfaceTransactionQuery.php | <?php
final class AlmanacInterfaceTransactionQuery
extends PhabricatorApplicationTransactionQuery {
public function getTemplateApplicationTransaction() {
return new AlmanacInterfaceTransaction();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacNetworkEditor.php | src/applications/almanac/editor/AlmanacNetworkEditor.php | <?php
final class AlmanacNetworkEditor
extends AlmanacEditor {
public function getEditorObjectsDescription() {
return pht('Almanac Network');
}
public function getCreateObjectTitle($author, $object) {
return pht('%s created this network.', $author);
}
public function getCreateObjectTitleForFeed($author, $object) {
return pht('%s created %s.', $author, $object);
}
protected function supportsSearch() {
return true;
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
return $types;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacServicePropertyEditEngine.php | src/applications/almanac/editor/AlmanacServicePropertyEditEngine.php | <?php
final class AlmanacServicePropertyEditEngine
extends AlmanacPropertyEditEngine {
const ENGINECONST = 'almanac.service.property';
protected function newObjectQuery() {
return new AlmanacServiceQuery();
}
protected function getObjectViewURI($object) {
return $object->getURI();
}
protected function getObjectName() {
return pht('Property');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacDeviceEditEngine.php | src/applications/almanac/editor/AlmanacDeviceEditEngine.php | <?php
final class AlmanacDeviceEditEngine
extends PhabricatorEditEngine {
const ENGINECONST = 'almanac.device';
public function isEngineConfigurable() {
return false;
}
public function getEngineName() {
return pht('Almanac Devices');
}
public function getSummaryHeader() {
return pht('Edit Almanac Device Configurations');
}
public function getSummaryText() {
return pht('This engine is used to edit Almanac devices.');
}
public function getEngineApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
protected function newEditableObject() {
return AlmanacDevice::initializeNewDevice();
}
protected function newObjectQuery() {
return id(new AlmanacDeviceQuery())
->needProperties(true);
}
protected function getObjectCreateTitleText($object) {
return pht('Create Device');
}
protected function getObjectCreateButtonText($object) {
return pht('Create Device');
}
protected function getObjectEditTitleText($object) {
return pht('Edit Device: %s', $object->getName());
}
protected function getObjectEditShortText($object) {
return pht('Edit Device');
}
protected function getObjectCreateShortText() {
return pht('Create Device');
}
protected function getObjectName() {
return pht('Device');
}
protected function getEditorURI() {
return '/almanac/device/edit/';
}
protected function getObjectCreateCancelURI($object) {
return '/almanac/device/';
}
protected function getObjectViewURI($object) {
return $object->getURI();
}
protected function getCreateNewObjectPolicy() {
return $this->getApplication()->getPolicy(
AlmanacCreateDevicesCapability::CAPABILITY);
}
protected function buildCustomEditFields($object) {
$status_map = $this->getDeviceStatusMap($object);
return array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setDescription(pht('Name of the device.'))
->setTransactionType(AlmanacDeviceNameTransaction::TRANSACTIONTYPE)
->setIsRequired(true)
->setValue($object->getName()),
id(new PhabricatorSelectEditField())
->setKey('status')
->setLabel(pht('Status'))
->setDescription(pht('Device status.'))
->setTransactionType(AlmanacDeviceStatusTransaction::TRANSACTIONTYPE)
->setOptions($status_map)
->setValue($object->getStatus()),
);
}
private function getDeviceStatusMap(AlmanacDevice $device) {
$status_map = AlmanacDeviceStatus::getStatusMap();
// If the device currently has an unknown status, add it to the list for
// the dropdown.
$status_value = $device->getStatus();
if (!isset($status_map[$status_value])) {
$status_map = array(
$status_value => AlmanacDeviceStatus::newStatusFromValue($status_value),
) + $status_map;
}
$status_map = mpull($status_map, 'getName');
return $status_map;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacBindingPropertyEditEngine.php | src/applications/almanac/editor/AlmanacBindingPropertyEditEngine.php | <?php
final class AlmanacBindingPropertyEditEngine
extends AlmanacPropertyEditEngine {
const ENGINECONST = 'almanac.binding.property';
protected function newObjectQuery() {
return new AlmanacBindingQuery();
}
protected function getObjectViewURI($object) {
return $object->getURI();
}
protected function getObjectName() {
return pht('Property');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacNamespaceEditor.php | src/applications/almanac/editor/AlmanacNamespaceEditor.php | <?php
final class AlmanacNamespaceEditor
extends AlmanacEditor {
public function getEditorObjectsDescription() {
return pht('Almanac Namespace');
}
public function getCreateObjectTitle($author, $object) {
return pht('%s created this namespace.', $author);
}
public function getCreateObjectTitleForFeed($author, $object) {
return pht('%s created %s.', $author, $object);
}
protected function supportsSearch() {
return true;
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
return $types;
}
protected function didCatchDuplicateKeyException(
PhabricatorLiskDAO $object,
array $xactions,
Exception $ex) {
$errors = array();
$errors[] = new PhabricatorApplicationTransactionValidationError(
null,
pht('Invalid'),
pht(
'Another namespace with this name already exists. Each namespace '.
'must have a unique name.'),
null);
throw new PhabricatorApplicationTransactionValidationException($errors);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacEditor.php | src/applications/almanac/editor/AlmanacEditor.php | <?php
abstract class AlmanacEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacBindingEditEngine.php | src/applications/almanac/editor/AlmanacBindingEditEngine.php | <?php
final class AlmanacBindingEditEngine
extends PhabricatorEditEngine {
const ENGINECONST = 'almanac.binding';
private $service;
public function setService(AlmanacService $service) {
$this->service = $service;
return $this;
}
public function getService() {
if (!$this->service) {
throw new PhutilInvalidStateException('setService');
}
return $this->service;
}
public function isEngineConfigurable() {
return false;
}
public function getEngineName() {
return pht('Almanac Bindings');
}
public function getSummaryHeader() {
return pht('Edit Almanac Binding Configurations');
}
public function getSummaryText() {
return pht('This engine is used to edit Almanac bindings.');
}
public function getEngineApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
protected function newEditableObject() {
$service = $this->getService();
return AlmanacBinding::initializeNewBinding($service);
}
protected function newEditableObjectForDocumentation() {
$service_type = AlmanacCustomServiceType::SERVICETYPE;
$service = AlmanacService::initializeNewService($service_type);
$this->setService($service);
return $this->newEditableObject();
}
protected function newEditableObjectFromConduit(array $raw_xactions) {
$service_phid = null;
foreach ($raw_xactions as $raw_xaction) {
if ($raw_xaction['type'] !== 'service') {
continue;
}
$service_phid = $raw_xaction['value'];
}
if ($service_phid === null) {
throw new Exception(
pht(
'When creating a new Almanac binding via the Conduit API, you '.
'must provide a "service" transaction to select a service to bind.'));
}
$service = id(new AlmanacServiceQuery())
->setViewer($this->getViewer())
->withPHIDs(array($service_phid))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$service) {
throw new Exception(
pht(
'Service "%s" is unrecognized, restricted, or you do not have '.
'permission to edit it.',
$service_phid));
}
$this->setService($service);
return $this->newEditableObject();
}
protected function newObjectQuery() {
return id(new AlmanacBindingQuery())
->needProperties(true);
}
protected function getObjectCreateTitleText($object) {
return pht('Create Binding');
}
protected function getObjectCreateButtonText($object) {
return pht('Create Binding');
}
protected function getObjectEditTitleText($object) {
return pht('Edit Binding');
}
protected function getObjectEditShortText($object) {
return pht('Edit Binding');
}
protected function getObjectCreateShortText() {
return pht('Create Binding');
}
protected function getObjectName() {
return pht('Binding');
}
protected function getEditorURI() {
return '/almanac/binding/edit/';
}
protected function getObjectCreateCancelURI($object) {
return '/almanac/binding/';
}
protected function getObjectViewURI($object) {
return $object->getURI();
}
protected function buildCustomEditFields($object) {
return array(
id(new PhabricatorTextEditField())
->setKey('service')
->setLabel(pht('Service'))
->setIsFormField(false)
->setTransactionType(
AlmanacBindingServiceTransaction::TRANSACTIONTYPE)
->setDescription(pht('Service to create a binding for.'))
->setConduitDescription(pht('Select the service to bind.'))
->setConduitTypeDescription(pht('Service PHID.'))
->setValue($object->getServicePHID()),
id(new PhabricatorTextEditField())
->setKey('interface')
->setLabel(pht('Interface'))
->setIsFormField(false)
->setTransactionType(
AlmanacBindingInterfaceTransaction::TRANSACTIONTYPE)
->setDescription(pht('Interface to bind the service to.'))
->setConduitDescription(pht('Set the interface to bind.'))
->setConduitTypeDescription(pht('Interface PHID.'))
->setValue($object->getInterfacePHID()),
id(new PhabricatorBoolEditField())
->setKey('disabled')
->setLabel(pht('Disabled'))
->setIsFormField(false)
->setTransactionType(
AlmanacBindingDisableTransaction::TRANSACTIONTYPE)
->setDescription(pht('Disable or enable the binding.'))
->setConduitDescription(pht('Disable or enable the binding.'))
->setConduitTypeDescription(pht('True to disable the binding.'))
->setValue($object->getIsDisabled())
->setOptions(
pht('Enable Binding'),
pht('Disable Binding')),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacServiceEditor.php | src/applications/almanac/editor/AlmanacServiceEditor.php | <?php
final class AlmanacServiceEditor
extends AlmanacEditor {
public function getEditorObjectsDescription() {
return pht('Almanac Service');
}
public function getCreateObjectTitle($author, $object) {
return pht('%s created this service.', $author);
}
public function getCreateObjectTitleForFeed($author, $object) {
return pht('%s created %s.', $author, $object);
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
return $types;
}
protected function validateAllTransactions(
PhabricatorLiskDAO $object,
array $xactions) {
$errors = parent::validateAllTransactions($object, $xactions);
if ($object->isClusterService()) {
$can_manage = PhabricatorPolicyFilter::hasCapability(
$this->getActor(),
new PhabricatorAlmanacApplication(),
AlmanacManageClusterServicesCapability::CAPABILITY);
if (!$can_manage) {
$errors[] = new PhabricatorApplicationTransactionValidationError(
null,
pht('Restricted'),
pht('You do not have permission to manage cluster services.'),
null);
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacInterfaceEditEngine.php | src/applications/almanac/editor/AlmanacInterfaceEditEngine.php | <?php
final class AlmanacInterfaceEditEngine
extends PhabricatorEditEngine {
const ENGINECONST = 'almanac.interface';
private $device;
public function setDevice(AlmanacDevice $device) {
$this->device = $device;
return $this;
}
public function getDevice() {
if (!$this->device) {
throw new PhutilInvalidStateException('setDevice');
}
return $this->device;
}
public function isEngineConfigurable() {
return false;
}
public function getEngineName() {
return pht('Almanac Interfaces');
}
public function getSummaryHeader() {
return pht('Edit Almanac Interface Configurations');
}
public function getSummaryText() {
return pht('This engine is used to edit Almanac interfaces.');
}
public function getEngineApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
protected function newEditableObject() {
$interface = AlmanacInterface::initializeNewInterface();
$device = $this->getDevice();
$interface
->setDevicePHID($device->getPHID())
->attachDevice($device);
return $interface;
}
protected function newEditableObjectForDocumentation() {
$this->setDevice(new AlmanacDevice());
return $this->newEditableObject();
}
protected function newEditableObjectFromConduit(array $raw_xactions) {
$device_phid = null;
foreach ($raw_xactions as $raw_xaction) {
if ($raw_xaction['type'] !== 'device') {
continue;
}
$device_phid = $raw_xaction['value'];
}
if ($device_phid === null) {
throw new Exception(
pht(
'When creating a new Almanac interface via the Conduit API, you '.
'must provide a "device" transaction to select a device.'));
}
$device = id(new AlmanacDeviceQuery())
->setViewer($this->getViewer())
->withPHIDs(array($device_phid))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$device) {
throw new Exception(
pht(
'Device "%s" is unrecognized, restricted, or you do not have '.
'permission to edit it.',
$device_phid));
}
$this->setDevice($device);
return $this->newEditableObject();
}
protected function newObjectQuery() {
return new AlmanacInterfaceQuery();
}
protected function getObjectCreateTitleText($object) {
return pht('Create Interface');
}
protected function getObjectCreateButtonText($object) {
return pht('Create Interface');
}
protected function getObjectEditTitleText($object) {
return pht('Edit Interface');
}
protected function getObjectEditShortText($object) {
return pht('Edit Interface');
}
protected function getObjectCreateShortText() {
return pht('Create Interface');
}
protected function getObjectName() {
return pht('Interface');
}
protected function getEditorURI() {
return '/almanac/interface/edit/';
}
protected function getObjectCreateCancelURI($object) {
if ($this->getDevice()) {
return $this->getDevice()->getURI();
}
return '/almanac/interface/';
}
protected function getObjectViewURI($object) {
return $object->getDevice()->getURI();
}
protected function buildCustomEditFields($object) {
$viewer = $this->getViewer();
// TODO: Some day, this should be a datasource.
$networks = id(new AlmanacNetworkQuery())
->setViewer($viewer)
->execute();
$network_map = mpull($networks, 'getName', 'getPHID');
return array(
id(new PhabricatorTextEditField())
->setKey('device')
->setLabel(pht('Device'))
->setIsFormField(false)
->setTransactionType(
AlmanacInterfaceDeviceTransaction::TRANSACTIONTYPE)
->setDescription(pht('When creating an interface, set the device.'))
->setConduitDescription(pht('Set the device.'))
->setConduitTypeDescription(pht('Device PHID.'))
->setValue($object->getDevicePHID()),
id(new PhabricatorSelectEditField())
->setKey('network')
->setLabel(pht('Network'))
->setDescription(pht('Network for the interface.'))
->setTransactionType(
AlmanacInterfaceNetworkTransaction::TRANSACTIONTYPE)
->setValue($object->getNetworkPHID())
->setOptions($network_map),
id(new PhabricatorTextEditField())
->setKey('address')
->setLabel(pht('Address'))
->setDescription(pht('Address of the service.'))
->setTransactionType(
AlmanacInterfaceAddressTransaction::TRANSACTIONTYPE)
->setIsRequired(true)
->setValue($object->getAddress()),
id(new PhabricatorIntEditField())
->setKey('port')
->setLabel(pht('Port'))
->setDescription(pht('Port of the service.'))
->setTransactionType(AlmanacInterfacePortTransaction::TRANSACTIONTYPE)
->setIsRequired(true)
->setValue($object->getPort()),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacDevicePropertyEditEngine.php | src/applications/almanac/editor/AlmanacDevicePropertyEditEngine.php | <?php
final class AlmanacDevicePropertyEditEngine
extends AlmanacPropertyEditEngine {
const ENGINECONST = 'almanac.device.property';
protected function newObjectQuery() {
return new AlmanacDeviceQuery();
}
protected function getObjectViewURI($object) {
return $object->getURI();
}
protected function getObjectName() {
return pht('Property');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacBindingEditor.php | src/applications/almanac/editor/AlmanacBindingEditor.php | <?php
final class AlmanacBindingEditor
extends AlmanacEditor {
public function getEditorObjectsDescription() {
return pht('Almanac Binding');
}
public function getCreateObjectTitle($author, $object) {
return pht('%s created this binding.', $author);
}
public function getCreateObjectTitleForFeed($author, $object) {
return pht('%s created %s.', $author, $object);
}
protected function supportsSearch() {
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacDeviceEditor.php | src/applications/almanac/editor/AlmanacDeviceEditor.php | <?php
final class AlmanacDeviceEditor
extends AlmanacEditor {
public function getEditorObjectsDescription() {
return pht('Almanac Device');
}
public function getCreateObjectTitle($author, $object) {
return pht('%s created this device.', $author);
}
public function getCreateObjectTitleForFeed($author, $object) {
return pht('%s created %s.', $author, $object);
}
protected function supportsSearch() {
return true;
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
return $types;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacNamespaceEditEngine.php | src/applications/almanac/editor/AlmanacNamespaceEditEngine.php | <?php
final class AlmanacNamespaceEditEngine
extends PhabricatorEditEngine {
const ENGINECONST = 'almanac.namespace';
public function isEngineConfigurable() {
return false;
}
public function getEngineName() {
return pht('Almanac Namespaces');
}
public function getSummaryHeader() {
return pht('Edit Almanac Namespace Configurations');
}
public function getSummaryText() {
return pht('This engine is used to edit Almanac namespaces.');
}
public function getEngineApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
protected function newEditableObject() {
return AlmanacNamespace::initializeNewNamespace();
}
protected function newObjectQuery() {
return new AlmanacNamespaceQuery();
}
protected function getObjectCreateTitleText($object) {
return pht('Create Namespace');
}
protected function getObjectCreateButtonText($object) {
return pht('Create Namespace');
}
protected function getObjectEditTitleText($object) {
return pht('Edit Namespace: %s', $object->getName());
}
protected function getObjectEditShortText($object) {
return pht('Edit Namespace');
}
protected function getObjectCreateShortText() {
return pht('Create Namespace');
}
protected function getObjectName() {
return pht('Namespace');
}
protected function getEditorURI() {
return '/almanac/namespace/edit/';
}
protected function getObjectCreateCancelURI($object) {
return '/almanac/namespace/';
}
protected function getObjectViewURI($object) {
$id = $object->getID();
return "/almanac/namespace/{$id}/";
}
protected function getCreateNewObjectPolicy() {
return $this->getApplication()->getPolicy(
AlmanacCreateNamespacesCapability::CAPABILITY);
}
protected function buildCustomEditFields($object) {
return array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setDescription(pht('Name of the namespace.'))
->setTransactionType(AlmanacNamespaceNameTransaction::TRANSACTIONTYPE)
->setIsRequired(true)
->setValue($object->getName()),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacServiceEditEngine.php | src/applications/almanac/editor/AlmanacServiceEditEngine.php | <?php
final class AlmanacServiceEditEngine
extends PhabricatorEditEngine {
const ENGINECONST = 'almanac.service';
private $serviceType;
public function setServiceType($service_type) {
$this->serviceType = $service_type;
return $this;
}
public function getServiceType() {
return $this->serviceType;
}
public function isEngineConfigurable() {
return false;
}
public function getEngineName() {
return pht('Almanac Services');
}
public function getSummaryHeader() {
return pht('Edit Almanac Service Configurations');
}
public function getSummaryText() {
return pht('This engine is used to edit Almanac services.');
}
public function getEngineApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
protected function newEditableObject() {
$service_type = $this->getServiceType();
return AlmanacService::initializeNewService($service_type);
}
protected function newEditableObjectFromConduit(array $raw_xactions) {
$type = null;
foreach ($raw_xactions as $raw_xaction) {
if ($raw_xaction['type'] !== 'type') {
continue;
}
$type = $raw_xaction['value'];
}
if ($type === null) {
throw new Exception(
pht(
'When creating a new Almanac service via the Conduit API, you '.
'must provide a "type" transaction to select a type.'));
}
$map = AlmanacServiceType::getAllServiceTypes();
if (!isset($map[$type])) {
throw new Exception(
pht(
'Service type "%s" is unrecognized. Valid types are: %s.',
$type,
implode(', ', array_keys($map))));
}
$this->setServiceType($type);
return $this->newEditableObject();
}
protected function newEditableObjectForDocumentation() {
$service_type = new AlmanacCustomServiceType();
$this->setServiceType($service_type->getServiceTypeConstant());
return $this->newEditableObject();
}
protected function newObjectQuery() {
return id(new AlmanacServiceQuery())
->needProperties(true);
}
protected function getObjectCreateTitleText($object) {
return pht('Create Service');
}
protected function getObjectCreateButtonText($object) {
return pht('Create Service');
}
protected function getObjectEditTitleText($object) {
return pht('Edit Service: %s', $object->getName());
}
protected function getObjectEditShortText($object) {
return pht('Edit Service');
}
protected function getObjectCreateShortText() {
return pht('Create Service');
}
protected function getObjectName() {
return pht('Service');
}
protected function getEditorURI() {
return '/almanac/service/edit/';
}
protected function getObjectCreateCancelURI($object) {
return '/almanac/service/';
}
protected function getObjectViewURI($object) {
return $object->getURI();
}
protected function getCreateNewObjectPolicy() {
return $this->getApplication()->getPolicy(
AlmanacCreateServicesCapability::CAPABILITY);
}
protected function buildCustomEditFields($object) {
return array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setDescription(pht('Name of the service.'))
->setTransactionType(AlmanacServiceNameTransaction::TRANSACTIONTYPE)
->setIsRequired(true)
->setValue($object->getName()),
id(new PhabricatorTextEditField())
->setKey('type')
->setLabel(pht('Type'))
->setIsFormField(false)
->setTransactionType(
AlmanacServiceTypeTransaction::TRANSACTIONTYPE)
->setDescription(pht('When creating a service, set the type.'))
->setConduitDescription(pht('Set the service type.'))
->setConduitTypeDescription(pht('Service type.'))
->setValue($object->getServiceType()),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacPropertyEditEngine.php | src/applications/almanac/editor/AlmanacPropertyEditEngine.php | <?php
abstract class AlmanacPropertyEditEngine
extends PhabricatorEditEngine {
private $propertyKey;
public function setPropertyKey($property_key) {
$this->propertyKey = $property_key;
return $this;
}
public function getPropertyKey() {
return $this->propertyKey;
}
public function isEngineConfigurable() {
return false;
}
public function isEngineExtensible() {
return false;
}
public function getEngineName() {
return pht('Almanac Properties');
}
public function getSummaryHeader() {
return pht('Edit Almanac Property Configurations');
}
public function getSummaryText() {
return pht('This engine is used to edit Almanac properties.');
}
public function getEngineApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
protected function newEditableObject() {
throw new PhutilMethodNotImplementedException();
}
protected function getObjectCreateTitleText($object) {
return pht('Create Property');
}
protected function getObjectCreateButtonText($object) {
return pht('Create Property');
}
protected function getObjectEditTitleText($object) {
return pht('Edit Property: %s', $object->getName());
}
protected function getObjectEditShortText($object) {
return pht('Edit Property');
}
protected function getObjectCreateShortText() {
return pht('Create Property');
}
protected function buildCustomEditFields($object) {
$property_key = $this->getPropertyKey();
$xaction_type = $object->getAlmanacPropertySetTransactionType();
$specs = $object->getAlmanacPropertyFieldSpecifications();
if (isset($specs[$property_key])) {
$field_template = clone $specs[$property_key];
} else {
$field_template = new PhabricatorTextEditField();
}
return array(
$field_template
->setKey('value')
->setMetadataValue('almanac.property', $property_key)
->setLabel($property_key)
->setTransactionType($xaction_type)
->setValue($object->getAlmanacPropertyValue($property_key)),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacNetworkEditEngine.php | src/applications/almanac/editor/AlmanacNetworkEditEngine.php | <?php
final class AlmanacNetworkEditEngine
extends PhabricatorEditEngine {
const ENGINECONST = 'almanac.network';
public function isEngineConfigurable() {
return false;
}
public function getEngineName() {
return pht('Almanac Networks');
}
public function getSummaryHeader() {
return pht('Edit Almanac Network Configurations');
}
public function getSummaryText() {
return pht('This engine is used to edit Almanac networks.');
}
public function getEngineApplicationClass() {
return 'PhabricatorAlmanacApplication';
}
protected function newEditableObject() {
return AlmanacNetwork::initializeNewNetwork();
}
protected function newObjectQuery() {
return new AlmanacNetworkQuery();
}
protected function getObjectCreateTitleText($object) {
return pht('Create Network');
}
protected function getObjectCreateButtonText($object) {
return pht('Create Network');
}
protected function getObjectEditTitleText($object) {
return pht('Edit Network: %s', $object->getName());
}
protected function getObjectEditShortText($object) {
return pht('Edit Network');
}
protected function getObjectCreateShortText() {
return pht('Create Network');
}
protected function getObjectName() {
return pht('Network');
}
protected function getEditorURI() {
return '/almanac/network/edit/';
}
protected function getObjectCreateCancelURI($object) {
return '/almanac/network/';
}
protected function getObjectViewURI($object) {
$id = $object->getID();
return "/almanac/network/{$id}/";
}
protected function getCreateNewObjectPolicy() {
return $this->getApplication()->getPolicy(
AlmanacCreateNetworksCapability::CAPABILITY);
}
protected function buildCustomEditFields($object) {
return array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setDescription(pht('Name of the network.'))
->setTransactionType(AlmanacNetworkNameTransaction::TRANSACTIONTYPE)
->setIsRequired(true)
->setValue($object->getName()),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/editor/AlmanacInterfaceEditor.php | src/applications/almanac/editor/AlmanacInterfaceEditor.php | <?php
final class AlmanacInterfaceEditor
extends AlmanacEditor {
public function getEditorObjectsDescription() {
return pht('Almanac Interface');
}
public function getCreateObjectTitle($author, $object) {
return pht('%s created this interface.', $author);
}
public function getCreateObjectTitleForFeed($author, $object) {
return pht('%s created %s.', $author, $object);
}
protected function didCatchDuplicateKeyException(
PhabricatorLiskDAO $object,
array $xactions,
Exception $ex) {
$errors = array();
$errors[] = new PhabricatorApplicationTransactionValidationError(
null,
pht('Invalid'),
pht(
'Interfaces must have a unique combination of network, device, '.
'address, and port.'),
null);
throw new PhabricatorApplicationTransactionValidationException($errors);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacServiceSetPropertyTransaction.php | src/applications/almanac/xaction/AlmanacServiceSetPropertyTransaction.php | <?php
final class AlmanacServiceSetPropertyTransaction
extends AlmanacServiceTransactionType {
const TRANSACTIONTYPE = 'almanac:property:update';
public function generateOldValue($object) {
return $this->getAlmanacPropertyOldValue($object);
}
public function applyExternalEffects($object, $value) {
return $this->setAlmanacProperty($object, $value);
}
public function getTitle() {
return $this->getAlmanacSetPropertyTitle();
}
public function validateTransactions($object, array $xactions) {
return $this->validateAlmanacSetPropertyTransactions($object, $xactions);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacInterfaceDeviceTransaction.php | src/applications/almanac/xaction/AlmanacInterfaceDeviceTransaction.php | <?php
final class AlmanacInterfaceDeviceTransaction
extends AlmanacInterfaceTransactionType {
const TRANSACTIONTYPE = 'almanac:interface:device';
public function generateOldValue($object) {
return $object->getDevicePHID();
}
public function applyInternalEffects($object, $value) {
$object->setDevicePHID($value);
}
public function getTitle() {
return pht(
'%s changed the device for this interface from %s to %s.',
$this->renderAuthor(),
$this->renderOldHandle(),
$this->renderNewHandle());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
$device_phid = $object->getDevicePHID();
if ($this->isEmptyTextTransaction($device_phid, $xactions)) {
$errors[] = $this->newRequiredError(
pht('Interfaces must have a device.'));
}
foreach ($xactions as $xaction) {
if (!$this->isNewObject()) {
$errors[] = $this->newInvalidError(
pht(
'The device for an interface can not be changed once it has '.
'been created.'),
$xaction);
continue;
}
$device_phid = $xaction->getNewValue();
$devices = id(new AlmanacDeviceQuery())
->setViewer($this->getActor())
->withPHIDs(array($device_phid))
->execute();
if (!$devices) {
$errors[] = $this->newInvalidError(
pht(
'You can not attach an interface to a nonexistent or restricted '.
'device.'),
$xaction);
continue;
}
$device = head($devices);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$this->getActor(),
$device,
PhabricatorPolicyCapability::CAN_EDIT);
if (!$can_edit) {
$errors[] = $this->newInvalidError(
pht(
'You can not attach an interface to a device which you do not '.
'have permission to edit.'));
continue;
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacNamespaceNameTransaction.php | src/applications/almanac/xaction/AlmanacNamespaceNameTransaction.php | <?php
final class AlmanacNamespaceNameTransaction
extends AlmanacNamespaceTransactionType {
const TRANSACTIONTYPE = 'almanac:namespace:name';
public function generateOldValue($object) {
return $object->getName();
}
public function applyInternalEffects($object, $value) {
$object->setName($value);
}
public function getTitle() {
return pht(
'%s renamed this namespace from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function getTitleForFeed() {
return pht(
'%s renamed %s from %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('Namespace name is required.'));
}
foreach ($xactions as $xaction) {
$name = $xaction->getNewValue();
$message = null;
try {
AlmanacNames::validateName($name);
} catch (Exception $ex) {
$message = $ex->getMessage();
}
if ($message !== null) {
$errors[] = $this->newInvalidError($message, $xaction);
continue;
}
if ($name === $object->getName()) {
continue;
}
$other = id(new AlmanacNamespaceQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withNames(array($name))
->executeOne();
if ($other && ($other->getID() != $object->getID())) {
$errors[] = $this->newInvalidError(
pht(
'The namespace name "%s" is already in use by another '.
'namespace. Each namespace must have a unique name.',
$name),
$xaction);
continue;
}
$namespace = AlmanacNamespace::loadRestrictedNamespace(
$this->getActor(),
$name);
if ($namespace) {
$errors[] = $this->newInvalidError(
pht(
'You do not have permission to create Almanac namespaces '.
'within the "%s" namespace.',
$namespace->getName()),
$xaction);
continue;
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacInterfaceTransactionType.php | src/applications/almanac/xaction/AlmanacInterfaceTransactionType.php | <?php
abstract class AlmanacInterfaceTransactionType
extends AlmanacTransactionType {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacNetworkNameTransaction.php | src/applications/almanac/xaction/AlmanacNetworkNameTransaction.php | <?php
final class AlmanacNetworkNameTransaction
extends AlmanacNetworkTransactionType {
const TRANSACTIONTYPE = 'almanac:network:name';
public function generateOldValue($object) {
return $object->getName();
}
public function applyInternalEffects($object, $value) {
$object->setName($value);
}
public function getTitle() {
return pht(
'%s renamed this network from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function getTitleForFeed() {
return pht(
'%s renamed %s from %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('Network name is required.'));
}
foreach ($xactions as $xaction) {
$name = $xaction->getNewValue();
$message = null;
try {
AlmanacNames::validateName($name);
} catch (Exception $ex) {
$message = $ex->getMessage();
}
if ($message !== null) {
$errors[] = $this->newInvalidError($message, $xaction);
continue;
}
if ($name === $object->getName()) {
continue;
}
$other = id(new AlmanacNetworkQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withNames(array($name))
->executeOne();
if ($other && ($other->getID() != $object->getID())) {
$errors[] = $this->newInvalidError(
pht('Almanac networks must have unique names.'),
$xaction);
continue;
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacBindingTransactionType.php | src/applications/almanac/xaction/AlmanacBindingTransactionType.php | <?php
abstract class AlmanacBindingTransactionType
extends AlmanacTransactionType {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacServiceNameTransaction.php | src/applications/almanac/xaction/AlmanacServiceNameTransaction.php | <?php
final class AlmanacServiceNameTransaction
extends AlmanacServiceTransactionType {
const TRANSACTIONTYPE = 'almanac:service:name';
public function generateOldValue($object) {
return $object->getName();
}
public function applyInternalEffects($object, $value) {
$object->setName($value);
}
public function getTitle() {
return pht(
'%s renamed this service from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function getTitleForFeed() {
return pht(
'%s renamed %s from %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('Almanac services must have a name.'));
}
foreach ($xactions as $xaction) {
$name = $xaction->getNewValue();
$message = null;
try {
AlmanacNames::validateName($name);
} catch (Exception $ex) {
$message = $ex->getMessage();
}
if ($message !== null) {
$errors[] = $this->newInvalidError($message, $xaction);
continue;
}
if ($name === $object->getName()) {
continue;
}
$other = id(new AlmanacServiceQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withNames(array($name))
->executeOne();
if ($other && ($other->getID() != $object->getID())) {
$errors[] = $this->newInvalidError(
pht('Almanac services must have unique names.'),
$xaction);
continue;
}
$namespace = AlmanacNamespace::loadRestrictedNamespace(
$this->getActor(),
$name);
if ($namespace) {
$errors[] = $this->newInvalidError(
pht(
'You do not have permission to create Almanac services '.
'within the "%s" namespace.',
$namespace->getName()),
$xaction);
continue;
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacInterfaceDestroyTransaction.php | src/applications/almanac/xaction/AlmanacInterfaceDestroyTransaction.php | <?php
final class AlmanacInterfaceDestroyTransaction
extends AlmanacInterfaceTransactionType {
const TRANSACTIONTYPE = 'almanac:interface:destroy';
public function generateOldValue($object) {
return false;
}
public function applyExternalEffects($object, $value) {
id(new PhabricatorDestructionEngine())
->destroyObject($object);
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($xactions) {
if ($object->loadIsInUse()) {
$errors[] = $this->newInvalidError(
pht(
'You can not delete this interface because it is currently in '.
'use. One or more services are bound to it.'));
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacInterfaceAddressTransaction.php | src/applications/almanac/xaction/AlmanacInterfaceAddressTransaction.php | <?php
final class AlmanacInterfaceAddressTransaction
extends AlmanacInterfaceTransactionType {
const TRANSACTIONTYPE = 'almanac:interface:address';
public function generateOldValue($object) {
return $object->getAddress();
}
public function applyInternalEffects($object, $value) {
$object->setAddress($value);
}
public function getTitle() {
return pht(
'%s changed the address for this interface from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($this->isEmptyTextTransaction($object->getAddress(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('Interfaces must have an address.'));
}
foreach ($xactions as $xaction) {
// NOTE: For now, we don't validate addresses. We generally expect users
// to provide IPv4 addresses, but it's reasonable for them to provide
// IPv6 addresses, and some installs currently use DNS names. This is
// off-label but works today.
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacDeviceSetPropertyTransaction.php | src/applications/almanac/xaction/AlmanacDeviceSetPropertyTransaction.php | <?php
final class AlmanacDeviceSetPropertyTransaction
extends AlmanacDeviceTransactionType {
const TRANSACTIONTYPE = 'almanac:property:update';
public function generateOldValue($object) {
return $this->getAlmanacPropertyOldValue($object);
}
public function applyExternalEffects($object, $value) {
return $this->setAlmanacProperty($object, $value);
}
public function getTitle() {
return $this->getAlmanacSetPropertyTitle();
}
public function validateTransactions($object, array $xactions) {
return $this->validateAlmanacSetPropertyTransactions($object, $xactions);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacServiceTypeTransaction.php | src/applications/almanac/xaction/AlmanacServiceTypeTransaction.php | <?php
final class AlmanacServiceTypeTransaction
extends AlmanacServiceTransactionType {
const TRANSACTIONTYPE = 'almanac:service:type';
public function generateOldValue($object) {
return $object->getServiceType();
}
public function applyInternalEffects($object, $value) {
$object->setServiceType($value);
}
public function getTitle() {
// This transaction can only be applied during object creation via
// Conduit and never generates a timeline event.
return null;
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($this->isEmptyTextTransaction($object->getServiceType(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('You must select a service type when creating a service.'));
}
$map = AlmanacServiceType::getAllServiceTypes();
foreach ($xactions as $xaction) {
if (!$this->isNewObject()) {
$errors[] = $this->newInvalidError(
pht(
'The type of a service can not be changed once it has '.
'been created.'),
$xaction);
continue;
}
$new = $xaction->getNewValue();
if (!isset($map[$new])) {
$errors[] = $this->newInvalidError(
pht(
'Service type "%s" is not valid. Valid types are: %s.',
$new,
implode(', ', array_keys($map))));
continue;
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacServiceTransactionType.php | src/applications/almanac/xaction/AlmanacServiceTransactionType.php | <?php
abstract class AlmanacServiceTransactionType
extends AlmanacTransactionType {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacDeviceStatusTransaction.php | src/applications/almanac/xaction/AlmanacDeviceStatusTransaction.php | <?php
final class AlmanacDeviceStatusTransaction
extends AlmanacDeviceTransactionType {
const TRANSACTIONTYPE = 'almanac:device:status';
public function generateOldValue($object) {
return $object->getStatus();
}
public function applyInternalEffects($object, $value) {
$object->setStatus($value);
}
public function getTitle() {
$old_value = $this->getOldValue();
$new_value = $this->getNewValue();
$old_status = AlmanacDeviceStatus::newStatusFromValue($old_value);
$new_status = AlmanacDeviceStatus::newStatusFromValue($new_value);
$old_name = $old_status->getName();
$new_name = $new_status->getName();
return pht(
'%s changed the status of this device from %s to %s.',
$this->renderAuthor(),
$this->renderValue($old_name),
$this->renderValue($new_name));
}
public function validateTransactions($object, array $xactions) {
$errors = array();
$status_map = AlmanacDeviceStatus::getStatusMap();
$old_value = $this->generateOldValue($object);
foreach ($xactions as $xaction) {
$new_value = $xaction->getNewValue();
if ($new_value === $old_value) {
continue;
}
if (!isset($status_map[$new_value])) {
$errors[] = $this->newInvalidError(
pht(
'Almanac device status "%s" is unrecognized. Valid status '.
'values are: %s.',
$new_value,
implode(', ', array_keys($status_map))),
$xaction);
continue;
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacInterfaceNetworkTransaction.php | src/applications/almanac/xaction/AlmanacInterfaceNetworkTransaction.php | <?php
final class AlmanacInterfaceNetworkTransaction
extends AlmanacInterfaceTransactionType {
const TRANSACTIONTYPE = 'almanac:interface:network';
public function generateOldValue($object) {
return $object->getNetworkPHID();
}
public function applyInternalEffects($object, $value) {
$object->setNetworkPHID($value);
}
public function getTitle() {
return pht(
'%s changed the network for this interface from %s to %s.',
$this->renderAuthor(),
$this->renderOldHandle(),
$this->renderNewHandle());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
$network_phid = $object->getNetworkPHID();
if ($this->isEmptyTextTransaction($network_phid, $xactions)) {
$errors[] = $this->newRequiredError(
pht('Interfaces must have a network.'));
}
foreach ($xactions as $xaction) {
$network_phid = $xaction->getNewValue();
$networks = id(new AlmanacNetworkQuery())
->setViewer($this->getActor())
->withPHIDs(array($network_phid))
->execute();
if (!$networks) {
$errors[] = $this->newInvalidError(
pht(
'You can not put an interface on a nonexistent or restricted '.
'network.'),
$xaction);
continue;
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacBindingInterfaceTransaction.php | src/applications/almanac/xaction/AlmanacBindingInterfaceTransaction.php | <?php
final class AlmanacBindingInterfaceTransaction
extends AlmanacBindingTransactionType {
const TRANSACTIONTYPE = 'almanac:binding:interface';
public function generateOldValue($object) {
return $object->getInterfacePHID();
}
public function applyInternalEffects($object, $value) {
$interface = $this->loadInterface($value);
$object
->setDevicePHID($interface->getDevicePHID())
->setInterfacePHID($interface->getPHID());
}
public function applyExternalEffects($object, $value) {
// When we change which services a device is bound to, we need to
// recalculate whether it is a cluster device or not so we can tell if
// the "Can Manage Cluster Services" permission applies to it.
$viewer = PhabricatorUser::getOmnipotentUser();
$interface_phids = array();
$interface_phids[] = $this->getOldValue();
$interface_phids[] = $this->getNewValue();
$interface_phids = array_filter($interface_phids);
$interface_phids = array_unique($interface_phids);
$interfaces = id(new AlmanacInterfaceQuery())
->setViewer($viewer)
->withPHIDs($interface_phids)
->execute();
$device_phids = array();
foreach ($interfaces as $interface) {
$device_phids[] = $interface->getDevicePHID();
}
$device_phids = array_unique($device_phids);
$devices = id(new AlmanacDeviceQuery())
->setViewer($viewer)
->withPHIDs($device_phids)
->execute();
foreach ($devices as $device) {
$device->rebuildClusterBindingStatus();
}
}
public function getTitle() {
if ($this->getOldValue() === null) {
return pht(
'%s set the interface for this binding to %s.',
$this->renderAuthor(),
$this->renderNewHandle());
} else if ($this->getNewValue() == null) {
return pht(
'%s removed the interface for this binding.',
$this->renderAuthor());
} else {
return pht(
'%s changed the interface for this binding from %s to %s.',
$this->renderAuthor(),
$this->renderOldHandle(),
$this->renderNewHandle());
}
}
public function validateTransactions($object, array $xactions) {
$errors = array();
$interface_phid = $object->getInterfacePHID();
if ($this->isEmptyTextTransaction($interface_phid, $xactions)) {
$errors[] = $this->newRequiredError(
pht('Bindings must specify an interface.'));
}
foreach ($xactions as $xaction) {
$interface_phid = $xaction->getNewValue();
$interface = $this->loadInterface($interface_phid);
if (!$interface) {
$errors[] = $this->newInvalidError(
pht(
'You can not bind a service to an invalid or restricted '.
'interface.'),
$xaction);
continue;
}
$binding = id(new AlmanacBindingQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withServicePHIDs(array($object->getServicePHID()))
->withInterfacePHIDs(array($interface_phid))
->executeOne();
if ($binding && ($binding->getID() != $object->getID())) {
$errors[] = $this->newInvalidError(
pht(
'You can not bind a service to the same interface multiple '.
'times.'),
$xaction);
continue;
}
}
return $errors;
}
private function loadInterface($phid) {
return id(new AlmanacInterfaceQuery())
->setViewer($this->getActor())
->withPHIDs(array($phid))
->executeOne();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacServiceDeletePropertyTransaction.php | src/applications/almanac/xaction/AlmanacServiceDeletePropertyTransaction.php | <?php
final class AlmanacServiceDeletePropertyTransaction
extends AlmanacServiceTransactionType {
const TRANSACTIONTYPE = 'almanac:property:remove';
public function generateOldValue($object) {
return $this->getAlmanacPropertyOldValue($object);
}
public function applyInternalEffects($object, $value) {
return $this->deleteAlmanacProperty($object);
}
public function getTitle() {
return $this->getAlmanacDeletePropertyTitle();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacDeviceDeletePropertyTransaction.php | src/applications/almanac/xaction/AlmanacDeviceDeletePropertyTransaction.php | <?php
final class AlmanacDeviceDeletePropertyTransaction
extends AlmanacDeviceTransactionType {
const TRANSACTIONTYPE = 'almanac:property:remove';
public function generateOldValue($object) {
return $this->getAlmanacPropertyOldValue($object);
}
public function applyInternalEffects($object, $value) {
return $this->deleteAlmanacProperty($object);
}
public function getTitle() {
return $this->getAlmanacDeletePropertyTitle();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacDeviceNameTransaction.php | src/applications/almanac/xaction/AlmanacDeviceNameTransaction.php | <?php
final class AlmanacDeviceNameTransaction
extends AlmanacDeviceTransactionType {
const TRANSACTIONTYPE = 'almanac:device:name';
public function generateOldValue($object) {
return $object->getName();
}
public function applyInternalEffects($object, $value) {
$object->setName($value);
}
public function getTitle() {
return pht(
'%s renamed this device from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('Device name is required.'));
}
foreach ($xactions as $xaction) {
$name = $xaction->getNewValue();
$message = null;
try {
AlmanacNames::validateName($name);
} catch (Exception $ex) {
$message = $ex->getMessage();
}
if ($message !== null) {
$errors[] = $this->newInvalidError($message, $xaction);
continue;
}
if ($name === $object->getName()) {
continue;
}
$other = id(new AlmanacDeviceQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withNames(array($name))
->executeOne();
if ($other && ($other->getID() != $object->getID())) {
$errors[] = $this->newInvalidError(
pht('Almanac devices must have unique names.'),
$xaction);
continue;
}
$namespace = AlmanacNamespace::loadRestrictedNamespace(
$this->getActor(),
$name);
if ($namespace) {
$errors[] = $this->newInvalidError(
pht(
'You do not have permission to create Almanac devices '.
'within the "%s" namespace.',
$namespace->getName()),
$xaction);
continue;
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacBindingDisableTransaction.php | src/applications/almanac/xaction/AlmanacBindingDisableTransaction.php | <?php
final class AlmanacBindingDisableTransaction
extends AlmanacBindingTransactionType {
const TRANSACTIONTYPE = 'almanac:binding:disable';
public function generateOldValue($object) {
return (bool)$object->getIsDisabled();
}
public function applyInternalEffects($object, $value) {
$object->setIsDisabled((int)$value);
}
public function getTitle() {
if ($this->getNewValue()) {
return pht(
'%s disabled this binding.',
$this->renderAuthor());
} else {
return pht(
'%s enabled this binding.',
$this->renderAuthor());
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacNetworkTransactionType.php | src/applications/almanac/xaction/AlmanacNetworkTransactionType.php | <?php
abstract class AlmanacNetworkTransactionType
extends AlmanacTransactionType {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacNamespaceTransactionType.php | src/applications/almanac/xaction/AlmanacNamespaceTransactionType.php | <?php
abstract class AlmanacNamespaceTransactionType
extends AlmanacTransactionType {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacInterfacePortTransaction.php | src/applications/almanac/xaction/AlmanacInterfacePortTransaction.php | <?php
final class AlmanacInterfacePortTransaction
extends AlmanacInterfaceTransactionType {
const TRANSACTIONTYPE = 'almanac:interface:port';
public function generateOldValue($object) {
$port = $object->getPort();
if ($port !== null) {
$port = (int)$port;
}
return $port;
}
public function applyInternalEffects($object, $value) {
$object->setPort((int)$value);
}
public function getTitle() {
return pht(
'%s changed the port for this interface from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($this->isEmptyTextTransaction($object->getPort(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('Interfaces must have a port number.'));
}
foreach ($xactions as $xaction) {
$port = $xaction->getNewValue();
$port = (int)$port;
if ($port < 1 || $port > 65535) {
$errors[] = $this->newInvalidError(
pht('Port numbers must be between 1 and 65535, inclusive.'),
$xaction);
continue;
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacBindingServiceTransaction.php | src/applications/almanac/xaction/AlmanacBindingServiceTransaction.php | <?php
final class AlmanacBindingServiceTransaction
extends AlmanacBindingTransactionType {
const TRANSACTIONTYPE = 'almanac:binding:service';
public function generateOldValue($object) {
return $object->getServicePHID();
}
public function applyInternalEffects($object, $value) {
$object->setServicePHID($value);
}
public function validateTransactions($object, array $xactions) {
$errors = array();
$service_phid = $object->getServicePHID();
if ($this->isEmptyTextTransaction($service_phid, $xactions)) {
$errors[] = $this->newRequiredError(
pht('Bindings must have a service.'));
}
foreach ($xactions as $xaction) {
if (!$this->isNewObject()) {
$errors[] = $this->newInvalidError(
pht(
'The service for a binding can not be changed once it has '.
'been created.'),
$xaction);
continue;
}
$service_phid = $xaction->getNewValue();
$services = id(new AlmanacServiceQuery())
->setViewer($this->getActor())
->withPHIDs(array($service_phid))
->execute();
if (!$services) {
$errors[] = $this->newInvalidError(
pht('You can not bind a nonexistent or restricted service.'),
$xaction);
continue;
}
$service = head($services);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$this->getActor(),
$service,
PhabricatorPolicyCapability::CAN_EDIT);
if (!$can_edit) {
$errors[] = $this->newInvalidError(
pht(
'You can not bind a service which you do not have permission '.
'to edit.'));
continue;
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacDeviceTransactionType.php | src/applications/almanac/xaction/AlmanacDeviceTransactionType.php | <?php
abstract class AlmanacDeviceTransactionType
extends AlmanacTransactionType {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacTransactionType.php | src/applications/almanac/xaction/AlmanacTransactionType.php | <?php
abstract class AlmanacTransactionType
extends PhabricatorModularTransactionType {
protected function getAlmanacPropertyOldValue($object) {
$property_key = $this->getMetadataValue('almanac.property');
$exists = $object->hasAlmanacProperty($property_key);
$value = $object->getAlmanacPropertyValue($property_key);
return array(
'existed' => $exists,
'value' => $value,
);
}
protected function setAlmanacProperty($object, $value) {
$property_key = $this->getMetadataValue('almanac.property');
if ($object->hasAlmanacProperty($property_key)) {
$property = $object->getAlmanacProperty($property_key);
} else {
$property = id(new AlmanacProperty())
->setObjectPHID($object->getPHID())
->setFieldName($property_key);
}
$property
->setFieldValue($value)
->save();
}
protected function deleteAlmanacProperty($object) {
$property_key = $this->getMetadataValue('almanac.property');
if ($object->hasAlmanacProperty($property_key)) {
$property = $object->getAlmanacProperty($property_key);
$property->delete();
}
}
protected function getAlmanacSetPropertyTitle() {
$property_key = $this->getMetadataValue('almanac.property');
return pht(
'%s updated the property %s.',
$this->renderAuthor(),
$this->renderValue($property_key));
}
protected function getAlmanacDeletePropertyTitle() {
$property_key = $this->getMetadataValue('almanac.property');
return pht(
'%s removed the property %s.',
$this->renderAuthor(),
$this->renderValue($property_key));
}
protected function validateAlmanacSetPropertyTransactions(
$object,
array $xactions) {
$errors = array();
foreach ($xactions as $xaction) {
$property_key = $xaction->getMetadataValue('almanac.property');
$message = null;
try {
AlmanacNames::validateName($property_key);
} catch (Exception $ex) {
$message = $ex->getMessage();
}
if ($message !== null) {
$errors[] = $this->newInvalidError($message, $xaction);
continue;
}
$new_value = $xaction->getNewValue();
try {
phutil_json_encode($new_value);
} catch (Exception $ex) {
$message = pht(
'Almanac property values must be representable in JSON. %s',
$ex->getMessage());
}
if ($message !== null) {
$errors[] = $this->newInvalidError($message, $xaction);
continue;
}
}
return $errors;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacBindingDeletePropertyTransaction.php | src/applications/almanac/xaction/AlmanacBindingDeletePropertyTransaction.php | <?php
final class AlmanacBindingDeletePropertyTransaction
extends AlmanacBindingTransactionType {
const TRANSACTIONTYPE = 'almanac:property:remove';
public function generateOldValue($object) {
return $this->getAlmanacPropertyOldValue($object);
}
public function applyInternalEffects($object, $value) {
return $this->deleteAlmanacProperty($object);
}
public function getTitle() {
return $this->getAlmanacDeletePropertyTitle();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/xaction/AlmanacBindingSetPropertyTransaction.php | src/applications/almanac/xaction/AlmanacBindingSetPropertyTransaction.php | <?php
final class AlmanacBindingSetPropertyTransaction
extends AlmanacBindingTransactionType {
const TRANSACTIONTYPE = 'almanac:property:update';
public function generateOldValue($object) {
return $this->getAlmanacPropertyOldValue($object);
}
public function applyExternalEffects($object, $value) {
return $this->setAlmanacProperty($object, $value);
}
public function getTitle() {
return $this->getAlmanacSetPropertyTitle();
}
public function validateTransactions($object, array $xactions) {
return $this->validateAlmanacSetPropertyTransactions($object, $xactions);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/servicetype/AlmanacDrydockPoolServiceType.php | src/applications/almanac/servicetype/AlmanacDrydockPoolServiceType.php | <?php
final class AlmanacDrydockPoolServiceType extends AlmanacServiceType {
const SERVICETYPE = 'drydock.pool';
public function getServiceTypeShortName() {
return pht('Drydock Pool');
}
public function getServiceTypeName() {
return pht('Drydock: Resource Pool');
}
public function getServiceTypeDescription() {
return pht(
'Defines a pool of hosts which Drydock can allocate.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/servicetype/AlmanacClusterDatabaseServiceType.php | src/applications/almanac/servicetype/AlmanacClusterDatabaseServiceType.php | <?php
final class AlmanacClusterDatabaseServiceType
extends AlmanacClusterServiceType {
const SERVICETYPE = 'cluster.database';
public function getServiceTypeShortName() {
return pht('Cluster Database');
}
public function getServiceTypeName() {
return pht('Cluster: Database');
}
public function getServiceTypeDescription() {
return pht(
'Defines a database service for use in a cluster.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/servicetype/AlmanacCustomServiceType.php | src/applications/almanac/servicetype/AlmanacCustomServiceType.php | <?php
final class AlmanacCustomServiceType extends AlmanacServiceType {
const SERVICETYPE = 'almanac.custom';
public function getServiceTypeShortName() {
return pht('Custom');
}
public function getServiceTypeName() {
return pht('Custom Service');
}
public function getServiceTypeDescription() {
return pht('Defines a unstructured custom service.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/servicetype/AlmanacServiceType.php | src/applications/almanac/servicetype/AlmanacServiceType.php | <?php
abstract class AlmanacServiceType extends Phobject {
/**
* Return a very short human-readable name for this service type, like
* "Custom".
*
* @return string Very short human-readable service type name.
*/
abstract public function getServiceTypeShortName();
/**
* Return a short, human-readable name for this service type, like
* "Custom Service".
*
* @return string Human-readable name for this service type.
*/
abstract public function getServiceTypeName();
/**
* Return a brief summary of this service type.
*
* This summary should be a sentence or two long.
*
* @return string Brief, human-readable description of this service type.
*/
abstract public function getServiceTypeDescription();
final public function getServiceTypeConstant() {
return $this->getPhobjectClassConstant('SERVICETYPE', 64);
}
public function getServiceTypeIcon() {
return 'fa-cog';
}
/**
* Return `true` if this service type is a Phabricator cluster service type.
*
* These special services change the behavior of Phabricator, and require
* elevated permission to create and edit.
*
* @return bool True if this is a Phabricator cluster service type.
*/
public function isClusterServiceType() {
return false;
}
public function getDefaultPropertyMap() {
return array();
}
public function getFieldSpecifications() {
return array();
}
public function getBindingFieldSpecifications(AlmanacBinding $binding) {
return array();
}
/**
* List all available service type implementations.
*
* @return map<string, object> Dictionary of available service types.
*/
public static function getAllServiceTypes() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getServiceTypeConstant')
->setSortMethod('getServiceTypeName')
->execute();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/almanac/servicetype/AlmanacClusterServiceType.php | src/applications/almanac/servicetype/AlmanacClusterServiceType.php | <?php
abstract class AlmanacClusterServiceType
extends AlmanacServiceType {
public function isClusterServiceType() {
return true;
}
public function getServiceTypeIcon() {
return 'fa-sitemap';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.