mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
When PHPExcel is not installed, detect it and provide install instructions
Summary: Depends on D18957. Ref T13049. To do Excel exports, PHPExcel needs to be installed on the system somewhere. This library is enormous (1K files, ~100K SLOC), which is why we don't just include it in `externals/`. This install process is a little weird and we could improve it, but users don't seem to have too much difficulty with it. This shouldn't be worse than the existing workflow in Maniphest, and I tried to make it at least slightly more clear. Test Plan: Uninstalled PHPExcel, got it marked "Unavailable" and got reasonably-helpful-ish guidance on how to get it to work. Reinstalled, exported, got a sheet. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13049 Differential Revision: https://secure.phabricator.com/D18958
This commit is contained in:
parent
61b8c12970
commit
00b4eae1f4
3 changed files with 58 additions and 15 deletions
|
@ -418,8 +418,24 @@ final class PhabricatorApplicationSearchController
|
|||
$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 @@ final class PhabricatorApplicationSearchController
|
|||
$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) {
|
||||
|
|
|
@ -14,7 +14,30 @@ final class PhabricatorExcelExportFormat
|
|||
}
|
||||
|
||||
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(<<<EOHELP
|
||||
Data can not be exported to Excel because the PHPExcel library is not
|
||||
installed. This software component is required for Phabricator to create
|
||||
Excel files.
|
||||
|
||||
You can install PHPExcel from GitHub:
|
||||
|
||||
> https://github.com/PHPOffice/PHPExcel
|
||||
|
||||
Briefly:
|
||||
|
||||
- Clone that repository somewhere on the sever
|
||||
(like `/path/to/example/PHPExcel`).
|
||||
- Update your PHP `%s` setting (in `php.ini`) to include the PHPExcel
|
||||
`Classes` directory (like `/path/to/example/PHPExcel/Classes`).
|
||||
EOHELP
|
||||
,
|
||||
'include_path');
|
||||
}
|
||||
|
||||
public function getFileExtension() {
|
||||
|
|
|
@ -50,16 +50,4 @@ abstract class PhabricatorExportFormat
|
|||
->execute();
|
||||
}
|
||||
|
||||
final public static function getAllEnabledExportFormats() {
|
||||
$formats = self::getAllExportFormats();
|
||||
|
||||
foreach ($formats as $key => $format) {
|
||||
if (!$format->isExportFormatEnabled()) {
|
||||
unset($formats[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $formats;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue