Skip to content
Permalink
Browse files

MDL-24343 core: Deprecate zip_files

  • Loading branch information...
andrewnicols committed Jul 11, 2016
1 parent d1a3ea6 commit 56b9e796af1c0a1272cf8e77a4d4ac9819c49465
Showing with 30 additions and 46 deletions.
  1. +6 −3 lib/deprecatedlib.php
  2. +23 −43 lib/odslib.class.php
  3. +1 −0 lib/upgrade.txt
@@ -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 @@ public function add_format($properties = array()) {
* 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 @@ public function __construct(array $worksheets) {
$this->worksheets = $worksheets;
}
/**
* Fetch the file ocntnet for the ODS.
*
* @return string
*/
public function get_file_content() {
global $CFG;
require_once($CFG->libdir.'/filelib.php');
do {
$dir = 'ods/'.time().'_'.rand(0, 10000);
} while (file_exists($CFG->tempdir.'/'.$dir));
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";
$dir = make_request_directory();
$filename = $dir . '/result.ods';
$filename = "$dir/result.ods";
zip_files($files, $filename);
$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()],
];
$handle = fopen($filename, 'rb');
$contents = fread($handle, filesize($filename));
fclose($handle);
$packer = get_file_packer('application/zip');
$packer->archive_to_pathname($files, $filename);
remove_dir($dir); // Cleanup the temp directory.
$contents = file_get_contents($filename);
remove_dir($dir);
return $contents;
}
@@ -1286,7 +1266,7 @@ protected function get_ods_meta() {
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()

0 comments on commit 56b9e79

Please sign in to comment.
You can’t perform that action at this time.