Skip to content

Commit

Permalink
Fix #13715: Export plugin columns to CSV and Excel
Browse files Browse the repository at this point in the history
Prior to this, trying to include plugin columns in a CSV or Excel
export would generate a file containing errors:

 * CSV: "Fatal error: Call to undefined function csv_format_XXX()
   in csv_export.php on line 116"
 * excel: "Fatal error: Call to undefined function excel_format_XXX()
   in excel_xml_export.php on line 96"

where XXX is the column's name.

Signed-off-by: Damien Regad <damien.regad@merckgroup.com>
  • Loading branch information
vincentsels authored and dregad committed Jan 10, 2012
1 parent 224ca74 commit 45f4f52
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
9 changes: 9 additions & 0 deletions core/columns_api.php
Expand Up @@ -142,6 +142,15 @@ function columns_get_plugin_columns() {
return $s_column_array;
}

/**
* Returns true if the specified $p_column is a plugin column.
* @param string $p_column A column name.
*/
function column_is_plugin_column( $p_column ) {
$t_plugin_columns = columns_get_plugin_columns();
return isset( $t_plugin_columns[ $p_column ] );
}

/**
* Allow plugin columns to pre-cache data for a set of issues
* rather than requiring repeated queries for each issue.
Expand Down
20 changes: 20 additions & 0 deletions core/excel_api.php
Expand Up @@ -473,6 +473,26 @@ function excel_format_custom_field( $p_issue_id, $p_project_id, $p_custom_field
return excel_prepare_string( '' );
}

/**
* Gets the formatted value for the specified plugin column value.
* @param $p_custom_field The plugin column name.
* @param $p_bug The bug to print the column for (needed for the display function of the plugin column).
* @returns The custom field value.
*/
function excel_format_plugin_column_value( $p_column, $p_bug ) {
$t_plugin_columns = columns_get_plugin_columns();

if ( !isset( $t_plugin_columns[$p_column] ) ) {
return excel_prepare_string( '' );
} else {
$t_column_object = $t_plugin_columns[ $p_column ];
ob_start();
$t_column_object->display( $p_bug, COLUMNS_TARGET_EXCEL_PAGE );
$t_value = ob_get_clean();
return excel_prepare_string( $t_value );
}
}

/**
* Gets the formatted due date.
* @param $p_due_date The due date.
Expand Down
6 changes: 4 additions & 2 deletions csv_export.php
Expand Up @@ -46,6 +46,9 @@
if ( $t_rows === false ) {
print_header_redirect( 'view_all_set.php?type=0' );
}

# pre-cache custom column data
columns_plugin_cache_issue_data( $t_rows );

$t_filename = csv_get_default_filename();

Expand Down Expand Up @@ -108,8 +111,7 @@
$t_first_column = false;
}

$t_custom_field = column_get_custom_field_name( $t_column );
if ( $t_custom_field !== null ) {
if ( column_get_custom_field_name( $t_column ) !== null || column_is_plugin_column( $t_column ) ) {
ob_start();
$t_column_value_function = 'print_column_value';
helper_call_custom_function( $t_column_value_function, array( $t_column, $t_row, COLUMNS_TARGET_CSV_PAGE ) );
Expand Down
7 changes: 6 additions & 1 deletion excel_xml_export.php
Expand Up @@ -55,6 +55,9 @@
if ( $result === false ) {
print_header_redirect( 'view_all_set.php?type=0&print=1' );
}

# pre-cache custom column data
columns_plugin_cache_issue_data( $result );

header( 'Content-Type: application/vnd.ms-excel; charset=UTF-8' );
header( 'Pragma: public' );
Expand Down Expand Up @@ -91,7 +94,9 @@
$t_custom_field = column_get_custom_field_name( $t_column );
if ( $t_custom_field !== null ) {
echo excel_format_custom_field( $t_row->id, $t_row->project_id, $t_custom_field );
} else {
} else if ( column_is_plugin_column( $t_column ) ) {
echo excel_format_plugin_column_value( $t_column, $t_row );
} else{
$t_function = 'excel_format_' . $t_column;
echo $t_function( $t_row->$t_column );
}
Expand Down
3 changes: 3 additions & 0 deletions print_all_bug_page.php
Expand Up @@ -80,6 +80,9 @@

$result = filter_get_bug_rows( $f_page_number, $t_per_page, $t_page_count, $t_bug_count );
$row_count = count( $result );

# pre-cache custom column data
columns_plugin_cache_issue_data( $result );

# for export
$t_show_flag = gpc_get_int( 'show_flag', 0 );
Expand Down

0 comments on commit 45f4f52

Please sign in to comment.