MDL-69049 tool_dataprivacy: Add possibly missing comment format columns
authorJun Pataleta <jun@moodle.com>
Mon, 15 Jun 2020 14:47:22 +0000 (22:47 +0800)
committerJun Pataleta <jun@moodle.com>
Tue, 16 Jun 2020 01:25:03 +0000 (09:25 +0800)
The earlier CONTRIB plugin versions of the tool (<33.2.0, <34.2.0) were
missing the following columns in the data requests table:
* commentsformat
* dpocommentformat
And the upgrade scripts for the merged tool failed in
Moodle 3.3.8+/3.3.0+ failed to add these columns.
So a site which uses the CONTRIB plugin and eventually upgrading to 3.9
will encounter an error during upgrade because of the missing
dpocommentformat column.

admin/tool/dataprivacy/db/upgrade.php
admin/tool/dataprivacy/version.php

index e166cf6..30a9881 100644 (file)
@@ -322,10 +322,29 @@ function xmldb_tool_dataprivacy_upgrade($oldversion) {
     // Automatically generated Moodle v3.8.0 release upgrade line.
     // Put any upgrade step following this.
 
-    if ($oldversion < 2019121700) {
+    // Automatically generated Moodle v3.9.0 release upgrade line.
+    // Put any upgrade step following this.
 
-        // Define field systemapproved to be added to tool_dataprivacy_request.
+    if ($oldversion < 2020061501) {
+
+        // Define field commentsformat to be added to tool_dataprivacy_request.
         $table = new xmldb_table('tool_dataprivacy_request');
+        $field = new xmldb_field('commentsformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'comments');
+
+        // Conditionally launch add field commentsformat.
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        // Define field dpocommentformat to be added to tool_dataprivacy_request.
+        $field = new xmldb_field('dpocommentformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'dpocomment');
+
+        // Conditionally launch add field dpocommentformat.
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        // Define field systemapproved to be added to tool_dataprivacy_request.
         $field = new xmldb_field('systemapproved', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'dpocommentformat');
 
         // Conditionally launch add field systemapproved.
@@ -334,11 +353,8 @@ function xmldb_tool_dataprivacy_upgrade($oldversion) {
         }
 
         // Dataprivacy savepoint reached.
-        upgrade_plugin_savepoint(true, 2019121700, 'tool', 'dataprivacy');
+        upgrade_plugin_savepoint(true, 2020061501, 'tool', 'dataprivacy');
     }
 
-    // Automatically generated Moodle v3.9.0 release upgrade line.
-    // Put any upgrade step following this.
-
     return true;
 }
index 7925e88..1df48bc 100644 (file)
@@ -24,6 +24,6 @@
 
 defined('MOODLE_INTERNAL') || die;
 
-$plugin->version   = 2020061500;
+$plugin->version   = 2020061501;
 $plugin->requires  = 2020060900;
 $plugin->component = 'tool_dataprivacy';