import, create checksums of the critical in-session objects (info, course_header
and restore) to be able to check in restore_execute.html that all the information
has arrived properly without any trim/error. Merged from 19_STABLE
//Save the restore session object
$SESSION->restore = $restore;
+ // Calculate all session objects checksum and store them in session too
+ // so restore_execute.html (used by manual restore and import) will be
+ // able to detect any problem in session info.
+ restore_save_session_object_checksums($restore, $info, $course_header);
+
echo "<div style='text-align:center'>";
/// Printout messages
$info = $SESSION->info;
$course_header = $SESSION->course_header;
$restore = $SESSION->restore;
+
+ // Validate objects from session by checking their checksums
+ $status = false;
+ if (isset($SESSION->restore_checksums)) {
+ $checksums = $SESSION->restore_checksums;
+ if (isset($checksums['info']) && $checksums['info'] == md5(serialize($info)) &&
+ isset($checksums['course_header']) && $checksums['course_header'] == md5(serialize($course_header)) &&
+ isset($checksums['restore']) && $checksums['restore'] == md5(serialize($restore))) {
+
+ $status = true; // All session checksums were or, we can rely on that to continue restoring
+ }
+ }
+ if(!$status) { // Something was wrong checking objects from session, abort with error
+ print_error('restorechecksumfailed');
+ }
}
//Add info->original_wwwroot to $restore to be able to use it in all the restore process
}
}
}
+ // Calculate all session objects checksum and store them in session too
+ // so restore_execute.html (used by manual restore and import) will be
+ // able to detect any problem in session info.
+ restore_save_session_object_checksums($restore, $SESSION->info, $SESSION->course_header);
+
return true;
}
+ /**
+ * Save the checksum of the 3 main in-session restore objects (restore, info, course_header)
+ * so restore_execute.html will be able to check that all them have arrived correctly, without
+ * losing data for any type of session size limit/error. MDL-18469. Used both by manual restore
+ * and import
+ */
+ function restore_save_session_object_checksums($restore, $info, $course_header) {
+ global $SESSION;
+ $restore_checksums = array();
+ $restore_checksums['info'] = md5(serialize($info));
+ $restore_checksums['course_header'] = md5(serialize($course_header));
+ $restore_checksums['restore'] = md5(serialize($restore));
+ $SESSION->restore_checksums = $restore_checksums;
+ }
+
function backup_to_restore_array($backup,$k=0) {
if (is_array($backup) ) {
$restore = array();