Fixing wrong zip file format error.

skala
Julio Montoya 13 years ago
parent 293caaec63
commit 5ddc52ce37
  1. 3
      main/course_info/download.php
  2. 60
      main/coursecopy/classes/CourseArchiver.class.php
  3. 5
      main/coursecopy/classes/CourseRestorer.class.php
  4. 3
      main/coursecopy/create_backup.php
  5. 10
      main/coursecopy/import_backup.php

@ -7,7 +7,6 @@
/**
* Code
*/
//session_cache_limiter('public');
require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
@ -46,11 +45,11 @@ if (Security::check_abs_path($archive_path.$archive_file, $archive_path)) {
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: public');
header('Pragma: no-cache');
header('Content-Type: '.$content_type);
header('Content-Length: '.filesize($archive_path.$archive_file));
header('Content-Disposition: attachment; filename='.$archive_file);
readfile($archive_path.$archive_file);
exit;
} else {
api_not_allowed(true);
}

@ -34,17 +34,18 @@ class CourseArchiver
* Write a course and all its resources to a zip-file.
* @return string A pointer to the zip-file
*/
static function write_course($course) {
static function write_course($course)
{
$perm_dirs = api_get_permissions_for_new_directories();
CourseArchiver::clean_backup_dir();
// Create a temp directory
$tmp_dir_name = 'CourseArchiver_' . api_get_unique_id();
$backup_dir = api_get_path(SYS_ARCHIVE_PATH) . $tmp_dir_name . '/';
$tmp_dir_name = 'CourseArchiver_'.api_get_unique_id();
$backup_dir = api_get_path(SYS_ARCHIVE_PATH).$tmp_dir_name . '/';
// All course-information will be stored in course_info.dat
$course_info_file = $backup_dir . 'course_info.dat';
$course_info_file = $backup_dir.'course_info.dat';
$zip_dir = api_get_path(SYS_ARCHIVE_PATH);
$user = api_get_user_info();
$date = new DateTime(api_get_local_time());
@ -71,11 +72,9 @@ class CourseArchiver
error_log(__FILE__ . ' line ' . __LINE__ . ': ' . (ini_get('track_errors') != false ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini'), 0);
}
//Documents
// Copy all documents to the temp-dir
if (is_array($course->resources[RESOURCE_DOCUMENT])) {
foreach ($course->resources[RESOURCE_DOCUMENT] as $id => $document) {
if (isset($course->resources[RESOURCE_DOCUMENT]) && is_array($course->resources[RESOURCE_DOCUMENT])) {
foreach ($course->resources[RESOURCE_DOCUMENT] as $document) {
if ($document->file_type == DOCUMENT) {
$doc_dir = $backup_dir . $document->path;
@mkdir(dirname($doc_dir), $perm_dirs, true);
@ -90,14 +89,14 @@ class CourseArchiver
// Copy all scorm documents to the temp-dir
if (isset($course->resources[RESOURCE_SCORM]) && is_array($course->resources[RESOURCE_SCORM])) {
foreach ($course->resources[RESOURCE_SCORM] as $id => $document) {
foreach ($course->resources[RESOURCE_SCORM] as $document) {
$doc_dir = dirname($backup_dir . $document->path);
@mkdir($doc_dir, $perm_dirs, true);
FileManager::copyDirTo($course->path . $document->path, $doc_dir, false);
}
}
// Copy calendar attachments
// Copy calendar attachments.
if (isset($course->resources[RESOURCE_EVENT]) && is_array($course->resources[RESOURCE_EVENT])) {
$doc_dir = dirname($backup_dir . '/upload/calendar/');
@ -105,14 +104,14 @@ class CourseArchiver
FileManager::copyDirTo($course->path . 'upload/calendar/', $doc_dir, false);
}
//Copy learningpath author image
// Copy Learning path author image.
if (isset($course->resources[RESOURCE_LEARNPATH]) && is_array($course->resources[RESOURCE_LEARNPATH])) {
$doc_dir = dirname($backup_dir . '/upload/learning_path/');
@mkdir($doc_dir, $perm_dirs, true);
FileManager::copyDirTo($course->path . 'upload/learning_path/', $doc_dir, false);
}
//Copy announcements attachments
// Copy announcements attachments.
if (isset($course->resources[RESOURCE_ANNOUNCEMENT]) && is_array($course->resources[RESOURCE_ANNOUNCEMENT])) {
$doc_dir = dirname($backup_dir . '/upload/announcements/');
@ -126,7 +125,7 @@ class CourseArchiver
//$zip->deleteByIndex(0);
// Remove the temp-dir.
rmdirr($backup_dir);
return '' . $zip_file;
return $zip_file;
}
/**
@ -174,28 +173,39 @@ class CourseArchiver
* @param boolean $delete Delete the file after reading the course?
* @todo Check if the archive is a correct Chamilo-export
*/
static function read_course($filename, $delete = false) {
static function read_course($filename, $delete = false)
{
CourseArchiver::clean_backup_dir();
// Create a temp directory
$tmp_dir_name = 'CourseArchiver_' . uniqid('');
$unzip_dir = api_get_path(SYS_ARCHIVE_PATH) . '' . $tmp_dir_name;
@mkdir($unzip_dir, api_get_permissions_for_new_directories(), true);
@copy(api_get_path(SYS_ARCHIVE_PATH) . '' . $filename, $unzip_dir . '/backup.zip');
$unzip_dir = api_get_path(SYS_ARCHIVE_PATH).$tmp_dir_name;
mkdir($unzip_dir, api_get_permissions_for_new_directories(), true);
copy(api_get_path(SYS_ARCHIVE_PATH).$filename, $unzip_dir.'/backup.zip');
// unzip the archive
$zip = new PclZip($unzip_dir . '/backup.zip');
@chdir($unzip_dir);
$zip->extract(PCLZIP_OPT_TEMP_FILE_ON);
$zip = new PclZip($unzip_dir.'/backup.zip');
chdir($unzip_dir);
$list = $zip->extract(PCLZIP_OPT_TEMP_FILE_ON);
if ($list == 0) {
/*global $app;
$errorMessage = $zip->errorInfo(true);
$app['session']->getFlashBag()->add('warning', $errorMessage);*/
}
// remove the archive-file
if ($delete) {
@unlink(api_get_path(SYS_ARCHIVE_PATH) . '' . $filename);
if (file_exists(api_get_path(SYS_ARCHIVE_PATH).$filename)) {
unlink(api_get_path(SYS_ARCHIVE_PATH).$filename);
}
}
// read the course
// Read the course
if (!is_file('course_info.dat')) {
return new Course();
}
$fp = @fopen('course_info.dat', "r");
$contents = @fread($fp, filesize('course_info.dat'));
@fclose($fp);
$contents = file_get_contents('course_info.dat');
// CourseCopyLearnpath class appeared in Chamilo 1.8.7, it is the former Learnpath class in the "Copy course" tool.
// For backward comaptibility with archives created on Chamilo 1.8.6.2 or older systems, we have to do the following:
// Before unserialization, if class name "Learnpath" was found, it should be renamed as "CourseCopyLearnpath".

@ -138,11 +138,13 @@ class CourseRestorer
$this->destination_course_info = $course_info;
$this->course->destination_path = $course_info['path'];
}
$this->destination_course_id = $course_info['real_id'];
//Getting first teacher (for the forums)
// Getting first teacher (for the forums)
$teacher_list = CourseManager::get_teacher_list_from_course_code($course_info['real_id']);
$this->first_teacher_id = api_get_user_id();
if (!empty($teacher_list)) {
foreach ($teacher_list as $teacher) {
$this->first_teacher_id = $teacher['user_id'];
@ -1663,7 +1665,6 @@ class CourseRestorer
$new_answer_id = Database::insert_id();
$matching_list[$answer['iid']] = $new_answer_id;
}
//var_dump($matching_list, $matching_to_update);
foreach ($matching_to_update as $old_answer_id => $old_correct_id) {
$new_correct = $matching_list[$old_correct_id];
$new_fixed_id = $matching_list[$old_answer_id];

@ -78,10 +78,8 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
$form = new FormValidator('create_backup_form', 'post', api_get_self().'?'.api_get_cidreq());
$form->addElement('header', get_lang('SelectOptionForBackup'));
$form->addElement('radio', 'backup_option', '', get_lang('CreateFullBackup'), 'full_backup');
$form->addElement('radio', 'backup_option', '', get_lang('LetMeSelectItems'), 'select_items');
$form->addElement('style_submit_button', null, get_lang('CreateBackup'), 'class="save"');
$form->add_progress_bar();
@ -102,5 +100,4 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
}
}
/* FOOTER */
Display::display_footer();

@ -57,10 +57,10 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
// Partial backup here we recover the documents posted
$course = CourseSelectForm::get_posted_course();
} else {
if ($_POST['backup_type'] == 'server') {
$filename = $_POST['backup_server'];
$backupServer = isset($_POST['backup_server']) ? $_POST['backup_server'] : null;
if ($backupServer == 'server') {
$filename = $backupServer;
$delete_file = false;
} else {
if ($_FILES['backup']['error'] == 0) {
@ -81,7 +81,6 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
}
}
if (!$error && $course->has_resources()) {
$cr = new CourseRestorer($course);
@ -139,7 +138,7 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
$backups = CourseArchiver::get_available_backups($user);
$backups_available = count($backups) > 0;
$form = new FormValidator('import_backup_form', 'post', 'import_backup.php', '', 'multipart/form-data');
$form = new FormValidator('import_backup_form', 'post', api_get_path(WEB_PUBLIC_PATH).'main/coursecopy/import_backup.php', '', 'multipart/form-data');
$form->addElement('header', get_lang('SelectBackupFile'));
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('<div>{element}</div> ');
@ -199,7 +198,6 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
);
$form->addElement('html', '<br /><br />');
$form->addElement('html', get_lang('SameFilename'));
$form->addElement('html', '<br /><br />');
$form->addElement(

Loading…
Cancel
Save