Support CSV, JSON, and tab-separated text as export formats
Summary: Depends on D18919. Ref T13046. Adds some simple modular exporters. Test Plan: Exported pull logs in each format. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13046 Differential Revision: https://secure.phabricator.com/D18934
This commit is contained in:
47
src/infrastructure/export/PhabricatorCSVExportFormat.php
Normal file
47
src/infrastructure/export/PhabricatorCSVExportFormat.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
final class PhabricatorCSVExportFormat
|
||||
extends PhabricatorExportFormat {
|
||||
|
||||
const EXPORTKEY = 'csv';
|
||||
|
||||
private $rows = array();
|
||||
|
||||
public function getExportFormatName() {
|
||||
return pht('Comma-Separated Values (.csv)');
|
||||
}
|
||||
|
||||
public function isExportFormatEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getFileExtension() {
|
||||
return 'csv';
|
||||
}
|
||||
|
||||
public function getMIMEContentType() {
|
||||
return 'text/csv';
|
||||
}
|
||||
|
||||
public function addObject($object, array $fields, array $map) {
|
||||
$values = array();
|
||||
foreach ($fields as $key => $field) {
|
||||
$value = $map[$key];
|
||||
$value = $field->getTextValue($value);
|
||||
|
||||
if (preg_match('/\s|,|\"/', $value)) {
|
||||
$value = str_replace('"', '""', $value);
|
||||
$value = '"'.$value.'"';
|
||||
}
|
||||
|
||||
$values[] = $value;
|
||||
}
|
||||
|
||||
$this->rows[] = implode(',', $values);
|
||||
}
|
||||
|
||||
public function newFileData() {
|
||||
return implode("\n", $this->rows);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user