Browse Source

Drop key doesn't work well, drop incorrect key and add correct one.

MOODLE_32_STABLE
Dan Marsden 8 years ago
parent
commit
b9c07817f6
  1. 2
      db/install.xml
  2. 63
      db/upgrade.php
  3. 2
      version.php

2
db/install.xml

@ -127,7 +127,7 @@
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="level_id" TYPE="unique" FIELDS="idnumber, warningpercent"/> <KEY NAME="level_id" TYPE="unique" FIELDS="idnumber, warningpercent, warnafter"/>
</KEYS> </KEYS>
</TABLE> </TABLE>
<TABLE NAME="attendance_warning_done" COMMENT="Warnings processed"> <TABLE NAME="attendance_warning_done" COMMENT="Warnings processed">

63
db/upgrade.php

@ -335,28 +335,6 @@ function xmldb_attendance_upgrade($oldversion=0) {
// Add new warning table. // Add new warning table.
if ($oldversion < 2016121315) { if ($oldversion < 2016121315) {
// 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. // Define table attendance_warning_done to be created.
$table = new xmldb_table('attendance_warning_done'); $table = new xmldb_table('attendance_warning_done');
@ -381,17 +359,44 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2016121315, 'attendance'); upgrade_mod_savepoint(true, 2016121315, 'attendance');
} }
if ($oldversion < 2016121317) { if ($oldversion < 2016121318) {
// Fix key. // Fix key.
$table = new xmldb_table('attendance_warning'); $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. // Attendance savepoint reached.
upgrade_mod_savepoint(true, 2016121317, 'attendance'); upgrade_mod_savepoint(true, 2016121318, 'attendance');
} }
return $result; return $result;

2
version.php

@ -23,7 +23,7 @@
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016121317; $plugin->version = 2016121318;
$plugin->requires = 2016111800; $plugin->requires = 2016111800;
$plugin->release = '3.2.14'; $plugin->release = '3.2.14';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;

Loading…
Cancel
Save