]> git.mjollnir.org Git - moodle.git/commitdiff
Now scheduled backup supports new blocks.
authorstronk7 <stronk7>
Thu, 27 Jan 2005 19:07:51 +0000 (19:07 +0000)
committerstronk7 <stronk7>
Thu, 27 Jan 2005 19:07:51 +0000 (19:07 +0000)
Moved blocks code to library.
Fixed a missing global preventing restore to work.

backup/CHANGES_14_15.txt
backup/backup_scheduled.php
backup/restore_execute.html
backup/restorelib.php

index 0ca00457afe1d7d1465cef4f958d09ff5e41005d..0327a9edc86266306a98f67615643322a0a32e6a 100644 (file)
@@ -28,7 +28,8 @@ Now I show the specific detailed status of every item in the process:
           (in backup process).
 18. TODO: If the course hasn't users and the importer is a teacher, make him
           teacher in the restored course.
-19. TODO: Move blocks code to libraries and use it in a standard way.
+19. DONE: Move blocks code to libraries and use it in a standard way. Now new
+          blocks are supported by scheduled backup.
 20. TODO: Review the lesson module completely! Check the upgrade process to
           mimic it.
 21. TODO: Review the workshop module completely! Check the upgrade process to
index 15b550be6798af09f95d1c12160d230cd4b133a0..5df076233780b6775e6d8dc6e493134afb9f2927 100644 (file)
@@ -558,6 +558,12 @@ function schedule_backup_course_execute($preferences,$starttime = 0) {
             $status = backup_course_start($backup_file,$preferences);
         }
 
+        //Block info
+        if ($status) {
+            schedule_backup_log($starttime,$preferences->backup_course,"      blocks info");
+            $status = backup_course_blocks($backup_file,$preferences);
+        }
+
         //Section info
         if ($status) {
             schedule_backup_log($starttime,$preferences->backup_course,"      sections info");
index e3c7b057cb1c6c59c388593d905b601eef21d9ee..d3b844d8c7bf0540a44b4fbb3c267ab99d32f43f 100644 (file)
 
     //Bring back the course blocks
     if($status) {
-        echo '<li>'.get_string('creatingblocks');
         //If we are deleting and bringing into a course or making a new course, same situation
         if($restore->restoreto == 0 || $restore->restoreto == 2) {
-            delete_records('block_instance', 'pageid', $course_header->course_id, 'pagetype', MOODLE_PAGE_COURSE);
-            if (empty($info->backup_block_format)) {     // This is a backup from Moodle < 1.5
-                if (empty($course_header->blockinfo)) {
-                    // Looks like it's from Moodle < 1.3. Let's give the course default blocks...
-                    $newpage = page_create_object(MOODLE_PAGE_COURSE, $course_header->course_id);
-                    blocks_repopulate_page($newpage);
-
-                } else {
-                    // We just have a blockinfo field, this is a legacy 1.4 or 1.3 backup
-                    $blockrecords = get_records_select('block', '', '', 'name, id');
-                    $temp_blocks_l = array();
-                    $temp_blocks_r = array();
-                    @list($temp_blocks_l, $temp_blocks_r) = explode(':', $course_header->blockinfo);
-                    $temp_blocks = array(BLOCK_POS_LEFT => explode(',', $temp_blocks_l), BLOCK_POS_RIGHT => explode(',', $temp_blocks_r));
-                    foreach($temp_blocks as $blockposition => $blocks) {
-                        $blockweight = 0;
-                        foreach($blocks as $blockname) {
-                            if(!isset($blockrecords[$blockname])) {
-                                // We don't know anything about this block!
-                                continue;
-                            }
-                            $blockinstance = new stdClass;
-                            // Remove any - prefix before doing the name-to-id mapping
-                            if(substr($blockname, 0, 1) == '-') {
-                                $blockname = substr($blockname, 1);
-                                $blockinstance->visible = 0;
-                            }
-                            else {
-                                $blockinstance->visible = 1;
-                            }
-                            $blockinstance->blockid  = $blockrecords[$blockname]->id;
-                            $blockinstance->pageid   = $course_header->course_id;
-                            $blockinstance->pagetype = MOODLE_PAGE_COURSE;
-                            $blockinstance->position = $blockposition;
-                            $blockinstance->weight   = $blockweight;
-                            if(!$status = insert_record('block_instance', $blockinstance)) {
-                                notify('Error while creating the course blocks');
-                            }
-                            ++$blockweight;
-                        }
-                    }
-                }
-            }
-            else if($info->backup_block_format == 'instances') {
-                if(!$status = restore_create_block_instances($restore,$xml_file)) {
-                    notify('Error while creating the course blocks');
-                }
+            echo '<li>'.get_string('creatingblocks');
+            if (!$status = restore_create_blocks($restore, $xml_file)) {
+                notify("Error while creating the course blocks");
             }
         }
-        //Otherwise we are adding the backup into an existing course; do nothing
-        else {
-        }
     }
 
     //Now create the course_sections and their associated course_modules
index c4845451f91cea1185843ab7ec190a59bf084915..f107ac63191bcd891de97531f8423caedb821551 100644 (file)
         return $status;
     }
 
+    //This function creates all the block stuff when restoring courses
+    //It calls selectively to  restore_create_block_instances() for 1.5 
+    //and above backups. Upwards compatible with old blocks.
+    function restore_create_blocks($restore, $backup_block_format, $blockinfo, $xml_file) {
+
+        $status = true;
+
+        delete_records('block_instance', 'pageid', $restore->course_id, 'pagetype', MOODLE_PAGE_COURSE);
+        if (empty($backup_block_format)) {     // This is a backup from Moodle < 1.5
+            if (empty($blockinfo)) {
+                echo " from pre 1.3";                                 //debug
+                // Looks like it's from Moodle < 1.3. Let's give the course default blocks...
+                $newpage = page_create_object(MOODLE_PAGE_COURSE, $restore->course_id);
+                blocks_repopulate_page($newpage);
+            } else {
+                echo " from 1.3-1.4";                                 //debug
+                // We just have a blockinfo field, this is a legacy 1.4 or 1.3 backup
+                $blockrecords = get_records_select('block', '', '', 'name, id');
+                $temp_blocks_l = array();
+                $temp_blocks_r = array();
+                @list($temp_blocks_l, $temp_blocks_r) = explode(':', $blockinfo);
+                $temp_blocks = array(BLOCK_POS_LEFT => explode(',', $temp_blocks_l), BLOCK_POS_RIGHT => explode(',', $temp_blocks_r));
+                foreach($temp_blocks as $blockposition => $blocks) {
+                    $blockweight = 0;
+                    foreach($blocks as $blockname) { 
+                        if(!isset($blockrecords[$blockname])) {
+                            // We don't know anything about this block!
+                            continue;
+                        }
+                        $blockinstance = new stdClass;
+                        // Remove any - prefix before doing the name-to-id mapping
+                        if(substr($blockname, 0, 1) == '-') {
+                            $blockname = substr($blockname, 1);
+                            $blockinstance->visible = 0;
+                        } else {
+                            $blockinstance->visible = 1;
+                        }
+                        $blockinstance->blockid  = $blockrecords[$blockname]->id;
+                        $blockinstance->pageid   = $restore->course_id;
+                        $blockinstance->pagetype = MOODLE_PAGE_COURSE;
+                        $blockinstance->position = $blockposition;
+                        $blockinstance->weight   = $blockweight;
+                        if(!$status = insert_record('block_instance', $blockinstance)) {
+                            $status = false;
+                        }
+                        ++$blockweight;
+                    }
+                }
+            }
+        } else if($info->backup_block_format == 'instances') {
+            echo " from 1.5";                                 //debug
+            if(!$status = restore_create_block_instances($restore,$xml_file)) {
+                $status = false;
+            }
+        }
+
+        return $status;
+
+    } 
+
     //This function creates all the block_instances from xml when restoring in a
     //new course
     function restore_create_block_instances($restore,$xml_file) {
 
     function restore_precheck($id,$file,$silent=false) {
         
-        global $CFG;
+        global $CFG, $SESSION;
 
         //Prepend dataroot to variable to have the absolute path
         $file = $CFG->dataroot."/".$file;