From e814e7d79c0e6115d8a03db2515eb2761cee3516 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Fri, 10 Aug 2007 05:22:20 +0000 Subject: [PATCH] MDL-10770, support null fields in backup/restore --- backup/backuplib.php | 8 ++++++-- backup/lib.php | 7 ++++++- backup/restorelib.php | 17 +++++++++++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/backup/backuplib.php b/backup/backuplib.php index d70c6e51d09..221d846939e 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -444,8 +444,12 @@ global $CFG; //Here we encode absolute links - $content = backup_encode_absolute_links($content); - + // MDL-10770 + if (is_null($content)) { + $content = '_NULL_'; + } else { + $content = backup_encode_absolute_links($content); + } $st = start_tag($tag,$level,$endline,$attributes); $co = xml_tag_safe_content($content); diff --git a/backup/lib.php b/backup/lib.php index 72b562b656a..52b08753819 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -538,7 +538,12 @@ //This function is used to add slashes (and decode from UTF-8 if needed) //It's used intensivelly when restoring modules and saving them in db function backup_todb ($data) { - return restore_decode_absolute_links(addslashes($data)); + // MDL-10770 + if ($data === '_NULL_') { + return null; + } else { + return restore_decode_absolute_links(addslashes($data)); + } } //This function is used to check that every necessary function to diff --git a/backup/restorelib.php b/backup/restorelib.php index 6ab234e0891..21bbcd2b04f 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -593,7 +593,7 @@ $course->shortname = addslashes($course_header->course_shortname); $course->idnumber = addslashes($course_header->course_idnumber); $course->idnumber = ''; //addslashes($course_header->course_idnumber); // we don't want this at all. - $course->summary = restore_decode_absolute_links(addslashes($course_header->course_summary)); + $course->summary = backup_todb($course_header->course_summary); $course->format = addslashes($course_header->course_format); $course->showgrades = addslashes($course_header->course_showgrades); $course->newsitems = addslashes($course_header->course_newsitems); @@ -882,7 +882,7 @@ $sequence = ""; $section->course = $restore->course_id; $section->section = $sect->number; - $section->summary = restore_decode_absolute_links(addslashes($sect->summary)); + $section->summary = backup_todb($sect->summary); $section->visible = $sect->visible; $section->sequence = ""; //Now calculate the section's newid @@ -1205,7 +1205,7 @@ } } } - } + } } // return if nothing to restore @@ -2215,7 +2215,7 @@ $user->address = addslashes($user->address); $user->city = addslashes($user->city); $user->url = addslashes($user->url); - $user->description = restore_decode_absolute_links(addslashes($user->description)); + $user->description = backup_todb($user->description); //We need to analyse the AUTH field to recode it: // - if the field isn't set, we are in a pre 1.4 backup and we'll @@ -3160,6 +3160,15 @@ global $CFG,$restore; + // MDL-10770 + // This function was replacing null with empty string + // Nullity check is added in backup_todb(), this function will no longer not be called from backup_todb() if content is null + // I noticed some parts of the restore code is calling this directly instead of calling backup_todb(), so just in case + // 3rd party mod etc are doing the same + if ($content === NULL) { + return NULL; + } + //Now decode wwwroot and file.php calls $search = array ("$@FILEPHP@$");