mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-20 13:52:40 +01:00
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
This commit is contained in:
parent
2845d11962
commit
911aaee89c
7 changed files with 138 additions and 32 deletions
|
@ -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',
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorConfigPHIDTypeConfig extends PhabricatorPHIDType {
|
||||
|
||||
const TYPECONST = 'CONF';
|
||||
|
||||
public function getTypeConstant() {
|
||||
return self::TYPECONST;
|
||||
}
|
||||
|
||||
public function getTypeName() {
|
||||
return pht('Config');
|
||||
}
|
||||
|
||||
public function newObject() {
|
||||
return new PhabricatorConfigEntry();
|
||||
}
|
||||
|
||||
public function loadObjects(
|
||||
PhabricatorObjectQuery $query,
|
||||
array $phids) {
|
||||
|
||||
return id(new PhabricatorConfigEntryQuery())
|
||||
->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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorConfigEntryQuery
|
||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
private $phids;
|
||||
private $ids;
|
||||
|
||||
public function withIDs($ids) {
|
||||
$this->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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorConfigEntry extends PhabricatorConfigEntryDAO {
|
||||
final class PhabricatorConfigEntry extends PhabricatorConfigEntryDAO
|
||||
implements PhabricatorPolicyInterface {
|
||||
|
||||
protected $id;
|
||||
protected $phid;
|
||||
|
@ -20,7 +21,7 @@ final class PhabricatorConfigEntry extends PhabricatorConfigEntryDAO {
|
|||
|
||||
public function generatePHID() {
|
||||
return PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_CONF);
|
||||
PhabricatorConfigPHIDTypeConfig::TYPECONST);
|
||||
}
|
||||
|
||||
public static function loadConfigEntry($key) {
|
||||
|
@ -32,11 +33,30 @@ final class PhabricatorConfigEntry extends PhabricatorConfigEntryDAO {
|
|||
|
||||
if (!$config_entry) {
|
||||
$config_entry = id(new PhabricatorConfigEntry())
|
||||
->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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ final class PhabricatorConfigTransaction
|
|||
}
|
||||
|
||||
public function getApplicationTransactionType() {
|
||||
return PhabricatorPHIDConstants::PHID_TYPE_CONF;
|
||||
return PhabricatorConfigPHIDTypeConfig::TYPECONST;
|
||||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue