Browse Source

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

MOODLE_34_STABLE
Dan Marsden 8 years ago
parent
commit
334f042f0c
  1. 2
      db/install.xml
  2. 73
      db/upgrade.php
  3. 2
      version.php

2
db/install.xml

@ -127,7 +127,7 @@
</FIELDS>
<KEYS>
<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>
</TABLE>
<TABLE NAME="attendance_warning_done" COMMENT="Warnings processed">

73
db/upgrade.php

@ -341,35 +341,6 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2017060900, 'attendance');
}
// Add new warning table.
if ($oldversion < 2017061600) {
// 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);
}
// Attendance savepoint reached.
upgrade_mod_savepoint(true, 2017061600, 'attendance');
}
if ($oldversion < 2017062000) {
// Define table attendance_warning_done to be created.
@ -396,17 +367,45 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2017062000, 'attendance');
}
if ($oldversion < 2017071301) {
// Fix key.
if ($oldversion < 2017071305) {
// Define table attendance_warning to be created.
$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, 2017071301, 'attendance');
upgrade_mod_savepoint(true, 2017071305, 'attendance');
}
return $result;

2
version.php

@ -23,7 +23,7 @@
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017071301;
$plugin->version = 2017071305;
$plugin->requires = 2017042100;
$plugin->release = '3.3.9';
$plugin->maturity = MATURITY_ALPHA;

Loading…
Cancel
Save