-
Myriam Delaruelle authoredMyriam Delaruelle authored
upgrade.php 2.91 KiB
<?php
function xmldb_format_iena_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = TRUE;
if ($oldversion < 2021220900) {
//Support for old versions: we copy format options to the course_format_options table
try {
$sections= $DB->get_records_sql('select * FROM {format_iena}');
}
catch (dml_exception $e) {
echo "Aucun cours avec le format hybride dans la base";
}
if(count($sections) > 0){
foreach ($sections as $section) {
try {
$courseid = $DB->get_record_sql('select course FROM {course_sections} WHERE id=?', array($section->id_section));
$section_data = new stdClass();
$section_data->courseid = $courseid->course;
$section_data->format = "iena";
$section_data->sectionid = $section->id_section;
//On va faire pour présence, daterendu et daysnotif
$section_data->name = "presence";
$section_data->value = $section->presence;
$exists = $DB->get_record_sql('select * FROM {course_format_options} WHERE sectionid=? AND name="presence"', array($section->id_section));
if(!$exists){
$resultat = $DB->insert_record('course_format_options', $section_data, true);
}
$exists = $DB->get_record_sql('select * FROM {course_format_options} WHERE sectionid=? AND name="daterendu"', array($section->id_section));
if(!$exists){
if(isset($section->date_rendu)){
$section_data->name = "daterendu";
$section_data->value = strtotime($section->date_rendu);
$resultat = $DB->insert_record('course_format_options', $section_data, true);
}
}
$exists = $DB->get_record_sql('select * FROM {course_format_options} WHERE sectionid=? AND name="daysnotif"', array($section->id_section));
if(!$exists){
if(!empty($section->day_before)){
$section_data->name = "daysnotif";
$section_data->value = $section->nb_days_before;
$resultat = $DB->insert_record('course_format_options', $section_data, true);
}
}
}
catch (dml_exception $e) {
}
}
}
// Format_iena savepoint reached.
upgrade_plugin_savepoint(true, 2021070600,'format', 'iena');
}
return $result;
}
?>