|
4 | 4 | use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
|
5 | 5 | use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
|
6 | 6 | use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
|
| 7 | +use ChamiloSession as Session; |
7 | 8 |
|
8 | 9 | /**
|
9 | 10 | * Import a backup.
|
|
40 | 41 | // Display the tool title
|
41 | 42 | echo Display::page_header($nameTools);
|
42 | 43 |
|
| 44 | +$action = isset($_POST['action']) ? $_POST['action'] : ''; |
| 45 | +$importOption = isset($_POST['import_option']) ? $_POST['import_option'] : ''; |
| 46 | + |
43 | 47 | /* MAIN CODE */
|
44 | 48 | $filename = '';
|
45 |
| -if (Security::check_token('post') && ( |
46 |
| - ( |
47 |
| - isset($_POST['action']) && |
48 |
| - $_POST['action'] == 'course_select_form' |
49 |
| - ) || ( |
50 |
| - isset($_POST['import_option']) && |
51 |
| - $_POST['import_option'] == 'full_backup' |
52 |
| - ) |
53 |
| - ) |
54 |
| -) { |
| 49 | +if (Security::check_token('post') && ($action === 'course_select_form' || $importOption === 'full_backup')) { |
55 | 50 | // Clear token
|
56 | 51 | Security::clear_token();
|
57 | 52 |
|
58 | 53 | $error = false;
|
59 |
| - if (isset($_POST['action']) && |
60 |
| - $_POST['action'] == 'course_select_form' |
61 |
| - ) { |
| 54 | + if ($action === 'course_select_form') { |
62 | 55 | // Partial backup here we recover the documents posted
|
63 |
| - // This gets $_POST['course']. Beware that when using Suhosin, |
64 |
| - // the post.max_value_length limit might get in the way of the |
65 |
| - // restoration of a course with many items. A value of 1,000,000 bytes |
66 |
| - // might be too short. |
67 |
| - $course = CourseSelectForm::get_posted_course(); |
| 56 | + $filename = Session::read('backup_file'); |
| 57 | + $course = CourseArchiver::readCourse($filename, false); |
| 58 | + $course = CourseSelectForm::get_posted_course(null, null, null, $course); |
68 | 59 | } else {
|
69 |
| - if ($_POST['backup_type'] == 'server') { |
| 60 | + if ($_POST['backup_type'] === 'server') { |
70 | 61 | $filename = $_POST['backup_server'];
|
71 | 62 | $delete_file = false;
|
72 | 63 | } else {
|
73 | 64 | if ($_FILES['backup']['error'] == 0) {
|
74 |
| - $filename = CourseArchiver::importUploadedFile( |
75 |
| - $_FILES['backup']['tmp_name'] |
76 |
| - ); |
| 65 | + $filename = CourseArchiver::importUploadedFile($_FILES['backup']['tmp_name']); |
77 | 66 | if ($filename === false) {
|
78 | 67 | $error = true;
|
79 | 68 | } else {
|
80 |
| - $delete_file = true; |
| 69 | + $delete_file = false; |
81 | 70 | }
|
| 71 | + Session::write('backup_file', $filename); |
82 | 72 | } else {
|
83 | 73 | $error = true;
|
84 | 74 | }
|
|
115 | 105 | }
|
116 | 106 | }
|
117 | 107 | CourseArchiver::cleanBackupDir();
|
118 |
| -} elseif (Security::check_token('post') && ( |
119 |
| - isset($_POST['import_option']) && |
120 |
| - $_POST['import_option'] == 'select_items' |
121 |
| - ) |
122 |
| -) { |
| 108 | +} elseif (Security::check_token('post') && $importOption === 'select_items') { |
123 | 109 | // Clear token
|
124 | 110 | Security::clear_token();
|
125 | 111 |
|
126 |
| - if ($_POST['backup_type'] == 'server') { |
| 112 | + if ($_POST['backup_type'] === 'server') { |
127 | 113 | $filename = $_POST['backup_server'];
|
128 | 114 | $delete_file = false;
|
129 | 115 | } else {
|
130 | 116 | $filename = CourseArchiver::importUploadedFile($_FILES['backup']['tmp_name']);
|
131 |
| - $delete_file = true; |
| 117 | + $delete_file = false; |
| 118 | + Session::write('backup_file', $filename); |
132 | 119 | }
|
133 | 120 | $course = CourseArchiver::readCourse($filename, $delete_file);
|
134 | 121 |
|
135 |
| - if ($course->has_resources() && ($filename !== false)) { |
| 122 | + if ($course->has_resources() && $filename !== false) { |
136 | 123 | $hiddenFields['same_file_name_option'] = $_POST['same_file_name_option'];
|
137 | 124 | // Add token to Course select form
|
138 | 125 | $hiddenFields['sec_token'] = Security::get_token();
|
|
146 | 133 | }
|
147 | 134 | } else {
|
148 | 135 | $user = api_get_user_info();
|
149 |
| - $backups = CourseArchiver::getAvailableBackups( |
150 |
| - $is_platformAdmin ? null : $user['user_id'] |
151 |
| - ); |
| 136 | + $backups = CourseArchiver::getAvailableBackups($is_platformAdmin ? null : $user['user_id']); |
152 | 137 | $backups_available = count($backups) > 0;
|
153 | 138 |
|
154 | 139 | $form = new FormValidator(
|
|
282 | 267 | $form->display();
|
283 | 268 | }
|
284 | 269 |
|
| 270 | +if (!isset($_POST['action'])) { |
| 271 | + Session::erase('backup_file'); |
| 272 | +} |
| 273 | + |
| 274 | + |
285 | 275 | Display::display_footer();
|
0 commit comments