Skip to content

Commit

Permalink
Fix foreign key violation (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Mar 9, 2020
1 parent 3ef47f0 commit 0cad226
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert"/>
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_template" REFFIELDS="id"/>
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_templates" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="customcert_templates" COMMENT="Stores each customcert template">
Expand Down Expand Up @@ -67,7 +67,7 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert_pages"/>
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_template" REFFIELDS="id"/>
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_templates" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="customcert_elements" COMMENT="Stores the elements for a given page">
Expand Down
20 changes: 20 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,25 @@ function xmldb_customcert_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2018051705, 'customcert');
}

if ($oldversion < 2019052003) {
$table = new xmldb_table('customcert');
$index = new xmldb_index('templateid', XMLDB_INDEX_UNIQUE, ['templateid']);
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
$key = new xmldb_key('templateid', XMLDB_KEY_FOREIGN, array('templateid'), 'customcert_templates', array('id'));
$dbman->add_key($table, $key);

$table = new xmldb_table('customcert_pages');
$index = new xmldb_index('templateid', XMLDB_INDEX_UNIQUE, ['templateid']);
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
$key = new xmldb_key('templateid', XMLDB_KEY_FOREIGN, array('templateid'), 'customcert_templates', array('id'));
$dbman->add_key($table, $key);

upgrade_main_savepoint(true, 2019052003);
}

return true;
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');

$plugin->version = 2019052002; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2019052003; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2019052000; // Requires this Moodle version (3.7).
$plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->component = 'mod_customcert';

$plugin->maturity = MATURITY_STABLE;
$plugin->release = "3.7.2"; // User-friendly version number.
$plugin->release = "3.7.3"; // User-friendly version number.

0 comments on commit 0cad226

Please sign in to comment.