From: toyomoyo Date: Thu, 25 May 2006 02:31:15 +0000 (+0000) Subject: merged backup-restore/db migrate for rsstitletemplate field X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7dbc6b589103835150c64ed4dc290eb1fe8e74eb;p=moodle.git merged backup-restore/db migrate for rsstitletemplate field --- diff --git a/mod/data/backuplib.php b/mod/data/backuplib.php index 280cd09fac..ab54da2f7a 100644 --- a/mod/data/backuplib.php +++ b/mod/data/backuplib.php @@ -85,6 +85,7 @@ function data_backup_one_mod($bf,$preferences,$data) { fwrite ($bf,full_tag("LISTTEMPLATE",4,false,$data->listtemplate)); fwrite ($bf,full_tag("ADDTEMPLATE",4,false,$data->addtemplate)); fwrite ($bf,full_tag("RSSTEMPLATE",4,false,$data->rsstemplate)); + fwrite ($bf,full_tag("RSSTITLETEMPLATE",4,false,$data->rsstitletemplate)); fwrite ($bf,full_tag("LISTTEMPLATEHEADER",4,false,$data->listtemplateheader)); fwrite ($bf,full_tag("LISTTEMPLATEFOOTER",4,false,$data->listtemplatefooter)); fwrite ($bf,full_tag("APPROVAL",4,false,$data->approval)); diff --git a/mod/data/db/migrate2utf8.php b/mod/data/db/migrate2utf8.php index 5dde2c3401..6e277964a8 100755 --- a/mod/data/db/migrate2utf8.php +++ b/mod/data/db/migrate2utf8.php @@ -328,6 +328,44 @@ function migrate2utf8_data_rsstemplate($recordid){ return $result; } +function migrate2utf8_data_rsstitletemplate($recordid){ + global $CFG, $globallang; + +/// Some trivial checks + if (empty($recordid)) { + log_the_problem_somewhere(); + return false; + } + + if (!$data = get_record('data','id',$recordid)) { + log_the_problem_somewhere(); + return false; + } + + if ($globallang) { + $fromenc = $globallang; + } else { + $sitelang = $CFG->lang; + $courselang = get_course_lang($data->course); //Non existing! + $userlang = get_main_teacher_lang($data->course); //N.E.!! + $fromenc = get_original_encoding($sitelang, $courselang, $userlang); + } + +/// We are going to use textlib facilities + +/// Convert the text + if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) { + $result = utfconvert($data->rsstitletemplate, $fromenc); + + $newdata= new object; + $newdata->id = $recordid; + $newdata->rsstitletemplate = $result; + migrate2utf8_update_record('data',$newdata); + } +/// And finally, just return the converted field + return $result; +} + function migrate2utf8_data_csstemplate($recordid){ global $CFG, $globallang; diff --git a/mod/data/db/migrate2utf8.xml b/mod/data/db/migrate2utf8.xml index fa48f5dd44..85bd0715b1 100755 --- a/mod/data/db/migrate2utf8.xml +++ b/mod/data/db/migrate2utf8.xml @@ -163,6 +163,11 @@ migrate2utf_data_rsstemplate(RECORDID) + + + migrate2utf_data_rsstitletemplate(RECORDID) + + migrate2utf_data_listtemplateheader(RECORDID) diff --git a/mod/data/restorelib.php b/mod/data/restorelib.php index 4251ad04e2..93def2de88 100644 --- a/mod/data/restorelib.php +++ b/mod/data/restorelib.php @@ -70,6 +70,7 @@ function data_restore_mods($mod,$restore) { $database->listtemplate = backup_todb($info['MOD']['#']['LISTTEMPLATE']['0']['#']); $database->addtemplate = backup_todb($info['MOD']['#']['ADDTEMPLATE']['0']['#']); $database->rsstemplate = backup_todb($info['MOD']['#']['RSSTEMPLATE']['0']['#']); + $database->rsstitletemplate = backup_todb($info['MOD']['#']['RSSTITLETEMPLATE']['0']['#']); $database->listtemplateheader = backup_todb($info['MOD']['#']['LISTTEMPLATEHEADER']['0']['#']); $database->listtemplatefooter = backup_todb($info['MOD']['#']['LISTTEMPLATEFOOTER']['0']['#']); $database->approval = backup_todb($info['MOD']['#']['APPROVAL']['0']['#']);