mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
MDL-24343 core: Deprecate zip_files
This commit is contained in:
parent
d1a3ea62ef
commit
56b9e796af
@ -674,11 +674,14 @@ function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
|
||||
* @param array $originalfiles Files to zip
|
||||
* @param string $destination The destination path
|
||||
* @return bool Outcome
|
||||
*
|
||||
* @deprecated since 2.0 MDL-15919
|
||||
*/
|
||||
function zip_files ($originalfiles, $destination) {
|
||||
global $CFG;
|
||||
function zip_files($originalfiles, $destination) {
|
||||
debugging(__FUNCTION__ . '() is deprecated. '
|
||||
. 'Please use the application/zip file_packer implementation instead.', DEBUG_DEVELOPER);
|
||||
|
||||
//Extract everything from destination
|
||||
// Extract everything from destination.
|
||||
$path_parts = pathinfo(cleardoubleslashes($destination));
|
||||
$destpath = $path_parts["dirname"]; //The path of the zip file
|
||||
$destfilename = $path_parts["basename"]; //The name of the zip file
|
||||
|
@ -72,6 +72,9 @@ class MoodleODSWorkbook {
|
||||
* Close the Moodle Workbook.
|
||||
*/
|
||||
public function close() {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
$writer = new MoodleODSWriter($this->worksheets);
|
||||
$contents = $writer->get_file_content();
|
||||
|
||||
@ -825,53 +828,30 @@ class MoodleODSWriter {
|
||||
$this->worksheets = $worksheets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the file ocntnet for the ODS.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_file_content() {
|
||||
global $CFG;
|
||||
$dir = make_request_directory();
|
||||
$filename = $dir . '/result.ods';
|
||||
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
$files = [
|
||||
'mimetype' => [$this->get_ods_mimetype()],
|
||||
'content.xml' => [$this->get_ods_content($this->worksheets)],
|
||||
'meta.xml' => [$this->get_ods_meta()],
|
||||
'styles.xml' => [$this->get_ods_styles()],
|
||||
'settings.xml' => [$this->get_ods_settings()],
|
||||
'META-INF/manifest.xml' => [$this->get_ods_manifest()],
|
||||
];
|
||||
|
||||
do {
|
||||
$dir = 'ods/'.time().'_'.rand(0, 10000);
|
||||
} while (file_exists($CFG->tempdir.'/'.$dir));
|
||||
$packer = get_file_packer('application/zip');
|
||||
$packer->archive_to_pathname($files, $filename);
|
||||
|
||||
make_temp_directory($dir);
|
||||
make_temp_directory($dir.'/META-INF');
|
||||
$dir = "$CFG->tempdir/$dir";
|
||||
$files = array();
|
||||
|
||||
$handle = fopen("$dir/mimetype", 'w');
|
||||
fwrite($handle, $this->get_ods_mimetype());
|
||||
$files[] = "$dir/mimetype";
|
||||
|
||||
$handle = fopen("$dir/content.xml", 'w');
|
||||
fwrite($handle, $this->get_ods_content($this->worksheets));
|
||||
$files[] = "$dir/content.xml";
|
||||
|
||||
$handle = fopen("$dir/meta.xml", 'w');
|
||||
fwrite($handle, $this->get_ods_meta());
|
||||
$files[] = "$dir/meta.xml";
|
||||
|
||||
$handle = fopen("$dir/styles.xml", 'w');
|
||||
fwrite($handle, $this->get_ods_styles());
|
||||
$files[] = "$dir/styles.xml";
|
||||
|
||||
$handle = fopen("$dir/settings.xml", 'w');
|
||||
fwrite($handle, $this->get_ods_settings());
|
||||
$files[] = "$dir/settings.xml";
|
||||
|
||||
$handle = fopen("$dir/META-INF/manifest.xml", 'w');
|
||||
fwrite($handle, $this->get_ods_manifest());
|
||||
$files[] = "$dir/META-INF";
|
||||
|
||||
$filename = "$dir/result.ods";
|
||||
zip_files($files, $filename);
|
||||
|
||||
$handle = fopen($filename, 'rb');
|
||||
$contents = fread($handle, filesize($filename));
|
||||
fclose($handle);
|
||||
|
||||
remove_dir($dir); // Cleanup the temp directory.
|
||||
$contents = file_get_contents($filename);
|
||||
|
||||
remove_dir($dir);
|
||||
return $contents;
|
||||
}
|
||||
|
||||
@ -1286,7 +1266,7 @@ class MoodleODSWriter {
|
||||
office:version="1.2">
|
||||
<office:meta>
|
||||
<meta:generator>Moodle '.$CFG->release.'</meta:generator>
|
||||
<meta:initial-creator>'.fullname($USER, true).'</meta:initial-creator>
|
||||
<meta:initial-creator>' . htmlspecialchars(fullname($USER, true), ENT_QUOTES, 'utf-8') . '</meta:initial-creator>
|
||||
<meta:creation-date>'.strftime('%Y-%m-%dT%H:%M:%S').'</meta:creation-date>
|
||||
<meta:document-statistic meta:table-count="1" meta:cell-count="0" meta:object-count="0"/>
|
||||
</office:meta>
|
||||
|
@ -25,6 +25,7 @@ information provided here is intended especially for developers.
|
||||
* The following functions have been deprecated and are not used any more:
|
||||
- get_records_csv() Please use csv_import_reader::load_csv_content() instead.
|
||||
- put_records_csv() Please use download_as_dataformat (lib/dataformatlib.php) instead.
|
||||
- zip_files() - See MDL-24343 for more information.
|
||||
* The password_compat library was removed as it is no longer required.
|
||||
* Phpunit has been upgraded to 5.4.x and following has been deprecated and is not used any more:
|
||||
- setExpectedException(), use @expectedException or $this->expectException() and $this->expectExceptionMessage()
|
||||
|
Loading…
x
Reference in New Issue
Block a user