Page MenuHomePhabricator

D18951.diff
No OneTemporary

D18951.diff

diff --git a/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php b/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php
--- a/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php
+++ b/src/applications/diffusion/query/DiffusionPullLogSearchEngine.php
@@ -49,12 +49,6 @@
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 @@
);
}
- public function newExport(array $events) {
+ protected function newExportData(array $events) {
$viewer = $this->requireViewer();
$phids = array();
@@ -112,8 +106,6 @@
}
$export[] = array(
- 'id' => $event->getID(),
- 'phid' => $event->getPHID(),
'repositoryPHID' => $repository_phid,
'repository' => $repository_name,
'pullerPHID' => $puller_phid,
diff --git a/src/applications/people/query/PhabricatorPeopleSearchEngine.php b/src/applications/people/query/PhabricatorPeopleSearchEngine.php
--- a/src/applications/people/query/PhabricatorPeopleSearchEngine.php
+++ b/src/applications/people/query/PhabricatorPeopleSearchEngine.php
@@ -322,12 +322,6 @@
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 @@
);
}
- 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(),
diff --git a/src/applications/search/controller/PhabricatorApplicationSearchController.php b/src/applications/search/controller/PhabricatorApplicationSearchController.php
--- a/src/applications/search/controller/PhabricatorApplicationSearchController.php
+++ b/src/applications/search/controller/PhabricatorApplicationSearchController.php
@@ -449,18 +449,7 @@
$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');
diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
--- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
+++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
@@ -1455,11 +1455,74 @@
}
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();
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Tue, Oct 22, 8:25 AM (3 d, 20 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6723810
Default Alt Text
D18951.diff (5 KB)

Event Timeline