Now blockinfo is fully supported in backup & restore. For old backups

(without blockinfo field, default blocks are applied). Every block
visibility is mantained in the process.
Bump versions a bit (2004042100) :-)
This commit is contained in:
stronk7
2004-04-20 23:28:46 +00:00
parent 5216e2c63c
commit 229f852a8a
5 changed files with 118 additions and 8 deletions
+1
View File
@@ -551,6 +551,7 @@
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));
+7 -2
View File
@@ -383,8 +383,8 @@
$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") {
@@ -393,6 +393,8 @@
//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);
@@ -1989,6 +1991,9 @@
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;
+1 -1
View 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
+1 -1
View 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)
+108 -4
View 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);
}
?>