report_customlang: regenerate foreign key after recent tables rename
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 15 Nov 2010 16:13:06 +0000 (16:13 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 15 Nov 2010 16:13:06 +0000 (16:13 +0000)
Thanks to Tim Hunt for spotting this overlooked key definition.

admin/report/customlang/db/install.xml
admin/report/customlang/db/upgrade.php
admin/report/customlang/version.php

index 3729c6c..361616b 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="admin/report/customlang/db" VERSION="20101112" COMMENT="XMLDB file for Moodle admin/report/customlang"
+<XMLDB PATH="admin/report/customlang/db" VERSION="20101115" COMMENT="XMLDB file for Moodle admin/report/customlang"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
 >
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="fk_component"/>
-        <KEY NAME="fk_component" TYPE="foreign" FIELDS="componentid" REFTABLE="customlang_components" REFFIELDS="id" PREVIOUS="primary"/>
+        <KEY NAME="fk_component" TYPE="foreign" FIELDS="componentid" REFTABLE="report_customlang_components" REFFIELDS="id" PREVIOUS="primary"/>
       </KEYS>
       <INDEXES>
         <INDEX NAME="uq_lang_component_string" UNIQUE="true" FIELDS="lang, componentid, stringid" COMMENT="For a given language and component, string identifiers must be unique"/>
       </INDEXES>
     </TABLE>
-    <TABLE NAME="report_customlang_components" COMMENT="Contains the list of all installed plugins that provide their own language pack " PREVIOUS="report_customlang">
+    <TABLE NAME="report_customlang_components" COMMENT="Contains the list of all installed plugins that provide their own language pack" PREVIOUS="report_customlang">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The normalized name of the plugin" PREVIOUS="id" NEXT="version"/>
@@ -37,4 +37,4 @@
       </KEYS>
     </TABLE>
   </TABLES>
-</XMLDB>
\ No newline at end of file
+</XMLDB>
index 48ac4fb..0a947db 100644 (file)
@@ -43,5 +43,19 @@ function xmldb_report_customlang_upgrade($oldversion) {
         upgrade_plugin_savepoint(true, 2010111200, 'report', 'customlang');
     }
 
+    /**
+     * Regenerate the foreign key after the tables rename
+     */
+    if ($oldversion < 2010111500) {
+        $table = new xmldb_table('report_customlang');
+        $oldkey = new xmldb_key('fk_component', XMLDB_KEY_FOREIGN, array('componentid'), 'customlang_components', array('id'));
+        $newkey = new xmldb_key('fk_component', XMLDB_KEY_FOREIGN, array('componentid'), 'report_customlang_components', array('id'));
+
+        $dbman->drop_key($table, $oldkey);
+        $dbman->add_key($table, $newkey);
+
+        upgrade_plugin_savepoint(true, 2010111500, 'report', 'customlang');
+    }
+
     return $result;
 }
index b060233..f55d828 100644 (file)
@@ -24,5 +24,5 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version  = 2010111200;
+$plugin->version  = 2010111500;
 $plugin->requires = 2010111002;