MDL-49795 mod_book: Add foreign key for course

This commit is contained in:
Kevin Pham 2021-06-28 16:47:10 +10:00
parent af71e4f412
commit c2167257c9
3 changed files with 13 additions and 2 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/book/db" VERSION="20200907" COMMENT="XMLDB file for Moodle mod_book"
<XMLDB PATH="mod/book/db" VERSION="20220530" COMMENT="XMLDB file for Moodle mod_book"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@ -20,6 +20,7 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="course" TYPE="foreign" FIELDS="course" REFTABLE="course" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="book_chapters" COMMENT="Defines book_chapters">

View File

@ -48,6 +48,16 @@ function xmldb_book_upgrade($oldversion) {
// Automatically generated Moodle v4.0.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2022053000) {
// Define key course (foreign) to be added to book.
$table = new xmldb_table('book');
$key = new xmldb_key('course', XMLDB_KEY_FOREIGN, ['course'], 'course', ['id']);
// Launch add key course.
$dbman->add_key($table, $key);
// Book savepoint reached.
upgrade_mod_savepoint(true, 2022053000, 'book');
}
return true;
}

View File

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die;
$plugin->component = 'mod_book'; // Full name of the plugin (used for diagnostics)
$plugin->version = 2022041900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2022053000; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2022041200; // Requires this Moodle version.
$plugin->cron = 0; // Period for cron to check this module (secs)