mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +02:00
MDL-55971 dataformat: method to write exports to file storage.
This commit is contained in:
parent
a04309d40e
commit
b670d3adb6
2 changed files with 63 additions and 2 deletions
|
@ -26,6 +26,7 @@ namespace core;
|
|||
|
||||
use coding_exception;
|
||||
use core_php_time_limit;
|
||||
use stored_file;
|
||||
|
||||
/**
|
||||
* Dataformat utility class
|
||||
|
@ -144,4 +145,25 @@ class dataformat {
|
|||
|
||||
return $filepath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a formatted data file to file storage
|
||||
*
|
||||
* @param array $filerecord File record for storage, 'filename' extension should be omitted as it's added by the dataformat
|
||||
* @param string $dataformat
|
||||
* @param array $columns
|
||||
* @param Iterable $iterator Iterable set of records to write
|
||||
* @param callable|null $callback Optional callback method to apply to each record prior to writing
|
||||
* @return stored_file
|
||||
*/
|
||||
public static function write_data_to_filearea(array $filerecord, string $dataformat, array $columns, Iterable $iterator,
|
||||
callable $callback = null): stored_file {
|
||||
|
||||
$filepath = self::write_data($filerecord['filename'], $dataformat, $columns, $iterator, $callback);
|
||||
|
||||
// Update filename of returned file record.
|
||||
$filerecord['filename'] = basename($filepath);
|
||||
|
||||
return get_file_storage()->create_file_from_pathname($filerecord, $filepath);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue