mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Modularize Almanac property transactions
Summary: Depends on D19329. Ref T13120. Ref T12414. Recent changes have mostly modularized Almanac transactions, but the "property" transactions remained written in an older style with the logic on the Editor/Transaction classes. This moves them to modern modular transactions. These end up being a little bit copy-pastey, but it doesn't feel too terribly bad. Test Plan: Created, edited, and deleted properties on services, devices and bindings. Grepped for removed constants. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13120, T12414 Differential Revision: https://secure.phabricator.com/D19334
This commit is contained in:
parent
71c77fcc3a
commit
4bce3fc8e6
30 changed files with 332 additions and 273 deletions
|
@ -12,6 +12,7 @@ phutil_register_library_map(array(
|
|||
'AlamancServiceEditConduitAPIMethod' => 'applications/almanac/conduit/AlamancServiceEditConduitAPIMethod.php',
|
||||
'AlmanacAddress' => 'applications/almanac/util/AlmanacAddress.php',
|
||||
'AlmanacBinding' => 'applications/almanac/storage/AlmanacBinding.php',
|
||||
'AlmanacBindingDeletePropertyTransaction' => 'applications/almanac/xaction/AlmanacBindingDeletePropertyTransaction.php',
|
||||
'AlmanacBindingDisableController' => 'applications/almanac/controller/AlmanacBindingDisableController.php',
|
||||
'AlmanacBindingDisableTransaction' => 'applications/almanac/xaction/AlmanacBindingDisableTransaction.php',
|
||||
'AlmanacBindingEditController' => 'applications/almanac/controller/AlmanacBindingEditController.php',
|
||||
|
@ -20,6 +21,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacBindingPHIDType' => 'applications/almanac/phid/AlmanacBindingPHIDType.php',
|
||||
'AlmanacBindingPropertyEditEngine' => 'applications/almanac/editor/AlmanacBindingPropertyEditEngine.php',
|
||||
'AlmanacBindingQuery' => 'applications/almanac/query/AlmanacBindingQuery.php',
|
||||
'AlmanacBindingSetPropertyTransaction' => 'applications/almanac/xaction/AlmanacBindingSetPropertyTransaction.php',
|
||||
'AlmanacBindingTableView' => 'applications/almanac/view/AlmanacBindingTableView.php',
|
||||
'AlmanacBindingTransaction' => 'applications/almanac/storage/AlmanacBindingTransaction.php',
|
||||
'AlmanacBindingTransactionQuery' => 'applications/almanac/query/AlmanacBindingTransactionQuery.php',
|
||||
|
@ -40,6 +42,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacDAO' => 'applications/almanac/storage/AlmanacDAO.php',
|
||||
'AlmanacDevice' => 'applications/almanac/storage/AlmanacDevice.php',
|
||||
'AlmanacDeviceController' => 'applications/almanac/controller/AlmanacDeviceController.php',
|
||||
'AlmanacDeviceDeletePropertyTransaction' => 'applications/almanac/xaction/AlmanacDeviceDeletePropertyTransaction.php',
|
||||
'AlmanacDeviceEditConduitAPIMethod' => 'applications/almanac/conduit/AlmanacDeviceEditConduitAPIMethod.php',
|
||||
'AlmanacDeviceEditController' => 'applications/almanac/controller/AlmanacDeviceEditController.php',
|
||||
'AlmanacDeviceEditEngine' => 'applications/almanac/editor/AlmanacDeviceEditEngine.php',
|
||||
|
@ -52,6 +55,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacDeviceQuery' => 'applications/almanac/query/AlmanacDeviceQuery.php',
|
||||
'AlmanacDeviceSearchConduitAPIMethod' => 'applications/almanac/conduit/AlmanacDeviceSearchConduitAPIMethod.php',
|
||||
'AlmanacDeviceSearchEngine' => 'applications/almanac/query/AlmanacDeviceSearchEngine.php',
|
||||
'AlmanacDeviceSetPropertyTransaction' => 'applications/almanac/xaction/AlmanacDeviceSetPropertyTransaction.php',
|
||||
'AlmanacDeviceTransaction' => 'applications/almanac/storage/AlmanacDeviceTransaction.php',
|
||||
'AlmanacDeviceTransactionQuery' => 'applications/almanac/query/AlmanacDeviceTransactionQuery.php',
|
||||
'AlmanacDeviceTransactionType' => 'applications/almanac/xaction/AlmanacDeviceTransactionType.php',
|
||||
|
@ -80,6 +84,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacManagementTrustKeyWorkflow' => 'applications/almanac/management/AlmanacManagementTrustKeyWorkflow.php',
|
||||
'AlmanacManagementUntrustKeyWorkflow' => 'applications/almanac/management/AlmanacManagementUntrustKeyWorkflow.php',
|
||||
'AlmanacManagementWorkflow' => 'applications/almanac/management/AlmanacManagementWorkflow.php',
|
||||
'AlmanacModularTransaction' => 'applications/almanac/storage/AlmanacModularTransaction.php',
|
||||
'AlmanacNames' => 'applications/almanac/util/AlmanacNames.php',
|
||||
'AlmanacNamesTestCase' => 'applications/almanac/util/__tests__/AlmanacNamesTestCase.php',
|
||||
'AlmanacNamespace' => 'applications/almanac/storage/AlmanacNamespace.php',
|
||||
|
@ -127,6 +132,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacService' => 'applications/almanac/storage/AlmanacService.php',
|
||||
'AlmanacServiceController' => 'applications/almanac/controller/AlmanacServiceController.php',
|
||||
'AlmanacServiceDatasource' => 'applications/almanac/typeahead/AlmanacServiceDatasource.php',
|
||||
'AlmanacServiceDeletePropertyTransaction' => 'applications/almanac/xaction/AlmanacServiceDeletePropertyTransaction.php',
|
||||
'AlmanacServiceEditController' => 'applications/almanac/controller/AlmanacServiceEditController.php',
|
||||
'AlmanacServiceEditEngine' => 'applications/almanac/editor/AlmanacServiceEditEngine.php',
|
||||
'AlmanacServiceEditor' => 'applications/almanac/editor/AlmanacServiceEditor.php',
|
||||
|
@ -138,6 +144,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacServiceQuery' => 'applications/almanac/query/AlmanacServiceQuery.php',
|
||||
'AlmanacServiceSearchConduitAPIMethod' => 'applications/almanac/conduit/AlmanacServiceSearchConduitAPIMethod.php',
|
||||
'AlmanacServiceSearchEngine' => 'applications/almanac/query/AlmanacServiceSearchEngine.php',
|
||||
'AlmanacServiceSetPropertyTransaction' => 'applications/almanac/xaction/AlmanacServiceSetPropertyTransaction.php',
|
||||
'AlmanacServiceTransaction' => 'applications/almanac/storage/AlmanacServiceTransaction.php',
|
||||
'AlmanacServiceTransactionQuery' => 'applications/almanac/query/AlmanacServiceTransactionQuery.php',
|
||||
'AlmanacServiceTransactionType' => 'applications/almanac/xaction/AlmanacServiceTransactionType.php',
|
||||
|
@ -146,7 +153,6 @@ phutil_register_library_map(array(
|
|||
'AlmanacServiceTypeTestCase' => 'applications/almanac/servicetype/__tests__/AlmanacServiceTypeTestCase.php',
|
||||
'AlmanacServiceTypeTransaction' => 'applications/almanac/xaction/AlmanacServiceTypeTransaction.php',
|
||||
'AlmanacServiceViewController' => 'applications/almanac/controller/AlmanacServiceViewController.php',
|
||||
'AlmanacTransaction' => 'applications/almanac/storage/AlmanacTransaction.php',
|
||||
'AlmanacTransactionType' => 'applications/almanac/xaction/AlmanacTransactionType.php',
|
||||
'AphlictDropdownDataQuery' => 'applications/aphlict/query/AphlictDropdownDataQuery.php',
|
||||
'Aphront304Response' => 'aphront/response/Aphront304Response.php',
|
||||
|
@ -5194,6 +5200,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDestructibleInterface',
|
||||
'PhabricatorExtendedPolicyInterface',
|
||||
),
|
||||
'AlmanacBindingDeletePropertyTransaction' => 'AlmanacBindingTransactionType',
|
||||
'AlmanacBindingDisableController' => 'AlmanacServiceController',
|
||||
'AlmanacBindingDisableTransaction' => 'AlmanacBindingTransactionType',
|
||||
'AlmanacBindingEditController' => 'AlmanacServiceController',
|
||||
|
@ -5202,8 +5209,9 @@ phutil_register_library_map(array(
|
|||
'AlmanacBindingPHIDType' => 'PhabricatorPHIDType',
|
||||
'AlmanacBindingPropertyEditEngine' => 'AlmanacPropertyEditEngine',
|
||||
'AlmanacBindingQuery' => 'AlmanacQuery',
|
||||
'AlmanacBindingSetPropertyTransaction' => 'AlmanacBindingTransactionType',
|
||||
'AlmanacBindingTableView' => 'AphrontView',
|
||||
'AlmanacBindingTransaction' => 'PhabricatorModularTransaction',
|
||||
'AlmanacBindingTransaction' => 'AlmanacModularTransaction',
|
||||
'AlmanacBindingTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'AlmanacBindingTransactionType' => 'AlmanacTransactionType',
|
||||
'AlmanacBindingViewController' => 'AlmanacServiceController',
|
||||
|
@ -5233,6 +5241,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorExtendedPolicyInterface',
|
||||
),
|
||||
'AlmanacDeviceController' => 'AlmanacController',
|
||||
'AlmanacDeviceDeletePropertyTransaction' => 'AlmanacDeviceTransactionType',
|
||||
'AlmanacDeviceEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
|
||||
'AlmanacDeviceEditController' => 'AlmanacDeviceController',
|
||||
'AlmanacDeviceEditEngine' => 'PhabricatorEditEngine',
|
||||
|
@ -5245,7 +5254,8 @@ phutil_register_library_map(array(
|
|||
'AlmanacDeviceQuery' => 'AlmanacQuery',
|
||||
'AlmanacDeviceSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
||||
'AlmanacDeviceSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'AlmanacDeviceTransaction' => 'PhabricatorModularTransaction',
|
||||
'AlmanacDeviceSetPropertyTransaction' => 'AlmanacDeviceTransactionType',
|
||||
'AlmanacDeviceTransaction' => 'AlmanacModularTransaction',
|
||||
'AlmanacDeviceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'AlmanacDeviceTransactionType' => 'AlmanacTransactionType',
|
||||
'AlmanacDeviceViewController' => 'AlmanacDeviceController',
|
||||
|
@ -5265,13 +5275,13 @@ phutil_register_library_map(array(
|
|||
'AlmanacInterfaceDeviceTransaction' => 'AlmanacInterfaceTransactionType',
|
||||
'AlmanacInterfaceEditController' => 'AlmanacDeviceController',
|
||||
'AlmanacInterfaceEditEngine' => 'PhabricatorEditEngine',
|
||||
'AlmanacInterfaceEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'AlmanacInterfaceEditor' => 'AlmanacEditor',
|
||||
'AlmanacInterfaceNetworkTransaction' => 'AlmanacInterfaceTransactionType',
|
||||
'AlmanacInterfacePHIDType' => 'PhabricatorPHIDType',
|
||||
'AlmanacInterfacePortTransaction' => 'AlmanacInterfaceTransactionType',
|
||||
'AlmanacInterfaceQuery' => 'AlmanacQuery',
|
||||
'AlmanacInterfaceTableView' => 'AphrontView',
|
||||
'AlmanacInterfaceTransaction' => 'PhabricatorModularTransaction',
|
||||
'AlmanacInterfaceTransaction' => 'AlmanacModularTransaction',
|
||||
'AlmanacInterfaceTransactionType' => 'AlmanacTransactionType',
|
||||
'AlmanacKeys' => 'Phobject',
|
||||
'AlmanacManageClusterServicesCapability' => 'PhabricatorPolicyCapability',
|
||||
|
@ -5279,6 +5289,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacManagementTrustKeyWorkflow' => 'AlmanacManagementWorkflow',
|
||||
'AlmanacManagementUntrustKeyWorkflow' => 'AlmanacManagementWorkflow',
|
||||
'AlmanacManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||
'AlmanacModularTransaction' => 'PhabricatorModularTransaction',
|
||||
'AlmanacNames' => 'Phobject',
|
||||
'AlmanacNamesTestCase' => 'PhabricatorTestCase',
|
||||
'AlmanacNamespace' => array(
|
||||
|
@ -5293,14 +5304,14 @@ phutil_register_library_map(array(
|
|||
'AlmanacNamespaceController' => 'AlmanacController',
|
||||
'AlmanacNamespaceEditController' => 'AlmanacNamespaceController',
|
||||
'AlmanacNamespaceEditEngine' => 'PhabricatorEditEngine',
|
||||
'AlmanacNamespaceEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'AlmanacNamespaceEditor' => 'AlmanacEditor',
|
||||
'AlmanacNamespaceListController' => 'AlmanacNamespaceController',
|
||||
'AlmanacNamespaceNameNgrams' => 'PhabricatorSearchNgrams',
|
||||
'AlmanacNamespaceNameTransaction' => 'AlmanacNamespaceTransactionType',
|
||||
'AlmanacNamespacePHIDType' => 'PhabricatorPHIDType',
|
||||
'AlmanacNamespaceQuery' => 'AlmanacQuery',
|
||||
'AlmanacNamespaceSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'AlmanacNamespaceTransaction' => 'PhabricatorModularTransaction',
|
||||
'AlmanacNamespaceTransaction' => 'AlmanacModularTransaction',
|
||||
'AlmanacNamespaceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'AlmanacNamespaceTransactionType' => 'AlmanacTransactionType',
|
||||
'AlmanacNamespaceViewController' => 'AlmanacNamespaceController',
|
||||
|
@ -5314,14 +5325,14 @@ phutil_register_library_map(array(
|
|||
'AlmanacNetworkController' => 'AlmanacController',
|
||||
'AlmanacNetworkEditController' => 'AlmanacNetworkController',
|
||||
'AlmanacNetworkEditEngine' => 'PhabricatorEditEngine',
|
||||
'AlmanacNetworkEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'AlmanacNetworkEditor' => 'AlmanacEditor',
|
||||
'AlmanacNetworkListController' => 'AlmanacNetworkController',
|
||||
'AlmanacNetworkNameNgrams' => 'PhabricatorSearchNgrams',
|
||||
'AlmanacNetworkNameTransaction' => 'AlmanacNetworkTransactionType',
|
||||
'AlmanacNetworkPHIDType' => 'PhabricatorPHIDType',
|
||||
'AlmanacNetworkQuery' => 'AlmanacQuery',
|
||||
'AlmanacNetworkSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'AlmanacNetworkTransaction' => 'PhabricatorModularTransaction',
|
||||
'AlmanacNetworkTransaction' => 'AlmanacModularTransaction',
|
||||
'AlmanacNetworkTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'AlmanacNetworkTransactionType' => 'AlmanacTransactionType',
|
||||
'AlmanacNetworkViewController' => 'AlmanacNetworkController',
|
||||
|
@ -5352,6 +5363,7 @@ phutil_register_library_map(array(
|
|||
),
|
||||
'AlmanacServiceController' => 'AlmanacController',
|
||||
'AlmanacServiceDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'AlmanacServiceDeletePropertyTransaction' => 'AlmanacServiceTransactionType',
|
||||
'AlmanacServiceEditController' => 'AlmanacServiceController',
|
||||
'AlmanacServiceEditEngine' => 'PhabricatorEditEngine',
|
||||
'AlmanacServiceEditor' => 'AlmanacEditor',
|
||||
|
@ -5363,7 +5375,8 @@ phutil_register_library_map(array(
|
|||
'AlmanacServiceQuery' => 'AlmanacQuery',
|
||||
'AlmanacServiceSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
||||
'AlmanacServiceSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'AlmanacServiceTransaction' => 'PhabricatorModularTransaction',
|
||||
'AlmanacServiceSetPropertyTransaction' => 'AlmanacServiceTransactionType',
|
||||
'AlmanacServiceTransaction' => 'AlmanacModularTransaction',
|
||||
'AlmanacServiceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'AlmanacServiceTransactionType' => 'AlmanacTransactionType',
|
||||
'AlmanacServiceType' => 'Phobject',
|
||||
|
@ -5371,7 +5384,6 @@ phutil_register_library_map(array(
|
|||
'AlmanacServiceTypeTestCase' => 'PhabricatorTestCase',
|
||||
'AlmanacServiceTypeTransaction' => 'AlmanacServiceTransactionType',
|
||||
'AlmanacServiceViewController' => 'AlmanacServiceController',
|
||||
'AlmanacTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'AlmanacTransactionType' => 'PhabricatorModularTransactionType',
|
||||
'AphlictDropdownDataQuery' => 'Phobject',
|
||||
'Aphront304Response' => 'AphrontResponse',
|
||||
|
|
|
@ -39,8 +39,10 @@ final class AlmanacPropertyDeleteController
|
|||
|
||||
$validation_exception = null;
|
||||
if ($request->isFormPost()) {
|
||||
$xaction_type = $object->getAlmanacPropertyDeleteTransactionType();
|
||||
|
||||
$xaction = $object->getApplicationTransactionTemplate()
|
||||
->setTransactionType(AlmanacTransaction::TYPE_PROPERTY_REMOVE)
|
||||
->setTransactionType($xaction_type)
|
||||
->setMetadataValue('almanac.property', $key);
|
||||
|
||||
$editor = $object->getApplicationTransactionEditor()
|
||||
|
|
|
@ -15,4 +15,8 @@ final class AlmanacBindingEditor
|
|||
return pht('%s created %s.', $author, $object);
|
||||
}
|
||||
|
||||
protected function supportsSearch() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,18 @@ final class AlmanacDeviceEditor
|
|||
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();
|
||||
|
||||
|
|
|
@ -7,150 +7,4 @@ abstract class AlmanacEditor
|
|||
return 'PhabricatorAlmanacApplication';
|
||||
}
|
||||
|
||||
protected function supportsSearch() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getTransactionTypes() {
|
||||
$types = parent::getTransactionTypes();
|
||||
|
||||
$types[] = AlmanacTransaction::TYPE_PROPERTY_UPDATE;
|
||||
$types[] = AlmanacTransaction::TYPE_PROPERTY_REMOVE;
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
protected function getCustomTransactionOldValue(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case AlmanacTransaction::TYPE_PROPERTY_UPDATE:
|
||||
case AlmanacTransaction::TYPE_PROPERTY_REMOVE:
|
||||
$property_key = $xaction->getMetadataValue('almanac.property');
|
||||
$exists = $object->hasAlmanacProperty($property_key);
|
||||
$value = $object->getAlmanacPropertyValue($property_key);
|
||||
return array(
|
||||
'existed' => $exists,
|
||||
'value' => $value,
|
||||
);
|
||||
}
|
||||
|
||||
return parent::getCustomTransactionOldValue($object, $xaction);
|
||||
}
|
||||
|
||||
protected function getCustomTransactionNewValue(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case AlmanacTransaction::TYPE_PROPERTY_UPDATE:
|
||||
case AlmanacTransaction::TYPE_PROPERTY_REMOVE:
|
||||
return $xaction->getNewValue();
|
||||
}
|
||||
|
||||
return parent::getCustomTransactionNewValue($object, $xaction);
|
||||
}
|
||||
|
||||
protected function applyCustomInternalTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case AlmanacTransaction::TYPE_PROPERTY_UPDATE:
|
||||
case AlmanacTransaction::TYPE_PROPERTY_REMOVE:
|
||||
return;
|
||||
}
|
||||
|
||||
return parent::applyCustomInternalTransaction($object, $xaction);
|
||||
}
|
||||
|
||||
protected function applyCustomExternalTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case AlmanacTransaction::TYPE_PROPERTY_UPDATE:
|
||||
$property_key = $xaction->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($xaction->getNewValue())
|
||||
->save();
|
||||
return;
|
||||
case AlmanacTransaction::TYPE_PROPERTY_REMOVE:
|
||||
$property_key = $xaction->getMetadataValue('almanac.property');
|
||||
if ($object->hasAlmanacProperty($property_key)) {
|
||||
$property = $object->getAlmanacProperty($property_key);
|
||||
$property->delete();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
return parent::applyCustomExternalTransaction($object, $xaction);
|
||||
}
|
||||
|
||||
protected function validateTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
$type,
|
||||
array $xactions) {
|
||||
|
||||
$errors = parent::validateTransaction($object, $type, $xactions);
|
||||
|
||||
switch ($type) {
|
||||
case AlmanacTransaction::TYPE_PROPERTY_UPDATE:
|
||||
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) {
|
||||
$error = new PhabricatorApplicationTransactionValidationError(
|
||||
$type,
|
||||
pht('Invalid'),
|
||||
$message,
|
||||
$xaction);
|
||||
$errors[] = $error;
|
||||
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) {
|
||||
$error = new PhabricatorApplicationTransactionValidationError(
|
||||
$type,
|
||||
pht('Invalid'),
|
||||
$message,
|
||||
$xaction);
|
||||
$errors[] = $error;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AlmanacTransaction::TYPE_PROPERTY_REMOVE:
|
||||
// NOTE: No name validation on removals since it's OK to delete
|
||||
// an invalid property that somehow came into existence.
|
||||
break;
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class AlmanacInterfaceEditor
|
||||
extends PhabricatorApplicationTransactionEditor {
|
||||
|
||||
public function getEditorApplicationClass() {
|
||||
return 'PhabricatorAlmanacApplication';
|
||||
}
|
||||
extends AlmanacEditor {
|
||||
|
||||
public function getEditorObjectsDescription() {
|
||||
return pht('Almanac Interface');
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class AlmanacNamespaceEditor
|
||||
extends PhabricatorApplicationTransactionEditor {
|
||||
|
||||
public function getEditorApplicationClass() {
|
||||
return 'PhabricatorAlmanacApplication';
|
||||
}
|
||||
extends AlmanacEditor {
|
||||
|
||||
public function getEditorObjectsDescription() {
|
||||
return pht('Almanac Namespace');
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class AlmanacNetworkEditor
|
||||
extends PhabricatorApplicationTransactionEditor {
|
||||
|
||||
public function getEditorApplicationClass() {
|
||||
return 'PhabricatorAlmanacApplication';
|
||||
}
|
||||
extends AlmanacEditor {
|
||||
|
||||
public function getEditorObjectsDescription() {
|
||||
return pht('Almanac Network');
|
||||
}
|
||||
|
||||
protected function supportsSearch() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getCreateObjectTitle($author, $object) {
|
||||
return pht('%s created this network.', $author);
|
||||
}
|
||||
|
@ -23,6 +15,10 @@ final class AlmanacNetworkEditor
|
|||
return pht('%s created %s.', $author, $object);
|
||||
}
|
||||
|
||||
protected function supportsSearch() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getTransactionTypes() {
|
||||
$types = parent::getTransactionTypes();
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ abstract class AlmanacPropertyEditEngine
|
|||
|
||||
protected function buildCustomEditFields($object) {
|
||||
$property_key = $this->getPropertyKey();
|
||||
$xaction_type = AlmanacTransaction::TYPE_PROPERTY_UPDATE;
|
||||
$xaction_type = $object->getAlmanacPropertySetTransactionType();
|
||||
|
||||
return array(
|
||||
id(new PhabricatorTextEditField())
|
||||
|
|
|
@ -9,5 +9,7 @@ interface AlmanacPropertyInterface {
|
|||
public function getAlmanacPropertyValue($key, $default = null);
|
||||
public function getAlmanacPropertyFieldSpecifications();
|
||||
public function newAlmanacPropertyEditEngine();
|
||||
public function getAlmanacPropertySetTransactionType();
|
||||
public function getAlmanacPropertyDeleteTransactionType();
|
||||
|
||||
}
|
||||
|
|
|
@ -134,6 +134,14 @@ final class AlmanacBinding
|
|||
return new AlmanacBindingPropertyEditEngine();
|
||||
}
|
||||
|
||||
public function getAlmanacPropertySetTransactionType() {
|
||||
return AlmanacBindingSetPropertyTransaction::TRANSACTIONTYPE;
|
||||
}
|
||||
|
||||
public function getAlmanacPropertyDeleteTransactionType() {
|
||||
return AlmanacBindingDeletePropertyTransaction::TRANSACTIONTYPE;
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class AlmanacBindingTransaction
|
||||
extends PhabricatorModularTransaction {
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'almanac';
|
||||
}
|
||||
extends AlmanacModularTransaction {
|
||||
|
||||
public function getApplicationTransactionType() {
|
||||
return AlmanacBindingPHIDType::TYPECONST;
|
||||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getBaseTransactionClass() {
|
||||
return 'AlmanacBindingTransactionType';
|
||||
}
|
||||
|
|
|
@ -143,6 +143,14 @@ final class AlmanacDevice
|
|||
return new AlmanacDevicePropertyEditEngine();
|
||||
}
|
||||
|
||||
public function getAlmanacPropertySetTransactionType() {
|
||||
return AlmanacDeviceSetPropertyTransaction::TRANSACTIONTYPE;
|
||||
}
|
||||
|
||||
public function getAlmanacPropertyDeleteTransactionType() {
|
||||
return AlmanacDeviceDeletePropertyTransaction::TRANSACTIONTYPE;
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class AlmanacDeviceTransaction
|
||||
extends PhabricatorModularTransaction {
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'almanac';
|
||||
}
|
||||
extends AlmanacModularTransaction {
|
||||
|
||||
public function getApplicationTransactionType() {
|
||||
return AlmanacDevicePHIDType::TYPECONST;
|
||||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getBaseTransactionClass() {
|
||||
return 'AlmanacDeviceTransactionType';
|
||||
}
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class AlmanacInterfaceTransaction
|
||||
extends PhabricatorModularTransaction {
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'almanac';
|
||||
}
|
||||
extends AlmanacModularTransaction {
|
||||
|
||||
public function getApplicationTransactionType() {
|
||||
return AlmanacInterfacePHIDType::TYPECONST;
|
||||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getBaseTransactionClass() {
|
||||
return 'AlmanacInterfaceTransactionType';
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
abstract class AlmanacModularTransaction
|
||||
extends PhabricatorModularTransaction {
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'almanac';
|
||||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -150,6 +150,14 @@ final class AlmanacNamespace
|
|||
throw new PhutilMethodNotImplementedException();
|
||||
}
|
||||
|
||||
public function getAlmanacPropertySetTransactionType() {
|
||||
throw new PhutilMethodNotImplementedException();
|
||||
}
|
||||
|
||||
public function getAlmanacPropertyDeleteTransactionType() {
|
||||
throw new PhutilMethodNotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class AlmanacNamespaceTransaction
|
||||
extends PhabricatorModularTransaction {
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'almanac';
|
||||
}
|
||||
extends AlmanacModularTransaction {
|
||||
|
||||
public function getApplicationTransactionType() {
|
||||
return AlmanacNamespacePHIDType::TYPECONST;
|
||||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getBaseTransactionClass() {
|
||||
return 'AlmanacNamespaceTransactionType';
|
||||
}
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class AlmanacNetworkTransaction
|
||||
extends PhabricatorModularTransaction {
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'almanac';
|
||||
}
|
||||
extends AlmanacModularTransaction {
|
||||
|
||||
public function getApplicationTransactionType() {
|
||||
return AlmanacNetworkPHIDType::TYPECONST;
|
||||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getBaseTransactionClass() {
|
||||
return 'AlmanacNetworkTransactionType';
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ final class AlmanacProperty
|
|||
}
|
||||
|
||||
$xactions[] = id(clone $template)
|
||||
->setTransactionType(AlmanacTransaction::TYPE_PROPERTY_UPDATE)
|
||||
->setTransactionType($object->getAlmanacPropertySetTransactionType())
|
||||
->setMetadataValue('almanac.property', $name)
|
||||
->setNewValue($property);
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ final class AlmanacProperty
|
|||
$xactions = array();
|
||||
foreach ($properties as $property) {
|
||||
$xactions[] = id(clone $template)
|
||||
->setTransactionType(AlmanacTransaction::TYPE_PROPERTY_REMOVE)
|
||||
->setTransactionType($object->getAlmanacPropertyDeleteTransactionType())
|
||||
->setMetadataValue('almanac.property', $property)
|
||||
->setNewValue(null);
|
||||
}
|
||||
|
|
|
@ -160,6 +160,14 @@ final class AlmanacService
|
|||
return new AlmanacServicePropertyEditEngine();
|
||||
}
|
||||
|
||||
public function getAlmanacPropertySetTransactionType() {
|
||||
return AlmanacServiceSetPropertyTransaction::TRANSACTIONTYPE;
|
||||
}
|
||||
|
||||
public function getAlmanacPropertyDeleteTransactionType() {
|
||||
return AlmanacServiceDeletePropertyTransaction::TRANSACTIONTYPE;
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
|
|
@ -1,15 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class AlmanacServiceTransaction
|
||||
extends PhabricatorModularTransaction {
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'almanac';
|
||||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
return null;
|
||||
}
|
||||
extends AlmanacModularTransaction {
|
||||
|
||||
public function getApplicationTransactionType() {
|
||||
return AlmanacServicePHIDType::TYPECONST;
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
abstract class AlmanacTransaction
|
||||
extends PhabricatorApplicationTransaction {
|
||||
|
||||
const TYPE_PROPERTY_UPDATE = 'almanac:property:update';
|
||||
const TYPE_PROPERTY_REMOVE = 'almanac:property:remove';
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'almanac';
|
||||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$author_phid = $this->getAuthorPHID();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_PROPERTY_UPDATE:
|
||||
$property_key = $this->getMetadataValue('almanac.property');
|
||||
return pht(
|
||||
'%s updated the property "%s".',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$property_key);
|
||||
case self::TYPE_PROPERTY_REMOVE:
|
||||
$property_key = $this->getMetadataValue('almanac.property');
|
||||
return pht(
|
||||
'%s deleted the property "%s".',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$property_key);
|
||||
}
|
||||
|
||||
return parent::getTitle();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,97 @@
|
|||
<?php
|
||||
|
||||
abstract class AlmanacTransactionType
|
||||
extends PhabricatorModularTransactionType {}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue