From 5ab70be18297194615f70fce588f97d029729781 Mon Sep 17 00:00:00 2001 From: Kevin Pham Date: Mon, 28 Jun 2021 17:02:28 +1000 Subject: [PATCH] MDL-49795 mod_data: Add userid foreign key to data_records --- mod/data/db/install.xml | 3 ++- mod/data/db/upgrade.php | 14 +++++++++++++- mod/data/version.php | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/mod/data/db/install.xml b/mod/data/db/install.xml index 38f427a1c80b2..a9c9de292d1f4 100644 --- a/mod/data/db/install.xml +++ b/mod/data/db/install.xml @@ -1,5 +1,5 @@ - @@ -91,6 +91,7 @@ + diff --git a/mod/data/db/upgrade.php b/mod/data/db/upgrade.php index 1fb0b4c4ee35c..c7b0f7a615764 100644 --- a/mod/data/db/upgrade.php +++ b/mod/data/db/upgrade.php @@ -22,13 +22,25 @@ defined('MOODLE_INTERNAL') || die(); function xmldb_data_upgrade($oldversion) { - global $CFG; + global $DB; + + $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 userid (foreign) to be added to data_records. + $table = new xmldb_table('data_records'); + $key = new xmldb_key('userid', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']); + // Launch add key userid. + $dbman->add_key($table, $key); + + // Data savepoint reached. + upgrade_mod_savepoint(true, 2022053000, 'data'); + } return true; } diff --git a/mod/data/version.php b/mod/data/version.php index 38c62baa5b85f..4e74dfd484ace 100644 --- a/mod/data/version.php +++ b/mod/data/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$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->component = 'mod_data'; // Full name of the plugin (used for diagnostics) $plugin->cron = 0;