-
DELARUELLE Myriam authoredDELARUELLE Myriam authored
upgrade.php 5.35 KiB
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
*
* Set setting for cron
*
* @package format_iena
* @copyright 2018 Softia/Université lorraine
* @author vrignaud camille
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function xmldb_format_iena_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
error_log($oldversion);
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));
$sectiondata = new stdClass();
$sectiondata->courseid = $courseid->course;
$sectiondata->format = "iena";
$sectiondata->sectionid = $section->id_section;
// On va faire pour présence, daterendu et daysnotif.
$sectiondata->name = "presence";
$sectiondata->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', $sectiondata, 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)) {
$sectiondata->name = "daterendu";
$sectiondata->value = strtotime($section->date_rendu);
$resultat = $DB->insert_record('course_format_options', $sectiondata, 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)) {
$sectiondata->name = "daysnotif";
$sectiondata->value = $section->nb_days_before;
$resultat = $DB->insert_record('course_format_options', $sectiondata, true);
}
}
} catch (dml_exception $e) {
}
}
}
// Format_iena savepoint reached.
upgrade_plugin_savepoint(true, 2021070600, 'format', 'iena');
}
if ($oldversion < 2024101505) {
error_log("on passe dans l'ancienne version");
// Define field id to be added to format_iena.
$table2 = new xmldb_table('format_iena_options');
$table2->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
$table2->add_field('optionname', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'id');
$table2->add_field('optionvalue', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'optionname');
$table2->add_field('courseid', XMLDB_TYPE_INTEGER, '8', null, XMLDB_NOTNULL, null, null, 'optionvalue');
$table2->add_field('userid', XMLDB_TYPE_INTEGER, '8', null, XMLDB_NOTNULL, null, null, 'courseid');
$table2->add_field('timecreated', XMLDB_TYPE_INTEGER, '16', null, XMLDB_NOTNULL, null, null, 'userid');
$table2->add_field('timemodified', XMLDB_TYPE_INTEGER, '16', null, null, null, null, 'timecreated');
$table2->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
// Conditionally launch add field id.
if (!$dbman->table_exists($table2)) {
error_log("on ajoute la table");
$dbman->create_table($table2);
}
else{
error_log("la table existe");
}
// Iena savepoint reached.
upgrade_plugin_savepoint(true, 2024101505, 'format','iena');
}
return $result;
}