From 911aaee89ccd0a9ba323be696cedb99e0a588d9f Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 21 Jul 2013 15:04:21 -0700 Subject: [PATCH] Convert config to application PHIDs Summary: Ref T2715. Test Plan: Used `phid.query` to load config entries. Edited config entries. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2715 Differential Revision: https://secure.phabricator.com/D6520 --- src/__phutil_library_map__.php | 10 +++- .../phid/PhabricatorConfigPHIDTypeConfig.php | 48 ++++++++++++++++ .../query/PhabricatorConfigEntryQuery.php | 56 +++++++++++++++++++ .../config/storage/PhabricatorConfigEntry.php | 28 ++++++++-- .../storage/PhabricatorConfigTransaction.php | 2 +- .../phid/PhabricatorPHIDConstants.php | 1 - .../handle/PhabricatorObjectHandleData.php | 25 --------- 7 files changed, 138 insertions(+), 32 deletions(-) create mode 100644 src/applications/config/phid/PhabricatorConfigPHIDTypeConfig.php create mode 100644 src/applications/config/query/PhabricatorConfigEntryQuery.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index c63a3bd51d..fffe2cfac6 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -964,6 +964,7 @@ phutil_register_library_map(array( 'PhabricatorConfigEditor' => 'applications/config/editor/PhabricatorConfigEditor.php', 'PhabricatorConfigEntry' => 'applications/config/storage/PhabricatorConfigEntry.php', 'PhabricatorConfigEntryDAO' => 'applications/config/storage/PhabricatorConfigEntryDAO.php', + 'PhabricatorConfigEntryQuery' => 'applications/config/query/PhabricatorConfigEntryQuery.php', 'PhabricatorConfigFileSource' => 'infrastructure/env/PhabricatorConfigFileSource.php', 'PhabricatorConfigGroupController' => 'applications/config/controller/PhabricatorConfigGroupController.php', 'PhabricatorConfigIgnoreController' => 'applications/config/controller/PhabricatorConfigIgnoreController.php', @@ -979,6 +980,7 @@ phutil_register_library_map(array( 'PhabricatorConfigManagementWorkflow' => 'applications/config/management/PhabricatorConfigManagementWorkflow.php', 'PhabricatorConfigOption' => 'applications/config/option/PhabricatorConfigOption.php', 'PhabricatorConfigOptionType' => 'applications/config/custom/PhabricatorConfigOptionType.php', + 'PhabricatorConfigPHIDTypeConfig' => 'applications/config/phid/PhabricatorConfigPHIDTypeConfig.php', 'PhabricatorConfigProxySource' => 'infrastructure/env/PhabricatorConfigProxySource.php', 'PhabricatorConfigResponse' => 'applications/config/response/PhabricatorConfigResponse.php', 'PhabricatorConfigSource' => 'infrastructure/env/PhabricatorConfigSource.php', @@ -2944,8 +2946,13 @@ phutil_register_library_map(array( 'PhabricatorConfigDictionarySource' => 'PhabricatorConfigSource', 'PhabricatorConfigEditController' => 'PhabricatorConfigController', 'PhabricatorConfigEditor' => 'PhabricatorApplicationTransactionEditor', - 'PhabricatorConfigEntry' => 'PhabricatorConfigEntryDAO', + 'PhabricatorConfigEntry' => + array( + 0 => 'PhabricatorConfigEntryDAO', + 1 => 'PhabricatorPolicyInterface', + ), 'PhabricatorConfigEntryDAO' => 'PhabricatorLiskDAO', + 'PhabricatorConfigEntryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorConfigFileSource' => 'PhabricatorConfigProxySource', 'PhabricatorConfigGroupController' => 'PhabricatorConfigController', 'PhabricatorConfigIgnoreController' => 'PhabricatorApplicationsController', @@ -2963,6 +2970,7 @@ phutil_register_library_map(array( 0 => 'Phobject', 1 => 'PhabricatorMarkupInterface', ), + 'PhabricatorConfigPHIDTypeConfig' => 'PhabricatorPHIDType', 'PhabricatorConfigProxySource' => 'PhabricatorConfigSource', 'PhabricatorConfigResponse' => 'AphrontHTMLResponse', 'PhabricatorConfigStackSource' => 'PhabricatorConfigSource', diff --git a/src/applications/config/phid/PhabricatorConfigPHIDTypeConfig.php b/src/applications/config/phid/PhabricatorConfigPHIDTypeConfig.php new file mode 100644 index 0000000000..04234c27b4 --- /dev/null +++ b/src/applications/config/phid/PhabricatorConfigPHIDTypeConfig.php @@ -0,0 +1,48 @@ +setViewer($query->getViewer()) + ->withPHIDs($phids) + ->execute(); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $entry = $objects[$phid]; + + $key = $entry->getConfigKey(); + + $handle->setName($key); + $handle->setURI("/config/edit/{$key}/"); + } + } + + public function canLoadNamedObject($name) { + return false; + } + +} diff --git a/src/applications/config/query/PhabricatorConfigEntryQuery.php b/src/applications/config/query/PhabricatorConfigEntryQuery.php new file mode 100644 index 0000000000..1f4026b58c --- /dev/null +++ b/src/applications/config/query/PhabricatorConfigEntryQuery.php @@ -0,0 +1,56 @@ +ids = $ids; + return $this; + } + + public function withPHIDs($phids) { + $this->phids = $phids; + return $this; + } + + public function loadPage() { + $table = new PhabricatorConfigEntry(); + $conn_r = $table->establishConnection('r'); + + $data = queryfx_all( + $conn_r, + 'SELECT * FROM %T %Q %Q %Q', + $table->getTableName(), + $this->buildWhereClause($conn_r), + $this->buildOrderClause($conn_r), + $this->buildLimitClause($conn_r)); + + return $table->loadAllFromArray($data); + } + + private function buildWhereClause(AphrontDatabaseConnection $conn_r) { + $where = array(); + + if ($this->ids) { + $where[] = qsprintf( + $conn_r, + 'id IN (%Ld)', + $this->ids); + } + + if ($this->phids) { + $where[] = qsprintf( + $conn_r, + 'phid IN (%Ls)', + $this->phids); + } + + $where[] = $this->buildPagingClause($conn_r); + + return $this->formatWhereClause($where); + } + +} diff --git a/src/applications/config/storage/PhabricatorConfigEntry.php b/src/applications/config/storage/PhabricatorConfigEntry.php index bd5756af58..86d01a37df 100644 --- a/src/applications/config/storage/PhabricatorConfigEntry.php +++ b/src/applications/config/storage/PhabricatorConfigEntry.php @@ -1,6 +1,7 @@ setConfigKey($key) - ->setNamespace('default'); + ->setConfigKey($key) + ->setNamespace('default'); } return $config_entry; } + +/* -( PhabricatorPolicyInterface )----------------------------------------- */ + + + public function getCapabilities() { + return array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + ); + } + + public function getPolicy($capability) { + return PhabricatorPolicies::POLICY_ADMIN; + } + + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { + return false; + } + } diff --git a/src/applications/config/storage/PhabricatorConfigTransaction.php b/src/applications/config/storage/PhabricatorConfigTransaction.php index a8932f1ec5..ad03fb6b46 100644 --- a/src/applications/config/storage/PhabricatorConfigTransaction.php +++ b/src/applications/config/storage/PhabricatorConfigTransaction.php @@ -10,7 +10,7 @@ final class PhabricatorConfigTransaction } public function getApplicationTransactionType() { - return PhabricatorPHIDConstants::PHID_TYPE_CONF; + return PhabricatorConfigPHIDTypeConfig::TYPECONST; } public function getApplicationTransactionCommentObject() { diff --git a/src/applications/phid/PhabricatorPHIDConstants.php b/src/applications/phid/PhabricatorPHIDConstants.php index aa8fc4d4d4..24f9303733 100644 --- a/src/applications/phid/PhabricatorPHIDConstants.php +++ b/src/applications/phid/PhabricatorPHIDConstants.php @@ -25,7 +25,6 @@ final class PhabricatorPHIDConstants { const PHID_TYPE_ANSW = 'ANSW'; const PHID_TYPE_PIMG = 'PIMG'; const PHID_TYPE_MCRO = 'MCRO'; - const PHID_TYPE_CONF = 'CONF'; const PHID_TYPE_CONP = 'CONP'; const PHID_TYPE_PVAR = 'PVAR'; const PHID_TYPE_ACNT = 'ACNT'; diff --git a/src/applications/phid/handle/PhabricatorObjectHandleData.php b/src/applications/phid/handle/PhabricatorObjectHandleData.php index fa5f788552..51f152c919 100644 --- a/src/applications/phid/handle/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/PhabricatorObjectHandleData.php @@ -56,13 +56,6 @@ final class PhabricatorObjectHandleData { $phids); return mpull($users, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_CONF: - $config_dao = new PhabricatorConfigEntry(); - $entries = $config_dao->loadAllWhere( - 'phid IN (%Ls)', - $phids); - return mpull($entries, null, 'getPHID'); - case PhabricatorPHIDConstants::PHID_TYPE_FILE: // TODO: Update this to PhabricatorFileQuery $object = new PhabricatorFile(); @@ -302,24 +295,6 @@ final class PhabricatorObjectHandleData { } break; - case PhabricatorPHIDConstants::PHID_TYPE_CONF: - foreach ($phids as $phid) { - $handle = new PhabricatorObjectHandle(); - $handle->setPHID($phid); - $handle->setType($type); - if (empty($objects[$phid])) { - $handle->setName('Unknown Config Entry'); - } else { - $entry = $objects[$phid]; - $handle->setName($entry->getKey()); - $handle->setURI('/config/edit/'.$entry->getKey()); - $handle->setFullName($entry->getKey()); - $handle->setComplete(true); - } - $handles[$phid] = $handle; - } - break; - case PhabricatorPHIDConstants::PHID_TYPE_FILE: foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle();