1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-10 14:51:06 +01:00

Implement common infrastructure fields as export extensions

Summary:
Depends on D18959. Ref T13049. Provide tags, subscribers, spaces, and created/modified as automatic extensions for all objects which support them.

(Also, for JSON export, be a little more consistent about exporting `null` instead of empty string when there's no value in a text field.)

Test Plan: Exported users and tasks, saw relevant fields in the export.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13049

Differential Revision: https://secure.phabricator.com/D18960
This commit is contained in:
epriestley 2018-01-29 08:37:38 -08:00
parent 2ac4e1991b
commit c00838878a
12 changed files with 276 additions and 7 deletions

View file

@ -3130,9 +3130,11 @@ phutil_register_library_map(array(
'PhabricatorLipsumManagementWorkflow' => 'applications/lipsum/management/PhabricatorLipsumManagementWorkflow.php',
'PhabricatorLipsumMondrianArtist' => 'applications/lipsum/image/PhabricatorLipsumMondrianArtist.php',
'PhabricatorLiskDAO' => 'infrastructure/storage/lisk/PhabricatorLiskDAO.php',
'PhabricatorLiskExportEngineExtension' => 'infrastructure/export/engine/PhabricatorLiskExportEngineExtension.php',
'PhabricatorLiskFulltextEngineExtension' => 'applications/search/engineextension/PhabricatorLiskFulltextEngineExtension.php',
'PhabricatorLiskSearchEngineExtension' => 'applications/search/engineextension/PhabricatorLiskSearchEngineExtension.php',
'PhabricatorLiskSerializer' => 'infrastructure/storage/lisk/PhabricatorLiskSerializer.php',
'PhabricatorListExportField' => 'infrastructure/export/field/PhabricatorListExportField.php',
'PhabricatorLocalDiskFileStorageEngine' => 'applications/files/engine/PhabricatorLocalDiskFileStorageEngine.php',
'PhabricatorLocalTimeTestCase' => 'view/__tests__/PhabricatorLocalTimeTestCase.php',
'PhabricatorLocaleScopeGuard' => 'infrastructure/internationalization/scope/PhabricatorLocaleScopeGuard.php',
@ -3431,6 +3433,7 @@ phutil_register_library_map(array(
'PhabricatorPHIDInterface' => 'applications/phid/interface/PhabricatorPHIDInterface.php',
'PhabricatorPHIDListEditField' => 'applications/transactions/editfield/PhabricatorPHIDListEditField.php',
'PhabricatorPHIDListEditType' => 'applications/transactions/edittype/PhabricatorPHIDListEditType.php',
'PhabricatorPHIDListExportField' => 'infrastructure/export/field/PhabricatorPHIDListExportField.php',
'PhabricatorPHIDResolver' => 'applications/phid/resolver/PhabricatorPHIDResolver.php',
'PhabricatorPHIDType' => 'applications/phid/type/PhabricatorPHIDType.php',
'PhabricatorPHIDTypeTestCase' => 'applications/phid/type/__tests__/PhabricatorPHIDTypeTestCase.php',
@ -3839,6 +3842,7 @@ phutil_register_library_map(array(
'PhabricatorProjectsCurtainExtension' => 'applications/project/engineextension/PhabricatorProjectsCurtainExtension.php',
'PhabricatorProjectsEditEngineExtension' => 'applications/project/engineextension/PhabricatorProjectsEditEngineExtension.php',
'PhabricatorProjectsEditField' => 'applications/transactions/editfield/PhabricatorProjectsEditField.php',
'PhabricatorProjectsExportEngineExtension' => 'infrastructure/export/engine/PhabricatorProjectsExportEngineExtension.php',
'PhabricatorProjectsFulltextEngineExtension' => 'applications/project/engineextension/PhabricatorProjectsFulltextEngineExtension.php',
'PhabricatorProjectsMembersSearchEngineAttachment' => 'applications/project/engineextension/PhabricatorProjectsMembersSearchEngineAttachment.php',
'PhabricatorProjectsMembershipIndexEngineExtension' => 'applications/project/engineextension/PhabricatorProjectsMembershipIndexEngineExtension.php',
@ -4130,6 +4134,7 @@ phutil_register_library_map(array(
'PhabricatorSpacesController' => 'applications/spaces/controller/PhabricatorSpacesController.php',
'PhabricatorSpacesDAO' => 'applications/spaces/storage/PhabricatorSpacesDAO.php',
'PhabricatorSpacesEditController' => 'applications/spaces/controller/PhabricatorSpacesEditController.php',
'PhabricatorSpacesExportEngineExtension' => 'infrastructure/export/engine/PhabricatorSpacesExportEngineExtension.php',
'PhabricatorSpacesInterface' => 'applications/spaces/interface/PhabricatorSpacesInterface.php',
'PhabricatorSpacesListController' => 'applications/spaces/controller/PhabricatorSpacesListController.php',
'PhabricatorSpacesNamespace' => 'applications/spaces/storage/PhabricatorSpacesNamespace.php',
@ -4196,6 +4201,7 @@ phutil_register_library_map(array(
'PhabricatorStringExportField' => 'infrastructure/export/field/PhabricatorStringExportField.php',
'PhabricatorStringListConfigType' => 'applications/config/type/PhabricatorStringListConfigType.php',
'PhabricatorStringListEditField' => 'applications/transactions/editfield/PhabricatorStringListEditField.php',
'PhabricatorStringListExportField' => 'infrastructure/export/field/PhabricatorStringListExportField.php',
'PhabricatorStringSetting' => 'applications/settings/setting/PhabricatorStringSetting.php',
'PhabricatorSubmitEditField' => 'applications/transactions/editfield/PhabricatorSubmitEditField.php',
'PhabricatorSubscribableInterface' => 'applications/subscriptions/interface/PhabricatorSubscribableInterface.php',
@ -4210,6 +4216,7 @@ phutil_register_library_map(array(
'PhabricatorSubscriptionsEditController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php',
'PhabricatorSubscriptionsEditEngineExtension' => 'applications/subscriptions/engineextension/PhabricatorSubscriptionsEditEngineExtension.php',
'PhabricatorSubscriptionsEditor' => 'applications/subscriptions/editor/PhabricatorSubscriptionsEditor.php',
'PhabricatorSubscriptionsExportEngineExtension' => 'infrastructure/export/engine/PhabricatorSubscriptionsExportEngineExtension.php',
'PhabricatorSubscriptionsFulltextEngineExtension' => 'applications/subscriptions/engineextension/PhabricatorSubscriptionsFulltextEngineExtension.php',
'PhabricatorSubscriptionsHeraldAction' => 'applications/subscriptions/herald/PhabricatorSubscriptionsHeraldAction.php',
'PhabricatorSubscriptionsListController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsListController.php',
@ -8608,9 +8615,11 @@ phutil_register_library_map(array(
'PhabricatorLipsumManagementWorkflow' => 'PhabricatorManagementWorkflow',
'PhabricatorLipsumMondrianArtist' => 'PhabricatorLipsumArtist',
'PhabricatorLiskDAO' => 'LiskDAO',
'PhabricatorLiskExportEngineExtension' => 'PhabricatorExportEngineExtension',
'PhabricatorLiskFulltextEngineExtension' => 'PhabricatorFulltextEngineExtension',
'PhabricatorLiskSearchEngineExtension' => 'PhabricatorSearchEngineExtension',
'PhabricatorLiskSerializer' => 'Phobject',
'PhabricatorListExportField' => 'PhabricatorExportField',
'PhabricatorLocalDiskFileStorageEngine' => 'PhabricatorFileStorageEngine',
'PhabricatorLocalTimeTestCase' => 'PhabricatorTestCase',
'PhabricatorLocaleScopeGuard' => 'Phobject',
@ -8948,6 +8957,7 @@ phutil_register_library_map(array(
'PhabricatorPHIDExportField' => 'PhabricatorExportField',
'PhabricatorPHIDListEditField' => 'PhabricatorEditField',
'PhabricatorPHIDListEditType' => 'PhabricatorEditType',
'PhabricatorPHIDListExportField' => 'PhabricatorListExportField',
'PhabricatorPHIDResolver' => 'Phobject',
'PhabricatorPHIDType' => 'Phobject',
'PhabricatorPHIDTypeTestCase' => 'PhutilTestCase',
@ -9448,6 +9458,7 @@ phutil_register_library_map(array(
'PhabricatorProjectsCurtainExtension' => 'PHUICurtainExtension',
'PhabricatorProjectsEditEngineExtension' => 'PhabricatorEditEngineExtension',
'PhabricatorProjectsEditField' => 'PhabricatorTokenizerEditField',
'PhabricatorProjectsExportEngineExtension' => 'PhabricatorExportEngineExtension',
'PhabricatorProjectsFulltextEngineExtension' => 'PhabricatorFulltextEngineExtension',
'PhabricatorProjectsMembersSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
'PhabricatorProjectsMembershipIndexEngineExtension' => 'PhabricatorIndexEngineExtension',
@ -9815,6 +9826,7 @@ phutil_register_library_map(array(
'PhabricatorSpacesController' => 'PhabricatorController',
'PhabricatorSpacesDAO' => 'PhabricatorLiskDAO',
'PhabricatorSpacesEditController' => 'PhabricatorSpacesController',
'PhabricatorSpacesExportEngineExtension' => 'PhabricatorExportEngineExtension',
'PhabricatorSpacesInterface' => 'PhabricatorPHIDInterface',
'PhabricatorSpacesListController' => 'PhabricatorSpacesController',
'PhabricatorSpacesNamespace' => array(
@ -9888,6 +9900,7 @@ phutil_register_library_map(array(
'PhabricatorStringExportField' => 'PhabricatorExportField',
'PhabricatorStringListConfigType' => 'PhabricatorTextListConfigType',
'PhabricatorStringListEditField' => 'PhabricatorEditField',
'PhabricatorStringListExportField' => 'PhabricatorListExportField',
'PhabricatorStringSetting' => 'PhabricatorSetting',
'PhabricatorSubmitEditField' => 'PhabricatorEditField',
'PhabricatorSubscribedToObjectEdgeType' => 'PhabricatorEdgeType',
@ -9901,6 +9914,7 @@ phutil_register_library_map(array(
'PhabricatorSubscriptionsEditController' => 'PhabricatorController',
'PhabricatorSubscriptionsEditEngineExtension' => 'PhabricatorEditEngineExtension',
'PhabricatorSubscriptionsEditor' => 'PhabricatorEditor',
'PhabricatorSubscriptionsExportEngineExtension' => 'PhabricatorExportEngineExtension',
'PhabricatorSubscriptionsFulltextEngineExtension' => 'PhabricatorFulltextEngineExtension',
'PhabricatorSubscriptionsHeraldAction' => 'HeraldAction',
'PhabricatorSubscriptionsListController' => 'PhabricatorController',

View file

@ -464,7 +464,7 @@ final class ManiphestTaskSearchEngine
->setLabel(pht('Priority Name')),
id(new PhabricatorStringExportField())
->setKey('subtype')
->setLabel('string'),
->setLabel('Subtype'),
id(new PhabricatorURIExportField())
->setKey('uri')
->setLabel(pht('URI')),

View file

@ -328,9 +328,6 @@ final class PhabricatorPeopleSearchEngine
id(new PhabricatorStringExportField())
->setKey('realName')
->setLabel(pht('Real Name')),
id(new PhabricatorEpochExportField())
->setKey('created')
->setLabel(pht('Date Created')),
);
}
@ -342,7 +339,6 @@ final class PhabricatorPeopleSearchEngine
$export[] = array(
'username' => $user->getUsername(),
'realName' => $user->getRealName(),
'created' => $user->getDateCreated(),
);
}

View file

@ -0,0 +1,42 @@
<?php
final class PhabricatorLiskExportEngineExtension
extends PhabricatorExportEngineExtension {
const EXTENSIONKEY = 'lisk';
public function supportsObject($object) {
if (!($object instanceof LiskDAO)) {
return false;
}
if (!$object->getConfigOption(LiskDAO::CONFIG_TIMESTAMPS)) {
return false;
}
return true;
}
public function newExportFields() {
return array(
id(new PhabricatorEpochExportField())
->setKey('dateCreated')
->setLabel(pht('Created')),
id(new PhabricatorEpochExportField())
->setKey('dateModified')
->setLabel(pht('Modified')),
);
}
public function newExportData(array $objects) {
$map = array();
foreach ($objects as $object) {
$map[] = array(
'dateCreated' => $object->getDateCreated(),
'dateModified' => $object->getDateModified(),
);
}
return $map;
}
}

View file

@ -0,0 +1,60 @@
<?php
final class PhabricatorProjectsExportEngineExtension
extends PhabricatorExportEngineExtension {
const EXTENSIONKEY = 'projects';
public function supportsObject($object) {
return ($object instanceof PhabricatorProjectInterface);
}
public function newExportFields() {
return array(
id(new PhabricatorPHIDListExportField())
->setKey('tagPHIDs')
->setLabel(pht('Tag PHIDs')),
id(new PhabricatorStringListExportField())
->setKey('tags')
->setLabel(pht('Tags')),
);
}
public function newExportData(array $objects) {
$viewer = $this->getViewer();
$object_phids = mpull($objects, 'getPHID');
$projects_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs($object_phids)
->withEdgeTypes(
array(
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
));
$projects_query->execute();
$handles = $viewer->loadHandles($projects_query->getDestinationPHIDs());
$map = array();
foreach ($objects as $object) {
$object_phid = $object->getPHID();
$project_phids = $projects_query->getDestinationPHIDs(
array($object_phid),
array(PhabricatorProjectObjectHasProjectEdgeType::EDGECONST));
$handle_list = $handles->newSublist($project_phids);
$handle_list = iterator_to_array($handle_list);
$handle_names = mpull($handle_list, 'getName');
$handle_names = array_values($handle_names);
$map[] = array(
'tagPHIDs' => $project_phids,
'tags' => $handle_names,
);
}
return $map;
}
}

View file

@ -0,0 +1,53 @@
<?php
final class PhabricatorSpacesExportEngineExtension
extends PhabricatorExportEngineExtension {
const EXTENSIONKEY = 'spaces';
public function supportsObject($object) {
$viewer = $this->getViewer();
if (!PhabricatorSpacesNamespaceQuery::getViewerSpacesExist($viewer)) {
return false;
}
return ($object instanceof PhabricatorSpacesInterface);
}
public function newExportFields() {
return array(
id(new PhabricatorPHIDExportField())
->setKey('spacePHID')
->setLabel(pht('Space PHID')),
id(new PhabricatorStringExportField())
->setKey('space')
->setLabel(pht('Space')),
);
}
public function newExportData(array $objects) {
$viewer = $this->getViewer();
$space_phids = array();
foreach ($objects as $object) {
$space_phids[] = PhabricatorSpacesNamespaceQuery::getObjectSpacePHID(
$object);
}
$handles = $viewer->loadHandles($space_phids);
$map = array();
foreach ($objects as $object) {
$space_phid = PhabricatorSpacesNamespaceQuery::getObjectSpacePHID(
$object);
$map[] = array(
'spacePHID' => $space_phid,
'space' => $handles[$space_phid]->getName(),
);
}
return $map;
}
}

View file

@ -0,0 +1,60 @@
<?php
final class PhabricatorSubscriptionsExportEngineExtension
extends PhabricatorExportEngineExtension {
const EXTENSIONKEY = 'subscriptions';
public function supportsObject($object) {
return ($object instanceof PhabricatorSubscribableInterface);
}
public function newExportFields() {
return array(
id(new PhabricatorPHIDListExportField())
->setKey('subscriberPHIDs')
->setLabel(pht('Subscriber PHIDs')),
id(new PhabricatorStringListExportField())
->setKey('subscribers')
->setLabel(pht('Subscribers')),
);
}
public function newExportData(array $objects) {
$viewer = $this->getViewer();
$object_phids = mpull($objects, 'getPHID');
$projects_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs($object_phids)
->withEdgeTypes(
array(
PhabricatorObjectHasSubscriberEdgeType::EDGECONST,
));
$projects_query->execute();
$handles = $viewer->loadHandles($projects_query->getDestinationPHIDs());
$map = array();
foreach ($objects as $object) {
$object_phid = $object->getPHID();
$project_phids = $projects_query->getDestinationPHIDs(
array($object_phid),
array(PhabricatorObjectHasSubscriberEdgeType::EDGECONST));
$handle_list = $handles->newSublist($project_phids);
$handle_list = iterator_to_array($handle_list);
$handle_names = mpull($handle_list, 'getName');
$handle_names = array_values($handle_names);
$map[] = array(
'subscriberPHIDs' => $project_phids,
'subscribers' => $handle_names,
);
}
return $map;
}
}

View file

@ -25,7 +25,13 @@ abstract class PhabricatorExportField
}
public function getTextValue($value) {
return (string)$this->getNaturalValue($value);
$natural_value = $this->getNaturalValue($value);
if ($natural_value === null) {
return null;
}
return (string)$natural_value;
}
public function getNaturalValue($value) {

View file

@ -0,0 +1,10 @@
<?php
abstract class PhabricatorListExportField
extends PhabricatorExportField {
public function getTextValue($value) {
return implode("\n", $value);
}
}

View file

@ -0,0 +1,10 @@
<?php
final class PhabricatorPHIDListExportField
extends PhabricatorListExportField {
public function getCharacterWidth() {
return 32;
}
}

View file

@ -1,4 +1,18 @@
<?php
final class PhabricatorStringExportField
extends PhabricatorExportField {}
extends PhabricatorExportField {
public function getNaturalValue($value) {
if ($value === null) {
return $value;
}
if (!strlen($value)) {
return null;
}
return (string)$value;
}
}

View file

@ -0,0 +1,4 @@
<?php
final class PhabricatorStringListExportField
extends PhabricatorListExportField {}