fixing bugs in event table

This commit is contained in:
moodler 2006-01-31 08:37:00 +00:00
parent 799ce77d79
commit 001fc706ef
2 changed files with 85 additions and 23 deletions

View File

@ -1,5 +1,80 @@
<?
function migrate2utf8_event_name($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$event = get_record('event', 'id', $recordid)) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($event->courseid); //Non existing!
if ($event->userid) {
$userlang = get_user_lang($event->userid);
} else {
$userlang = get_main_teacher_lang($event->courseid);
}
$fromenc = get_original_encoding($sitelang, $courselang, $userlang);
/// We are going to use textlib facilities
/// Convert the text
$result = utfconvert($event->name, $fromenc);
$newevent = new object;
$newevent->id = $recordid;
$newevent->name = $result;
update_record('event',$newevent);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_event_description($recordid){
global $CFG;
/// Some trivial checks
if (empty($recordid)) {
log_the_problem_somewhere();
return false;
}
if (!$event = get_record('event', 'id', $recordid)) {
log_the_problem_somewhere();
return false;
}
$sitelang = $CFG->lang;
$courselang = get_course_lang($event->courseid); //Non existing!
if ($event->userid) {
$userlang = get_user_lang($event->userid);
} else {
$userlang = get_main_teacher_lang($event->courseid);
}
$fromenc = get_original_encoding($sitelang, $courselang, $userlang);
/// We are going to use textlib facilities
/// Convert the text
$result = utfconvert($event->description, $fromenc);
$newevent = new object;
$newevent->id = $recordid;
$newevent->description = $result;
update_record('event',$newevent);
/// And finally, just return the converted field
return $result;
}
function migrate2utf8_config_value($recordid){
global $CFG;
@ -868,7 +943,7 @@ function migrate2utf8_user_description($recordid){
$fromenc = get_original_encoding($sitelang, $courselang, $userlang);
/// We are going to use textlib facilities
/// Convert the text
$result = utfconvert($user->description, $fromenc);
@ -876,6 +951,7 @@ function migrate2utf8_user_description($recordid){
$newuser->id = $recordid;
$newuser->description = $result;
update_record('user',$newuser);
/// And finally, just return the converted field
return $result;
}

View File

@ -89,29 +89,15 @@
</TABLE>
<TABLE name="event">
<FIELDS>
<FIELD name="name" method="PLAIN_SQL_UPDATE" type="varchar" length="255">
<SQL_DETECT_USER>
SELECT e.userid
FROM {$CFG->prefix}event e
WHERE e.id = RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT e.courseid as course
FROM {$CFG->prefix}event e
WHERE e.id = RECORDID
</SQL_DETECT_COURSE>
<FIELD name="name" method="PHP_FUNCTION" type="varchar" length="255">
<PHP_FUNCTION>
migrate2utf8_event_name(RECORDID);
</PHP_FUNCTION>
</FIELD>
<FIELD name="description" method="PLAIN_SQL_UPDATE" type="text" length="0">
<SQL_DETECT_USER>
SELECT e.userid
FROM {$CFG->prefix}event e
WHERE e.id = RECORDID
</SQL_DETECT_USER>
<SQL_DETECT_COURSE>
SELECT e.courseid as course
FROM {$CFG->prefix}event e
WHERE e.id = RECORDID
</SQL_DETECT_COURSE>
<FIELD name="description" method="PHP_FUNCTION" type="text" length="0">
<PHP_FUNCTION>
migrate2utf8_event_description(RECORDID);
</PHP_FUNCTION>
</FIELD>
<FIELD name="modulename" method="NO_CONV" type="varchar" length="20" />
<FIELD name="eventtype" method="NO_CONV" type="varchar" length="20" />