From 700c4b1bfbeade058193307695ad209ad8eed968 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Thu, 13 Jul 2017 13:11:05 +1200 Subject: [PATCH] Allow warnings with same percentage but different warnlevel. --- db/upgrade.php | 14 +++++++++++++- version.php | 2 +- warnings.php | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/db/upgrade.php b/db/upgrade.php index 36fc683..726ee36 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -351,7 +351,6 @@ function xmldb_attendance_upgrade($oldversion=0) { // Adding keys to table attendance_warning. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('level_id', XMLDB_KEY_UNIQUE, array('idnumber, warningpercent')); // Conditionally launch create table for attendance_warning. if (!$dbman->table_exists($table)) { @@ -382,5 +381,18 @@ function xmldb_attendance_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2017050210, 'attendance'); } + if ($oldversion < 2017050212) { + // Fix key. + $table = new xmldb_table('attendance_warning'); + if ($table->getkey('level_id')) { + $table->deleteKey('level_id'); + } + $key = new xmldb_key('level_id', XMLDB_KEY_UNIQUE, array('idnumber, warningpercent, warnafter')); + $dbman->add_key($table, $key); + + // Attendance savepoint reached. + upgrade_mod_savepoint(true, 2017050212, 'attendance'); + } + return $result; } diff --git a/version.php b/version.php index d82687c..fb968ba 100644 --- a/version.php +++ b/version.php @@ -23,7 +23,7 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017050211; +$plugin->version = 2017050212; $plugin->requires = 2017042100; $plugin->release = '3.3.9'; $plugin->maturity = MATURITY_STABLE; diff --git a/warnings.php b/warnings.php index d9cde6b..eaa3bba 100644 --- a/warnings.php +++ b/warnings.php @@ -93,7 +93,8 @@ if ($data = $mform->get_data()) { $notify->thirdpartyemails = implode(',', $data->thirdpartyemails); } $existingrecord = $DB->record_exists('attendance_warning', array('idnumber' => $notify->idnumber, - 'warningpercent' => $notify->warningpercent)); + 'warningpercent' => $notify->warningpercent, + 'warnafter' => $notify->warnafter)); if (empty($existingrecord)) { $DB->insert_record('attendance_warning', $notify); echo $OUTPUT->notification(get_string('warningupdated', 'mod_attendance'), 'success');