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 @@ -418,8 +418,24 @@ $filename = phutil_utf8_strtolower($filename); $filename = PhabricatorFile::normalizeFileName($filename); - $formats = PhabricatorExportFormat::getAllEnabledExportFormats(); - $format_options = mpull($formats, 'getExportFormatName'); + $all_formats = PhabricatorExportFormat::getAllExportFormats(); + + $available_options = array(); + $unavailable_options = array(); + $formats = array(); + $unavailable_formats = array(); + foreach ($all_formats as $key => $format) { + if ($format->isExportFormatEnabled()) { + $available_options[$key] = $format->getExportFormatName(); + $formats[$key] = $format; + } else { + $unavailable_options[$key] = pht( + '%s (Not Available)', + $format->getExportFormatName()); + $unavailable_formats[$key] = $format; + } + } + $format_options = $available_options + $unavailable_options; // 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. @@ -433,6 +449,22 @@ $e_format = null; if ($request->isFormPost()) { $format_key = $request->getStr('format'); + + if (isset($unavailable_formats[$format_key])) { + $unavailable = $unavailable_formats[$format_key]; + $instructions = $unavailable->getInstallInstructions(); + + $markup = id(new PHUIRemarkupView($viewer, $instructions)) + ->setRemarkupOption( + PHUIRemarkupView::OPTION_PRESERVE_LINEBREAKS, + false); + + return $this->newDialog() + ->setTitle(pht('Export Format Not Available')) + ->appendChild($markup) + ->addCancelButton($cancel_uri, pht('Done')); + } + $format = idx($formats, $format_key); if (!$format) { diff --git a/src/infrastructure/export/field/PhabricatorExportFormat.php b/src/infrastructure/export/field/PhabricatorExportFormat.php --- a/src/infrastructure/export/field/PhabricatorExportFormat.php +++ b/src/infrastructure/export/field/PhabricatorExportFormat.php @@ -50,16 +50,4 @@ ->execute(); } - final public static function getAllEnabledExportFormats() { - $formats = self::getAllExportFormats(); - - foreach ($formats as $key => $format) { - if (!$format->isExportFormatEnabled()) { - unset($formats[$key]); - } - } - - return $formats; - } - } diff --git a/src/infrastructure/export/format/PhabricatorExcelExportFormat.php b/src/infrastructure/export/format/PhabricatorExcelExportFormat.php --- a/src/infrastructure/export/format/PhabricatorExcelExportFormat.php +++ b/src/infrastructure/export/format/PhabricatorExcelExportFormat.php @@ -14,7 +14,30 @@ } public function isExportFormatEnabled() { - return true; + // TODO: PHPExcel has a dependency on the PHP zip extension. We should test + // for that here, since it fatals if we don't have the ZipArchive class. + return @include_once 'PHPExcel.php'; + } + + public function getInstallInstructions() { + return pht(<< https://github.com/PHPOffice/PHPExcel + +Briefly: + + - Clone that repository somewhere on the sever + (like `/path/to/example/PHPExcel`). + - Update your PHP `%s` setting to include the PHPExcel `Classes` directory + (like `/path/to/example/PHPExcel/Classes`). +EOHELP + , + 'include_path'); } public function getFileExtension() {