Differential D18954 Diff 45478 src/applications/search/engine/PhabricatorApplicationSearchEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
| Show First 20 Lines • Show All 1,477 Lines • ▼ Show 20 Lines | foreach ($export_fields as $export_field) { | ||||
| 'unique key.', | 'unique key.', | ||||
| get_class($this), | get_class($this), | ||||
| $key)); | $key)); | ||||
| } | } | ||||
| $fields[$key] = $export_field; | $fields[$key] = $export_field; | ||||
| } | } | ||||
| $extensions = $this->newExportExtensions(); | |||||
| foreach ($extensions as $extension) { | |||||
| $extension_fields = $extension->newExportFields(); | |||||
| foreach ($extension_fields as $extension_field) { | |||||
| $key = $extension_field->getKey(); | |||||
| if (isset($fields[$key])) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Export engine extension ("%s") defines an export field with '. | |||||
| 'a key ("%s") that collides with another field. Each field '. | |||||
| 'must have a unique key.', | |||||
| get_class($extension_field), | |||||
| $key)); | |||||
| } | |||||
| $fields[$key] = $extension_field; | |||||
| } | |||||
| } | |||||
| return $fields; | return $fields; | ||||
| } | } | ||||
| final public function newExport(array $objects) { | final public function newExport(array $objects) { | ||||
| $objects = array_values($objects); | $objects = array_values($objects); | ||||
| $n = count($objects); | $n = count($objects); | ||||
| $maps = array(); | $maps = array(); | ||||
| Show All 15 Lines | if (count($export_data) !== count($objects)) { | ||||
| phutil_count($objects), | phutil_count($objects), | ||||
| phutil_count($export_data))); | phutil_count($export_data))); | ||||
| } | } | ||||
| for ($ii = 0; $ii < $n; $ii++) { | for ($ii = 0; $ii < $n; $ii++) { | ||||
| $maps[$ii] += $export_data[$ii]; | $maps[$ii] += $export_data[$ii]; | ||||
| } | } | ||||
| $extensions = $this->newExportExtensions(); | |||||
| foreach ($extensions as $extension) { | |||||
| $extension_data = $extension->newExportData($objects); | |||||
| $extension_data = array_values($extension_data); | |||||
| if (count($export_data) !== count($objects)) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Export engine extension ("%s") exported the wrong number of '. | |||||
| 'objects, expected %s but got %s.', | |||||
| get_class($extension), | |||||
| phutil_count($objects), | |||||
| phutil_count($export_data))); | |||||
| } | |||||
| for ($ii = 0; $ii < $n; $ii++) { | |||||
| $maps[$ii] += $extension_data[$ii]; | |||||
| } | |||||
| } | |||||
| return $maps; | return $maps; | ||||
| } | } | ||||
| protected function newExportFields() { | protected function newExportFields() { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| protected function newExportData(array $objects) { | protected function newExportData(array $objects) { | ||||
| throw new PhutilMethodNotImplementedException(); | throw new PhutilMethodNotImplementedException(); | ||||
| } | } | ||||
| private function newExportExtensions() { | |||||
| $object = $this->newResultObject(); | |||||
| $viewer = $this->requireViewer(); | |||||
| $extensions = PhabricatorExportEngineExtension::getAllExtensions(); | |||||
| $supported = array(); | |||||
| foreach ($extensions as $extension) { | |||||
| $extension = clone $extension; | |||||
| $extension->setViewer($viewer); | |||||
| if ($extension->supportsObject($object)) { | |||||
| $supported[] = $extension; | |||||
| } | |||||
| } | |||||
| return $supported; | |||||
| } | |||||
| } | } | ||||