diff --git a/db/install.xml b/db/install.xml
index b310deb..482b8e0 100644
--- a/db/install.xml
+++ b/db/install.xml
@@ -127,7 +127,7 @@
-
+
diff --git a/db/upgrade.php b/db/upgrade.php
index 726ee36..04fd818 100644
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -335,28 +335,6 @@ function xmldb_attendance_upgrade($oldversion=0) {
// Add new warning table.
if ($oldversion < 2017050210) {
- // Define table attendance_warning to be created.
- $table = new xmldb_table('attendance_warning');
-
- // Adding fields to table attendance_warning.
- $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
- $table->add_field('idnumber', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
- $table->add_field('warningpercent', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
- $table->add_field('warnafter', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
- $table->add_field('emailuser', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null);
- $table->add_field('emailsubject', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
- $table->add_field('emailcontent', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
- $table->add_field('emailcontentformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null);
- $table->add_field('thirdpartyemails', XMLDB_TYPE_TEXT, null, null, null, null, null);
-
- // Adding keys to table attendance_warning.
- $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
-
- // Conditionally launch create table for attendance_warning.
- if (!$dbman->table_exists($table)) {
- $dbman->create_table($table);
- }
-
// Define table attendance_warning_done to be created.
$table = new xmldb_table('attendance_warning_done');
@@ -381,17 +359,44 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2017050210, 'attendance');
}
- if ($oldversion < 2017050212) {
+ if ($oldversion < 2017050213) {
// 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);
+ if (!$dbman->table_exists($table)) {
+ // Adding fields to table attendance_warning.
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+ $table->add_field('idnumber', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('warningpercent', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('warnafter', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('emailuser', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('emailsubject', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('emailcontent', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
+ $table->add_field('emailcontentformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('thirdpartyemails', XMLDB_TYPE_TEXT, null, null, null, null, null);
+
+ // 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, warnafter'));
+
+ // Conditionally launch create table for attendance_warning.
+ $dbman->create_table($table);
+
+ } else {
+ // Key definition is probably incorrect so fix it - drop_key dml function doesn't seem to work.
+ $indexes = $DB->get_indexes('attendance_warning');
+ foreach ($indexes as $name => $index) {
+ if ($DB->get_dbfamily() === 'mysql') {
+ $DB->execute("ALTER TABLE {attendance_warning} DROP INDEX ". $name);
+ } else {
+ $DB->execute("DROP INDEX ". $name);
+ }
+ }
+ $index = new xmldb_key('level_id', XMLDB_KEY_UNIQUE, array('idnumber, warningpercent', 'warnafter'));
+ $dbman->add_key($table, $index);
+ }
// Attendance savepoint reached.
- upgrade_mod_savepoint(true, 2017050212, 'attendance');
+ upgrade_mod_savepoint(true, 2017050213, 'attendance');
}
return $result;
diff --git a/version.php b/version.php
index fb968ba..9885e54 100644
--- a/version.php
+++ b/version.php
@@ -23,7 +23,7 @@
*/
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2017050212;
+$plugin->version = 2017050213;
$plugin->requires = 2017042100;
$plugin->release = '3.3.9';
$plugin->maturity = MATURITY_STABLE;