Use gzdeflate/gzinflate to compress the course backup see BT#14425

pull/2573/head
Julio 8 years ago
parent 93a2201d28
commit 1ee5737663
  1. 24
      main/coursecopy/create_backup.php
  2. 28
      src/Chamilo/CourseBundle/Component/CourseCopy/Course.php
  3. 5
      src/Chamilo/CourseBundle/Component/CourseCopy/CourseSelectForm.php

@ -16,13 +16,13 @@ require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE; $current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_course_script(true); api_protect_course_script(true);
api_check_archive_dir();
// Check access rights (only teachers are allowed here) // Check access rights (only teachers are allowed here)
if (!api_is_allowed_to_edit()) { if (!api_is_allowed_to_edit()) {
api_not_allowed(true); api_not_allowed(true);
} }
api_check_archive_dir();
api_set_more_memory_and_time_limits(); api_set_more_memory_and_time_limits();
// Section for the tabs // Section for the tabs
@ -53,7 +53,6 @@ if (Security::check_token('post') && (
) { ) {
// Clear token // Clear token
Security::clear_token(); Security::clear_token();
if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') { if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
$course = CourseSelectForm::get_posted_course(); $course = CourseSelectForm::get_posted_course();
} else { } else {
@ -61,12 +60,14 @@ if (Security::check_token('post') && (
$course = $cb->build(); $course = $cb->build();
} }
$zip_file = CourseArchiver::createBackup($course); $zipFile = CourseArchiver::createBackup($course);
echo Display::return_message(get_lang('BackupCreated'), 'confirm'); echo Display::return_message(get_lang('BackupCreated'), 'confirm');
echo '<br /> echo '<br />';
<a class="btn btn-primary btn-large" echo Display::url(
href="'.api_get_path(WEB_CODE_PATH).'course_info/download.php?archive='.$zip_file.'&'.api_get_cidreq().'"> get_lang('Download'),
'.get_lang('Download').'</a>'; api_get_path(WEB_CODE_PATH).'course_info/download.php?archive='.$zipFile.'&'.api_get_cidreq(),
['class' => 'btn btn-primary btn-large']
);
} elseif (Security::check_token('post') && ( } elseif (Security::check_token('post') && (
isset($_POST['backup_option']) && isset($_POST['backup_option']) &&
$_POST['backup_option'] == 'select_items' $_POST['backup_option'] == 'select_items'
@ -74,17 +75,15 @@ if (Security::check_token('post') && (
) { ) {
// Clear token // Clear token
Security::clear_token(); Security::clear_token();
$cb = new CourseBuilder('partial'); $cb = new CourseBuilder('partial');
$course = $cb->build(); $course = $cb->build();
if ($course->has_resources()) {
// Add token to Course select form // Add token to Course select form
$hiddenFields['sec_token'] = Security::get_token(); $hiddenFields['sec_token'] = Security::get_token();
CourseSelectForm::display_form($course, $hiddenFields); CourseSelectForm::display_form($course, $hiddenFields);
} else { } else {
$cb = new CourseBuilder(); echo Display::return_message(get_lang('NoResourcesToBackup'), 'warning');
$course = $cb->build(); }
if (!$course->has_resources()) {
echo get_lang('NoResourcesToBackup');
} else { } else {
$form = new FormValidator( $form = new FormValidator(
'create_backup_form', 'create_backup_form',
@ -121,6 +120,5 @@ if (Security::check_token('post') && (
echo '</div>'; echo '</div>';
echo '</div>'; echo '</div>';
} }
}
Display::display_footer(); Display::display_footer();

@ -340,10 +340,20 @@ class Course
public static function serialize($course) public static function serialize($course)
{ {
if (extension_loaded('igbinary')) { if (extension_loaded('igbinary')) {
return igbinary_serialize($course); $serialized = igbinary_serialize($course);
} else { } else {
return serialize($course); $serialized = serialize($course);
} }
// Compress
if (function_exists('gzdeflate')) {
$deflated = gzdeflate($serialized, 9);
if ($deflated !== false) {
$deflated = $serialized;
}
}
return $serialized;
} }
/** /**
@ -355,10 +365,20 @@ class Course
*/ */
public static function unserialize($course) public static function unserialize($course)
{ {
// Uncompress
if (function_exists('gzdeflate')) {
$inflated = @gzinflate($course);
if ($inflated !== false) {
$course = $inflated;
}
}
if (extension_loaded('igbinary')) { if (extension_loaded('igbinary')) {
return igbinary_unserialize($course); $unserialized = igbinary_unserialize($course);
} else { } else {
return unserialize($course); $unserialized = unserialize($course);
} }
return $unserialized;
} }
} }

@ -333,7 +333,10 @@ class CourseSelectForm
$course->resources['document'] = null; $course->resources['document'] = null;
} }
echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>'; /** @var Course $course */
$courseSerialized = base64_encode(Course::serialize($course));
echo '<input type="hidden" name="course" value="'.$courseSerialized.'"/>';
if (is_array($hidden_fields)) { if (is_array($hidden_fields)) {
foreach ($hidden_fields as $key => $value) { foreach ($hidden_fields as $key => $value) {
echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>'; echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';

Loading…
Cancel
Save