2016-03-05 01:08:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AlmanacServiceEditEngine
|
|
|
|
extends PhabricatorEditEngine {
|
|
|
|
|
|
|
|
const ENGINECONST = 'almanac.service';
|
|
|
|
|
|
|
|
private $serviceType;
|
|
|
|
|
|
|
|
public function setServiceType($service_type) {
|
|
|
|
$this->serviceType = $service_type;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getServiceType() {
|
|
|
|
return $this->serviceType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isEngineConfigurable() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEngineName() {
|
|
|
|
return pht('Almanac Services');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSummaryHeader() {
|
|
|
|
return pht('Edit Almanac Service Configurations');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSummaryText() {
|
|
|
|
return pht('This engine is used to edit Almanac services.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEngineApplicationClass() {
|
|
|
|
return 'PhabricatorAlmanacApplication';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function newEditableObject() {
|
|
|
|
$service_type = $this->getServiceType();
|
|
|
|
return AlmanacService::initializeNewService($service_type);
|
|
|
|
}
|
|
|
|
|
2018-04-09 19:00:13 +02:00
|
|
|
protected function newEditableObjectFromConduit(array $raw_xactions) {
|
|
|
|
$type = null;
|
|
|
|
foreach ($raw_xactions as $raw_xaction) {
|
|
|
|
if ($raw_xaction['type'] !== 'type') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$type = $raw_xaction['value'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type === null) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'When creating a new Almanac service via the Conduit API, you '.
|
|
|
|
'must provide a "type" transaction to select a type.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$map = AlmanacServiceType::getAllServiceTypes();
|
|
|
|
if (!isset($map[$type])) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'Service type "%s" is unrecognized. Valid types are: %s.',
|
|
|
|
$type,
|
|
|
|
implode(', ', array_keys($map))));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->setServiceType($type);
|
|
|
|
|
|
|
|
return $this->newEditableObject();
|
|
|
|
}
|
|
|
|
|
2018-04-09 18:54:57 +02:00
|
|
|
protected function newEditableObjectForDocumentation() {
|
|
|
|
$service_type = new AlmanacCustomServiceType();
|
|
|
|
$this->setServiceType($service_type->getServiceTypeConstant());
|
|
|
|
return $this->newEditableObject();
|
|
|
|
}
|
|
|
|
|
2016-03-05 01:08:38 +01:00
|
|
|
protected function newObjectQuery() {
|
|
|
|
return new AlmanacServiceQuery();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectCreateTitleText($object) {
|
|
|
|
return pht('Create Service');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectCreateButtonText($object) {
|
|
|
|
return pht('Create Service');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectEditTitleText($object) {
|
|
|
|
return pht('Edit Service: %s', $object->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectEditShortText($object) {
|
|
|
|
return pht('Edit Service');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectCreateShortText() {
|
|
|
|
return pht('Create Service');
|
|
|
|
}
|
|
|
|
|
2016-03-28 18:05:22 +02:00
|
|
|
protected function getObjectName() {
|
|
|
|
return pht('Service');
|
|
|
|
}
|
|
|
|
|
2016-03-05 01:08:38 +01:00
|
|
|
protected function getEditorURI() {
|
|
|
|
return '/almanac/service/edit/';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectCreateCancelURI($object) {
|
|
|
|
return '/almanac/service/';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectViewURI($object) {
|
|
|
|
return $object->getURI();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCreateNewObjectPolicy() {
|
|
|
|
return $this->getApplication()->getPolicy(
|
|
|
|
AlmanacCreateServicesCapability::CAPABILITY);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildCustomEditFields($object) {
|
|
|
|
return array(
|
|
|
|
id(new PhabricatorTextEditField())
|
|
|
|
->setKey('name')
|
|
|
|
->setLabel(pht('Name'))
|
|
|
|
->setDescription(pht('Name of the service.'))
|
Partially modularize AlmanacService transactions
Summary:
Ref T13120. Ref T12414. See PHI145. See PHI473. This partially modernizes AlmanacService transactions by moving them to ModularTransactions.
This isn't complete because the "update property" and "remove property" transactions aren't modularized. They still //work//, since the parent Editor implements them, but they no longer render properly on the timeline since the `Transaction` object no longer has rendering logic for them.
Tentatively, I'm going to try to convert the rest of the Almanac objects and then modularize those transactions. (Currently, all of Binding, Device, Namespace and Service support properties, although they can only actually be edited on Service, Device and Binding.)
If that turns out to be really tricky for some reason I can just copy/paste the timeline rendering for now, but I think it won't be too hard.
Test Plan:
- Created and edited Services.
- Tried to create a service with: a bad name, no name, a name which put it in a namespace I can't edit (got errors in all cases).
- Edited and removed properties. The edits worked, the timeline just renders a generic story now ('X edited this object (transaction type "almanac:property:update").').
Reviewers: amckinley
Reviewed By: amckinley
Maniphest Tasks: T13120, T12414
Differential Revision: https://secure.phabricator.com/D19317
2018-04-09 19:05:39 +02:00
|
|
|
->setTransactionType(AlmanacServiceNameTransaction::TRANSACTIONTYPE)
|
2016-03-05 01:08:38 +01:00
|
|
|
->setIsRequired(true)
|
|
|
|
->setValue($object->getName()),
|
2018-04-09 19:00:13 +02:00
|
|
|
id(new PhabricatorTextEditField())
|
|
|
|
->setKey('type')
|
|
|
|
->setLabel(pht('Type'))
|
|
|
|
->setIsConduitOnly(true)
|
|
|
|
->setTransactionType(
|
|
|
|
AlmanacServiceTypeTransaction::TRANSACTIONTYPE)
|
|
|
|
->setDescription(pht('When creating a service, set the type.'))
|
|
|
|
->setConduitDescription(pht('Set the service type.'))
|
|
|
|
->setConduitTypeDescription(pht('Service type.'))
|
|
|
|
->setValue($object->getServiceType()),
|
2016-03-05 01:08:38 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|