]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18469 checksum restore in-session objects - both in manual restore and
authorstronk7 <stronk7>
Mon, 5 Oct 2009 17:23:31 +0000 (17:23 +0000)
committerstronk7 <stronk7>
Mon, 5 Oct 2009 17:23:31 +0000 (17:23 +0000)
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

backup/restore_check.html
backup/restore_execute.html
backup/restorelib.php

index 8e00ab2bfd2f6d3e1097bb5bc28465d38ed6eb71..f2ac378543261c7eda65b2625b66fddca8b3fe1f 100644 (file)
         //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
index 6fd307e369a57cfd93171fecc114c5cf07048123..083cd45bc489db1c9b92a4d98bfe1dbea972f0b0 100644 (file)
@@ -8,6 +8,21 @@
         $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
index 47e0f9654dd0a3530cff598ae53018d7442fa294..275d74a336e4bfb33fcc68a93004e35e5f340bb7 100644 (file)
@@ -8016,9 +8016,29 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
                 }
             }
         }
+        // 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();