1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Export "date" and "remarkup" custom fields to Excel + "zip" extension check

Summary:
Fixes T13342. This does a few different things, although all of them seem small enough that I didn't bother splitting it up:

  - Support export of "remarkup" custom fields as text. There's some argument here to export them in some kind of structure if the target is JSON, but it's hard for me to really imagine we'll live in a world some day where we really regret just exporting them as text.
  - Support export of "date" custom fields as dates. This is easy except that I added `null` support.
  - If you built PHP from source without "--enable-zip", as I did, you can hit the TODO in Excel exports about "ZipArchive". Since I had a reproduction case, test for "ZipArchive" and give the user a better error if it's missing.
  - Add a setup check for the "zip" extension to try to avoid getting there in the first place. This is normally part of PHP so I believe users generally won't hit it, I just hit it because I built from source. See also T13232.

Test Plan:
  - Added a custom "date" field. On tasks A and B, set it to null and some non-null value. Exported both tasks to Excel/JSON/text, saw null and a date, respectively.
  - Added a custom "remarkup" field, exported some values, saw the values in Excel.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13342

Differential Revision: https://secure.phabricator.com/D20658
This commit is contained in:
epriestley 2019-07-17 15:33:02 -07:00
parent d02beaf816
commit 9ab5f59ca2
6 changed files with 64 additions and 2 deletions

View file

@ -5023,6 +5023,7 @@ phutil_register_library_map(array(
'PhabricatorXHProfSampleQuery' => 'applications/xhprof/query/PhabricatorXHProfSampleQuery.php', 'PhabricatorXHProfSampleQuery' => 'applications/xhprof/query/PhabricatorXHProfSampleQuery.php',
'PhabricatorXHProfSampleSearchEngine' => 'applications/xhprof/query/PhabricatorXHProfSampleSearchEngine.php', 'PhabricatorXHProfSampleSearchEngine' => 'applications/xhprof/query/PhabricatorXHProfSampleSearchEngine.php',
'PhabricatorYoutubeRemarkupRule' => 'infrastructure/markup/rule/PhabricatorYoutubeRemarkupRule.php', 'PhabricatorYoutubeRemarkupRule' => 'infrastructure/markup/rule/PhabricatorYoutubeRemarkupRule.php',
'PhabricatorZipSetupCheck' => 'applications/config/check/PhabricatorZipSetupCheck.php',
'Phame404Response' => 'applications/phame/site/Phame404Response.php', 'Phame404Response' => 'applications/phame/site/Phame404Response.php',
'PhameBlog' => 'applications/phame/storage/PhameBlog.php', 'PhameBlog' => 'applications/phame/storage/PhameBlog.php',
'PhameBlog404Controller' => 'applications/phame/controller/blog/PhameBlog404Controller.php', 'PhameBlog404Controller' => 'applications/phame/controller/blog/PhameBlog404Controller.php',
@ -11449,6 +11450,7 @@ phutil_register_library_map(array(
'PhabricatorXHProfSampleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorXHProfSampleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorXHProfSampleSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorXHProfSampleSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorYoutubeRemarkupRule' => 'PhutilRemarkupRule', 'PhabricatorYoutubeRemarkupRule' => 'PhutilRemarkupRule',
'PhabricatorZipSetupCheck' => 'PhabricatorSetupCheck',
'Phame404Response' => 'AphrontHTMLResponse', 'Phame404Response' => 'AphrontHTMLResponse',
'PhameBlog' => array( 'PhameBlog' => array(
'PhameDAO', 'PhameDAO',

View file

@ -0,0 +1,29 @@
<?php
final class PhabricatorZipSetupCheck extends PhabricatorSetupCheck {
public function getDefaultGroup() {
return self::GROUP_OTHER;
}
protected function executeChecks() {
if (!extension_loaded('zip')) {
$message = pht(
'The PHP "zip" extension is not installed. This extension is '.
'required by certain data export operations, including exporting '.
'data to Excel.'.
"\n\n".
'To clear this setup issue, install the extension and restart your '.
'webserver.'.
"\n\n".
'You may safely ignore this issue if you do not plan to export '.
'data in Zip archives or Excel spreadsheets, or intend to install '.
'the extension later.');
$this->newIssue('extension.zip')
->setName(pht('Missing "zip" Extension'))
->setMessage($message)
->addPHPExtension('zip');
}
}
}

View file

@ -242,4 +242,8 @@ final class PhabricatorStandardCustomFieldDate
return new ConduitEpochParameterType(); return new ConduitEpochParameterType();
} }
protected function newExportFieldType() {
return new PhabricatorEpochExportField();
}
} }

View file

@ -107,4 +107,8 @@ final class PhabricatorStandardCustomFieldRemarkup
return new ConduitStringParameterType(); return new ConduitStringParameterType();
} }
protected function newExportFieldType() {
return new PhabricatorStringExportField();
}
} }

View file

@ -6,6 +6,10 @@ final class PhabricatorEpochExportField
private $zone; private $zone;
public function getTextValue($value) { public function getTextValue($value) {
if ($value === null) {
return '';
}
if (!isset($this->zone)) { if (!isset($this->zone)) {
$this->zone = new DateTimeZone('UTC'); $this->zone = new DateTimeZone('UTC');
} }
@ -21,12 +25,20 @@ final class PhabricatorEpochExportField
} }
public function getNaturalValue($value) { public function getNaturalValue($value) {
if ($value === null) {
return $value;
}
return (int)$value; return (int)$value;
} }
public function getPHPExcelValue($value) { public function getPHPExcelValue($value) {
$epoch = $this->getNaturalValue($value); $epoch = $this->getNaturalValue($value);
if ($epoch === null) {
return null;
}
$seconds_per_day = phutil_units('1 day in seconds'); $seconds_per_day = phutil_units('1 day in seconds');
$offset = ($seconds_per_day * 25569); $offset = ($seconds_per_day * 25569);

View file

@ -14,12 +14,23 @@ final class PhabricatorExcelExportFormat
} }
public function isExportFormatEnabled() { public function isExportFormatEnabled() {
// TODO: PHPExcel has a dependency on the PHP zip extension. We should test if (!extension_loaded('zip')) {
// for that here, since it fatals if we don't have the ZipArchive class. return false;
}
return @include_once 'PHPExcel.php'; return @include_once 'PHPExcel.php';
} }
public function getInstallInstructions() { public function getInstallInstructions() {
if (!extension_loaded('zip')) {
return pht(<<<EOHELP
Data can not be exported to Excel because the "zip" PHP extension is not
installed. Consult the setup issue in the Config application for guidance on
installing the extension.
EOHELP
);
}
return pht(<<<EOHELP return pht(<<<EOHELP
Data can not be exported to Excel because the PHPExcel library is not Data can not be exported to Excel because the PHPExcel library is not
installed. This software component is required for Phabricator to create installed. This software component is required for Phabricator to create