Merge branch 'MDL-65573-master-2' of git://github.com/peterRd/moodle
authorSara Arjona <sara@moodle.com>
Tue, 14 Jan 2020 11:20:00 +0000 (12:20 +0100)
committerSara Arjona <sara@moodle.com>
Tue, 14 Jan 2020 11:20:00 +0000 (12:20 +0100)
mod/forum/db/upgrade.php
mod/forum/post.php
mod/forum/version.php

index 6cdf26f..1446801 100644 (file)
@@ -220,8 +220,28 @@ function xmldb_forum_upgrade($oldversion) {
         upgrade_mod_savepoint(true, 2019100109, 'forum');
 
     }
+
     // Automatically generated Moodle v3.8.0 release upgrade line.
     // Put any upgrade step following this.
 
+    if ($oldversion < 2019111801) {
+        $sql = "SELECT d.id AS discussionid, p.userid AS correctuser
+                FROM {forum_discussions} d
+                INNER JOIN {forum_posts} p ON p.id = d.firstpost
+                WHERE d.userid <> p.userid";
+        $recordset = $DB->get_recordset_sql($sql);
+        foreach ($recordset as $record) {
+            $object = new stdClass();
+            $object->id = $record->discussionid;
+            $object->userid = $record->correctuser;
+            $DB->update_record('forum_discussions', $object);
+        }
+
+        $recordset->close();
+
+        // Forum savepoint reached.
+        upgrade_mod_savepoint(true, 2019111801, 'forum');
+    }
+
     return true;
 }
index d265d9a..7d9e3ab 100644 (file)
@@ -562,7 +562,7 @@ if (!empty($forum)) {
         $newdiscussion->forum        = $discussion->forum;
         $newdiscussion->name         = $name;
         $newdiscussion->firstpost    = $post->id;
-        $newdiscussion->userid       = $discussion->userid;
+        $newdiscussion->userid       = $post->userid;
         $newdiscussion->groupid      = $discussion->groupid;
         $newdiscussion->assessed     = $discussion->assessed;
         $newdiscussion->usermodified = $post->userid;
index 4f530f2..7d1f874 100644 (file)
@@ -24,6 +24,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2019111800;       // The current module version (Date: YYYYMMDDXX)
+$plugin->version   = 2019111801;       // The current module version (Date: YYYYMMDDXX)
 $plugin->requires  = 2019111200;       // Requires this Moodle version
 $plugin->component = 'mod_forum';      // Full name of the plugin (used for diagnostics)