]> git.mjollnir.org Git - moodle.git/commitdiff
Now blockinfo is fully supported in backup & restore. For old backups
authorstronk7 <stronk7>
Tue, 20 Apr 2004 23:28:46 +0000 (23:28 +0000)
committerstronk7 <stronk7>
Tue, 20 Apr 2004 23:28:46 +0000 (23:28 +0000)
(without blockinfo field, default blocks are applied). Every block
visibility is mantained in the process.
Bump versions a bit (2004042100) :-)

backup/backuplib.php
backup/restorelib.php
backup/version.php
blocks/version.php
lib/blocklib.php

index e8724293ca2eb721dda9aeed5ef28e690ab3834f..eccc3513f215f13e2da5458fe2a1e3247bce9b06 100644 (file)
             fwrite ($bf,full_tag("SUMMARY",3,false,$course->summary));
             fwrite ($bf,full_tag("FORMAT",3,false,$course->format));
             fwrite ($bf,full_tag("SHOWGRADES",3,false,$course->showgrades));
+            fwrite ($bf,full_tag("BLOCKINFO",3,false,blocks_get_block_names($course->blockinfo)));
             fwrite ($bf,full_tag("NEWSITEMS",3,false,$course->newsitems));
             fwrite ($bf,full_tag("TEACHER",3,false,$course->teacher));
             fwrite ($bf,full_tag("TEACHERS",3,false,$course->teachers));
index 787d0eccad2a10813711951edfb3cff8f9d56668..54f51e587ec1ecce3f666bd8bed67423667624c9 100644 (file)
             $course->timecreated = addslashes($course_header->course_timecreated);
             $course->timemodified = addslashes($course_header->course_timemodified);
             //Adjust blockinfo field.
-            //NOTE: For now, it's imposible to find it in backup files because it isn't saved,
-            //      so, we always rebuid it with defaults.
+            //If the info doesn't exist in backup, we create defaults, else we recode it 
+            //to current site blocks.
             if (!$course->blockinfo) {
                 //Create blockinfo default content
                 if ($course->format == "social") {
                     //For topics and weeks formats (default built in the function)
                     $course->blockinfo = blocks_get_default_blocks();
                 }
+            } else {
+                $course->blockinfo = blocks_get_block_ids($course->blockinfo);
             }
             //Now insert the record
             $newid = insert_record("course",$course);
                         case "SHOWGRADES":
                             $this->info->course_showgrades = $this->getContents();
                             break;
+                        case "BLOCKINFO":
+                            $this->info->blockinfo = $this->getContents();
+                            break;
                         case "NEWSITEMS":
                             $this->info->course_newsitems = $this->getContents();
                             break;
index b32bfb1229ad2c95baf2f4688430e50f3164493c..9a207b5a820f407dfcdca4d92ecbce7436b5f778 100644 (file)
@@ -5,6 +5,6 @@
 // database (backup_version) to determine whether upgrades should
 // be performed (see db/backup_*.php)
 
-$backup_version = 2004041800;   // The current version is a date (YYYYMMDDXX)
+$backup_version = 2004042100;   // The current version is a date (YYYYMMDDXX)
 
 $backup_release = "1.3 development";  // User-friendly version number
index 5ed36ebe5587347515cbe6f91ada7b4dceaa67fc..3ccd3c1d9bc3cf6a39d5bdb1dacecc696e60af4f 100644 (file)
@@ -5,4 +5,4 @@
 // database (blocks_version) to determine whether upgrades should
 // be performed (see db/backup_*.php)
 
-$blocks_version = 2004041800;   // The current version is a date (YYYYMMDDXX)
+$blocks_version = 2004042100;   // The current version is a date (YYYYMMDDXX)
index a6fa5647792f0082af8fea5b89cc5726b314acaa..7453f1ba669af5ab9a26edacb3919d029667f967 100644 (file)
@@ -736,11 +736,16 @@ function blocks_get_default_blocks ($courseid = NULL, $blocknames="participants,
     if ($leftblocksn) {
         foreach($leftblocksn as $leftblockn) {
             //Convert blockname to id
-            $leftblock = block_get_id_by_name($leftblockn);
+            $leftblock = block_get_id_by_name(str_replace("-","",$leftblockn));
             if ($leftblock) {
                 //Check it's visible
                 if($block = get_record("blocks","id",$leftblock,"visible","1")) {
-                    $leftblocks[] = $leftblock;
+                    //Check if the module was hidden at course level
+                    if (substr($leftblockn,0,1) == "-") {
+                        $leftblocks[] = -$leftblock;
+                    } else  {
+                        $leftblocks[] = $leftblock;
+                    }
                 }
             }
         }
@@ -749,11 +754,16 @@ function blocks_get_default_blocks ($courseid = NULL, $blocknames="participants,
     if ($rightblocksn) {
         foreach($rightblocksn as $rightblockn) {
             //Convert blockname to id
-            $rightblock = block_get_id_by_name($rightblockn);
+            $rightblock = block_get_id_by_name(str_replace("-","",$rightblockn));
             if ($rightblock) {
                 //Check it's visible
                 if($block = get_record("blocks","id",$rightblock,"visible","1")) {
-                    $rightblocks[] = $rightblock;
+                    //Check if the module was hidden at course level
+                    if (substr($rightblockn,0,1) == "-") {
+                        $rightblocks[] = -$rightblock;
+                    } else {
+                        $rightblocks[] = $rightblock;
+                    }
                 }
             }
         }
@@ -781,4 +791,98 @@ function blocks_get_default_blocks ($courseid = NULL, $blocknames="participants,
     return $blockinfo;
 }
 
+//This function will return the names representation of the blockinfo field.
+//It's used to include that info in backups. To restore we'll use the
+//blocks_get_block_ids() function. It makes the opposite conversion
+//(from names to ids)
+function blocks_get_block_names ($blockinfo) {
+
+    //Calculate left and right blocks
+    $blocksn = $blockinfo;
+    $delimpos = strpos($blocksn, ':');
+
+    if($delimpos === false) {
+        // No ':' found, we have all left blocks
+        $leftblocksn = explode(',', $blocksn);
+        $rightblocksn = array();
+    } else if($delimpos === 0) {
+        // ':' at start of string, we have all right blocks
+        $blocksn = substr($blocksn, 1);
+        $leftblocksn = array();
+        $rightblocksn = explode(',', $blocksn);
+    }
+    else {
+        // Both left and right blocks
+        $leftpartn = substr($blocksn, 0, $delimpos);
+        $rightpartn = substr($blocksn, $delimpos + 1);
+        $leftblocksn = explode(',', $leftpartn);
+        $rightblocksn = explode(',', $rightpartn);
+    }
+
+    //Now I have blocks separated
+
+    $leftblocks = array();
+    $rightblocks = array();
+
+    if ($leftblocksn) {
+        foreach($leftblocksn as $leftblockn) {
+            //Convert id to blockname
+            $leftblock = block_get_name_by_id(abs($leftblockn));
+            if ($leftblock) {
+                //Check it's visible
+                if($block = get_record("blocks","name",$leftblock,"visible","1")) {
+                    //Check if it's hidden oe no in the course
+                    if($leftblockn<0) {
+                        $leftblocks[] = '-'.$leftblock;
+                    } else {
+                        $leftblocks[] = $leftblock;
+                    }
+                }
+            }
+        }
+    }
+
+    if ($rightblocksn) {
+        foreach($rightblocksn as $rightblockn) {
+            //Convert id to blockname
+            $rightblock = block_get_name_by_id(abs($rightblockn));
+            if ($rightblock) {
+                //Check it's visible
+                if($block = get_record("blocks","name",$rightblock,"visible","1")) {
+                    //Check if it's hidden oe no in the course
+                    if($rightblockn<0) {
+                        $rightblocks[] = '-'.$rightblock;
+                    } else {
+                        $rightblocks[] = $rightblock;
+                    }
+                }
+            }
+        }
+    }
+
+    //Calculate the blockinfo field
+    if ($leftblocks || $rightblocks) {
+        $blockinfo = '';
+        if ($leftblocks) {
+            $blockinfo .= implode(",", $leftblocks);
+        }
+        if ($rightblocks) {
+            $blockinfo .= ':'.implode(",",$rightblocks);
+        }
+    } else {
+        $blockinfo = '';
+    }
+
+    //Returns the blockinfo
+    return $blockinfo;
+}
+
+//This function will return the ids representation of the blockinfo field.
+//It's used to load that info from backups.  This function is the opposite
+//to the blocks_get_block_names() used in backup
+function blocks_get_block_ids ($blockinfo) {
+
+    //Just call this with the appropiate parammeters.
+    return blocks_get_default_blocks(NULL,$blockinfo);
+}
 ?>