From ab09cf2b84f95c11d3b52d7fdeb1a7c32871f7d0 Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Mon, 13 Mar 2023 21:49:55 +0100 Subject: [PATCH] MDL-40084 mod_data: Remove xls export, deprecate data_export_xls --- mod/data/deprecatedlib.php | 39 ++++++++++++++++++++++++++++++++++++++ mod/data/export.php | 6 +++--- mod/data/lib.php | 35 ---------------------------------- mod/data/upgrade.txt | 3 +++ 4 files changed, 45 insertions(+), 38 deletions(-) diff --git a/mod/data/deprecatedlib.php b/mod/data/deprecatedlib.php index d3c4315e86d..10a4a03b284 100644 --- a/mod/data/deprecatedlib.php +++ b/mod/data/deprecatedlib.php @@ -61,3 +61,42 @@ function data_get_completion_state($course, $cm, $userid, $type) { } return $result; } + +/** + * @deprecated since Moodle 4.3. + * @global object + * @param array $export + * @param string $dataname + * @param int $count + * @return string + */ +function data_export_xls($export, $dataname, $count) { + global $CFG; + + debugging('Function data_export_xls() has been deprecated, because xls export has been dropped.', + DEBUG_DEVELOPER); + require_once("$CFG->libdir/excellib.class.php"); + $filename = clean_filename("{$dataname}-{$count}_record"); + if ($count > 1) { + $filename .= 's'; + } + $filename .= clean_filename('-' . gmdate("Ymd_Hi")); + $filename .= '.xls'; + + $filearg = '-'; + $workbook = new MoodleExcelWorkbook($filearg); + $workbook->send($filename); + $worksheet = array(); + $worksheet[0] = $workbook->add_worksheet(''); + $rowno = 0; + foreach ($export as $row) { + $colno = 0; + foreach($row as $col) { + $worksheet[0]->write($rowno, $colno, $col); + $colno++; + } + $rowno++; + } + $workbook->close(); + return $filename; +} diff --git a/mod/data/export.php b/mod/data/export.php index e7f043ea1fc..f4d5c79cd08 100644 --- a/mod/data/export.php +++ b/mod/data/export.php @@ -102,12 +102,12 @@ if ($mform->is_cancelled()) { case 'csv': data_export_csv($exportdata, $formdata['delimiter_name'], $data->name, $count); break; - case 'xls': - data_export_xls($exportdata, $data->name, $count); - break; case 'ods': data_export_ods($exportdata, $data->name, $count); break; + default: + throw new coding_exception('Invalid export format has been specified. ' + . 'Only "csv" and "ods" are currently supported.'); } } diff --git a/mod/data/lib.php b/mod/data/lib.php index 9835ecd0275..fc16be4418c 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -3135,41 +3135,6 @@ function data_export_csv($export, $delimiter_name, $database, $count, $return=fa } } -/** - * @global object - * @param array $export - * @param string $dataname - * @param int $count - * @return string - */ -function data_export_xls($export, $dataname, $count) { - global $CFG; - require_once("$CFG->libdir/excellib.class.php"); - $filename = clean_filename("{$dataname}-{$count}_record"); - if ($count > 1) { - $filename .= 's'; - } - $filename .= clean_filename('-' . gmdate("Ymd_Hi")); - $filename .= '.xls'; - - $filearg = '-'; - $workbook = new MoodleExcelWorkbook($filearg); - $workbook->send($filename); - $worksheet = array(); - $worksheet[0] = $workbook->add_worksheet(''); - $rowno = 0; - foreach ($export as $row) { - $colno = 0; - foreach($row as $col) { - $worksheet[0]->write($rowno, $colno, $col); - $colno++; - } - $rowno++; - } - $workbook->close(); - return $filename; -} - /** * @global object * @param array $export diff --git a/mod/data/upgrade.txt b/mod/data/upgrade.txt index 34ee6113f20..11de206cffb 100644 --- a/mod/data/upgrade.txt +++ b/mod/data/upgrade.txt @@ -1,6 +1,9 @@ This files describes API changes in /mod/data - plugins, information provided here is intended especially for developers. +== 4.3 == +* Function data_export_xls() has been deprecated and moved to deprecatedlib, because xls support has already been dropped. + == 4.2 == * The field base class now has a method validate(). Overwrite it in the field type to provide validation of field type's parameters in the field add/modify form.