1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-28 12:08:14 +01:00
phorge-phorge/src/applications/almanac/controller/AlmanacPropertyDeleteController.php
epriestley f7d5904e4b Expose modern *.search Conduit endpoints in Almanac
Summary: Fixes T10411. Ref T10246. There are probably still some rough edges with this, but replace the old-school endpoints with modern ones so we don't unprototype with deprecated stuff.

Test Plan:
  - Made a bunch of calls to the new endpoints with various constraints/attachments.
  - Created and edited services, devices, interfaces, bindings, and properties on everything.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10246, T10411

Differential Revision: https://secure.phabricator.com/D15329
2016-02-23 08:20:57 -08:00

70 lines
2 KiB
PHP

<?php
final class AlmanacPropertyDeleteController
extends AlmanacPropertyController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$response = $this->loadPropertyObject();
if ($response) {
return $response;
}
$object = $this->getPropertyObject();
$key = $request->getStr('key');
if (!strlen($key)) {
return new Aphront404Response();
}
$cancel_uri = $object->getURI();
$builtins = $object->getAlmanacPropertyFieldSpecifications();
$is_builtin = isset($builtins[$key]);
if ($is_builtin) {
$title = pht('Reset Property');
$body = pht(
'Reset property "%s" to its default value?',
$key);
$submit_text = pht('Reset Property');
} else {
$title = pht('Delete Property');
$body = pht(
'Delete property "%s"?',
$key);
$submit_text = pht('Delete Property');
}
$validation_exception = null;
if ($request->isFormPost()) {
$xaction = $object->getApplicationTransactionTemplate()
->setTransactionType(AlmanacTransaction::TYPE_PROPERTY_REMOVE)
->setMetadataValue('almanac.property', $key);
$editor = $object->getApplicationTransactionEditor()
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);
try {
$editor->applyTransactions($object, array($xaction));
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
}
}
return $this->newDialog()
->setTitle($title)
->setValidationException($validation_exception)
->addHiddenInput('objectPHID', $object->getPHID())
->addHiddenInput('key', $key)
->appendParagraph($body)
->addCancelButton($cancel_uri)
->addSubmitButton($submit_text);
}
}