mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Define common ID and PHID export fields in SearchEngine
Summary: Ref T13049. All exportable objects should always have these fields, so make them builtins. This also sets things up for extensions (like custom fields). Test Plan: Exported user data, got the same export as before. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13049 Differential Revision: https://secure.phabricator.com/D18951
This commit is contained in:
parent
1db281bcd1
commit
213eb8e93d
4 changed files with 66 additions and 30 deletions
|
@ -49,12 +49,6 @@ final class DiffusionPullLogSearchEngine
|
|||
|
||||
protected function newExportFields() {
|
||||
return array(
|
||||
id(new PhabricatorIDExportField())
|
||||
->setKey('id')
|
||||
->setLabel(pht('ID')),
|
||||
id(new PhabricatorPHIDExportField())
|
||||
->setKey('phid')
|
||||
->setLabel(pht('PHID')),
|
||||
id(new PhabricatorPHIDExportField())
|
||||
->setKey('repositoryPHID')
|
||||
->setLabel(pht('Repository PHID')),
|
||||
|
@ -82,7 +76,7 @@ final class DiffusionPullLogSearchEngine
|
|||
);
|
||||
}
|
||||
|
||||
public function newExport(array $events) {
|
||||
protected function newExportData(array $events) {
|
||||
$viewer = $this->requireViewer();
|
||||
|
||||
$phids = array();
|
||||
|
@ -112,8 +106,6 @@ final class DiffusionPullLogSearchEngine
|
|||
}
|
||||
|
||||
$export[] = array(
|
||||
'id' => $event->getID(),
|
||||
'phid' => $event->getPHID(),
|
||||
'repositoryPHID' => $repository_phid,
|
||||
'repository' => $repository_name,
|
||||
'pullerPHID' => $puller_phid,
|
||||
|
|
|
@ -322,12 +322,6 @@ final class PhabricatorPeopleSearchEngine
|
|||
|
||||
protected function newExportFields() {
|
||||
return array(
|
||||
id(new PhabricatorIDExportField())
|
||||
->setKey('id')
|
||||
->setLabel(pht('ID')),
|
||||
id(new PhabricatorPHIDExportField())
|
||||
->setKey('phid')
|
||||
->setLabel(pht('PHID')),
|
||||
id(new PhabricatorStringExportField())
|
||||
->setKey('username')
|
||||
->setLabel(pht('Username')),
|
||||
|
@ -340,14 +334,12 @@ final class PhabricatorPeopleSearchEngine
|
|||
);
|
||||
}
|
||||
|
||||
public function newExport(array $users) {
|
||||
protected function newExportData(array $users) {
|
||||
$viewer = $this->requireViewer();
|
||||
|
||||
$export = array();
|
||||
foreach ($users as $user) {
|
||||
$export[] = array(
|
||||
'id' => $user->getID(),
|
||||
'phid' => $user->getPHID(),
|
||||
'username' => $user->getUsername(),
|
||||
'realName' => $user->getRealName(),
|
||||
'created' => $user->getDateCreated(),
|
||||
|
|
|
@ -449,18 +449,7 @@ final class PhabricatorApplicationSearchController
|
|||
$format->setViewer($viewer);
|
||||
|
||||
$export_data = $engine->newExport($objects);
|
||||
|
||||
if (count($export_data) !== count($objects)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Search engine exported the wrong number of objects, expected '.
|
||||
'%s but got %s.',
|
||||
phutil_count($objects),
|
||||
phutil_count($export_data)));
|
||||
}
|
||||
|
||||
$objects = array_values($objects);
|
||||
$export_data = array_values($export_data);
|
||||
|
||||
$field_list = $engine->newExportFieldList();
|
||||
$field_list = mpull($field_list, null, 'getKey');
|
||||
|
|
|
@ -1455,11 +1455,74 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject {
|
|||
}
|
||||
|
||||
final public function newExportFieldList() {
|
||||
return $this->newExportFields();
|
||||
$builtin_fields = array(
|
||||
id(new PhabricatorIDExportField())
|
||||
->setKey('id')
|
||||
->setLabel(pht('ID')),
|
||||
id(new PhabricatorPHIDExportField())
|
||||
->setKey('phid')
|
||||
->setLabel(pht('PHID')),
|
||||
);
|
||||
|
||||
$fields = mpull($builtin_fields, null, 'getKey');
|
||||
|
||||
$export_fields = $this->newExportFields();
|
||||
foreach ($export_fields as $export_field) {
|
||||
$key = $export_field->getKey();
|
||||
|
||||
if (isset($fields[$key])) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Search engine ("%s") defines an export field with a key ("%s") '.
|
||||
'that collides with another field. Each field must have a '.
|
||||
'unique key.',
|
||||
get_class($this),
|
||||
$key));
|
||||
}
|
||||
|
||||
$fields[$key] = $export_field;
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
final public function newExport(array $objects) {
|
||||
$objects = array_values($objects);
|
||||
$n = count($objects);
|
||||
|
||||
$maps = array();
|
||||
foreach ($objects as $object) {
|
||||
$maps[] = array(
|
||||
'id' => $object->getID(),
|
||||
'phid' => $object->getPHID(),
|
||||
);
|
||||
}
|
||||
|
||||
$export_data = $this->newExportData($objects);
|
||||
$export_data = array_values($export_data);
|
||||
if (count($export_data) !== count($objects)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Search engine ("%s") exported the wrong number of objects, '.
|
||||
'expected %s but got %s.',
|
||||
get_class($this),
|
||||
phutil_count($objects),
|
||||
phutil_count($export_data)));
|
||||
}
|
||||
|
||||
for ($ii = 0; $ii < $n; $ii++) {
|
||||
$maps[$ii] += $export_data[$ii];
|
||||
}
|
||||
|
||||
return $maps;
|
||||
}
|
||||
|
||||
protected function newExportFields() {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function newExportData(array $objects) {
|
||||
throw new PhutilMethodNotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue