MDL-49795 tool_monitor: Add foreign keys to tool_monitor_events

This commit is contained in:
Kevin Pham
2022-08-03 15:17:04 +10:00
parent 2157cc74a4
commit 08564004ec
3 changed files with 35 additions and 2 deletions
+4 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="admin/tool/monitor/db" VERSION="20141103" COMMENT="XMLDB file for Moodle tool/monitor"
<XMLDB PATH="admin/tool/monitor/db" VERSION="20220530" COMMENT="XMLDB file for Moodle tool/monitor"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
@@ -76,6 +76,9 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="courseid" TYPE="foreign" FIELDS="courseid" REFTABLE="course" REFFIELDS="id"/>
<KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id"/>
<KEY NAME="contextinstanceid" TYPE="foreign" FIELDS="contextinstanceid" REFTABLE="context" REFFIELDS="instanceid"/>
</KEYS>
</TABLE>
</TABLES>
+30
View File
@@ -33,11 +33,41 @@ defined('MOODLE_INTERNAL') || die();
function xmldb_tool_monitor_upgrade($oldversion) {
global $CFG, $DB;
require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions.
$dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
// Automatically generated Moodle v3.9.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.0.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2022053000) {
// Define key courseid (foreign) to be added to tool_monitor_events.
$table = new xmldb_table('tool_monitor_events');
$key = new xmldb_key('courseid', XMLDB_KEY_FOREIGN, ['courseid'], 'course', ['id']);
// Launch add key courseid.
$dbman->add_key($table, $key);
// Define key contextid (foreign) to be added to tool_monitor_events.
$table = new xmldb_table('tool_monitor_events');
$key = new xmldb_key('contextid', XMLDB_KEY_FOREIGN, ['contextid'], 'context', ['id']);
// Launch add key contextid.
$dbman->add_key($table, $key);
// Define key contextinstanceid (foreign) to be added to tool_monitor_events.
$table = new xmldb_table('tool_monitor_events');
$key = new xmldb_key('contextinstanceid', XMLDB_KEY_FOREIGN, ['contextinstanceid'], 'context', ['instanceid']);
// Launch add key contextinstanceid.
$dbman->add_key($table, $key);
// Monitor savepoint reached.
upgrade_plugin_savepoint(true, 2022053000, 'tool', 'monitor');
}
return true;
}
+1 -1
View File
@@ -26,6 +26,6 @@
defined('MOODLE_INTERNAL') || die;
$plugin->version = 2022041900; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2022053000; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2022041200; // Requires this Moodle version.
$plugin->component = 'tool_monitor'; // Full name of the plugin (used for diagnostics).