Differential D15327 Diff 36968 src/applications/almanac/controller/AlmanacPropertyDeleteController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/controller/AlmanacPropertyDeleteController.php
Show All 28 Lines | public function handleRequest(AphrontRequest $request) { | ||||
} | } | ||||
$cancel_uri = $object->getURI(); | $cancel_uri = $object->getURI(); | ||||
$builtins = $object->getAlmanacPropertyFieldSpecifications(); | $builtins = $object->getAlmanacPropertyFieldSpecifications(); | ||||
$is_builtin = isset($builtins[$key]); | $is_builtin = isset($builtins[$key]); | ||||
if ($is_builtin) { | if ($is_builtin) { | ||||
// This is a builtin property, so we're going to reset it to the | |||||
// default value. | |||||
$field_list = PhabricatorCustomField::getObjectFields( | |||||
$object, | |||||
PhabricatorCustomField::ROLE_DEFAULT); | |||||
// Note that we're NOT loading field values from the object: we just want | |||||
// to get the field's default value so we can reset it. | |||||
$fields = $field_list->getFields(); | |||||
$field = $fields[$key]; | |||||
$is_delete = false; | |||||
$new_value = $field->getValueForStorage(); | |||||
// Now, load the field to get the old value. | |||||
$field_list | |||||
->setViewer($viewer) | |||||
->readFieldsFromStorage($object); | |||||
$old_value = $field->getValueForStorage(); | |||||
$title = pht('Reset Property'); | $title = pht('Reset Property'); | ||||
$body = pht('Reset this property to its default value?'); | $body = pht( | ||||
$submit_text = pht('Reset'); | 'Reset property "%s" to its default value?', | ||||
$key); | |||||
$submit_text = pht('Reset Property'); | |||||
} else { | } else { | ||||
// This is a custom property, so we're going to delete it outright. | |||||
$is_delete = true; | |||||
$old_value = $object->getAlmanacPropertyValue($key); | |||||
$new_value = null; | |||||
$title = pht('Delete Property'); | $title = pht('Delete Property'); | ||||
$body = pht('Delete this property? TODO: DOES NOT WORK YET'); | $body = pht( | ||||
$submit_text = pht('Delete'); | 'Delete property "%s"?', | ||||
$key); | |||||
$submit_text = pht('Delete Property'); | |||||
} | } | ||||
$validation_exception = null; | $validation_exception = null; | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$xaction = $object->getApplicationTransactionTemplate() | $xaction = $object->getApplicationTransactionTemplate() | ||||
->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD) | ->setTransactionType(AlmanacTransaction::TYPE_PROPERTY_REMOVE) | ||||
->setMetadataValue('customfield:key', $key) | ->setMetadataValue('almanac.property', $key); | ||||
->setOldValue($old_value) | |||||
->setNewValue($new_value); | |||||
// TODO: We aren't really deleting properties that we claim to delete | |||||
// yet, but that needs to be specialized a little bit. | |||||
$editor = $object->getApplicationTransactionEditor() | $editor = $object->getApplicationTransactionEditor() | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->setContinueOnMissingFields(true); | ->setContinueOnMissingFields(true); | ||||
try { | try { | ||||
Show All 18 Lines |