diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2852,6 +2852,7 @@ 'PhabricatorExportEngineExtension' => 'infrastructure/export/engine/PhabricatorExportEngineExtension.php', 'PhabricatorExportField' => 'infrastructure/export/field/PhabricatorExportField.php', 'PhabricatorExportFormat' => 'infrastructure/export/format/PhabricatorExportFormat.php', + 'PhabricatorExportFormatSetting' => 'infrastructure/export/engine/PhabricatorExportFormatSetting.php', 'PhabricatorExtendedPolicyInterface' => 'applications/policy/interface/PhabricatorExtendedPolicyInterface.php', 'PhabricatorExtendingPhabricatorConfigOptions' => 'applications/config/option/PhabricatorExtendingPhabricatorConfigOptions.php', 'PhabricatorExtensionsSetupCheck' => 'applications/config/check/PhabricatorExtensionsSetupCheck.php', @@ -8288,6 +8289,7 @@ 'PhabricatorExportEngineExtension' => 'Phobject', 'PhabricatorExportField' => 'Phobject', 'PhabricatorExportFormat' => 'Phobject', + 'PhabricatorExportFormatSetting' => 'PhabricatorInternalSetting', 'PhabricatorExtendingPhabricatorConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorExtensionsSetupCheck' => 'PhabricatorSetupCheck', 'PhabricatorExternalAccount' => array( 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 @@ -421,6 +421,13 @@ $formats = PhabricatorExportFormat::getAllEnabledExportFormats(); $format_options = mpull($formats, 'getExportFormatName'); + // Try to default to the format the user used last time. If you just + // exported to Excel, you probably want to export to Excel again. + $format_key = $this->readExportFormatPreference(); + if (!isset($formats[$format_key])) { + $format_key = head_key($format_options); + } + $errors = array(); $e_format = null; @@ -434,6 +441,8 @@ } if (!$errors) { + $this->writeExportFormatPreference($format_key); + $query = $engine->buildQueryFromSavedQuery($saved_query); // NOTE: We aren't reading the pager from the request. Exports always @@ -497,6 +506,7 @@ ->setName('format') ->setLabel(pht('Format')) ->setError($e_format) + ->setValue($format_key) ->setOptions($format_options)); return $this->newDialog() @@ -912,4 +922,32 @@ return true; } + private function readExportFormatPreference() { + $viewer = $this->getViewer(); + $export_key = PhabricatorPolicyFavoritesSetting::SETTINGKEY; + return $viewer->getUserSetting($export_key); + } + + private function writeExportFormatPreference($value) { + $viewer = $this->getViewer(); + $request = $this->getRequest(); + + if (!$viewer->isLoggedIn()) { + return; + } + + $export_key = PhabricatorPolicyFavoritesSetting::SETTINGKEY; + $preferences = PhabricatorUserPreferences::loadUserPreferences($viewer); + + $editor = id(new PhabricatorUserPreferencesEditor()) + ->setActor($viewer) + ->setContentSourceFromRequest($request) + ->setContinueOnNoEffect(true) + ->setContinueOnMissingFields(true); + + $xactions = array(); + $xactions[] = $preferences->newTransaction($export_key, $value); + $editor->applyTransactions($preferences, $xactions); + } + } diff --git a/src/infrastructure/export/engine/PhabricatorExportFormatSetting.php b/src/infrastructure/export/engine/PhabricatorExportFormatSetting.php new file mode 100644 --- /dev/null +++ b/src/infrastructure/export/engine/PhabricatorExportFormatSetting.php @@ -0,0 +1,16 @@ +