MDL-54630 core_tags: preserve 'timemodified' when moving tags
authorMark Nelson <markn@moodle.com>
Wed, 18 May 2016 11:42:40 +0000 (19:42 +0800)
committerMark Nelson <markn@moodle.com>
Thu, 19 May 2016 06:50:12 +0000 (14:50 +0800)
tag/classes/area.php
tag/tests/taglib_test.php

index 93f16c1..a51b825 100644 (file)
@@ -390,7 +390,7 @@ class core_tag_area {
 
         // Find all tags that are related to the tags being moved and make sure they are present in the target tagcoll.
         // This query is a little complicated because Oracle does not allow to run SELECT DISTINCT on CLOB fields.
-        $sql = "SELECT name, rawname, description, descriptionformat, userid, isstandard, flag ".
+        $sql = "SELECT name, rawname, description, descriptionformat, userid, isstandard, flag, timemodified ".
                 "FROM {tag} WHERE id IN ".
                 "(SELECT r.id ".
                 "FROM {tag_instance} ti ". // Instances that need moving.
@@ -424,7 +424,7 @@ class core_tag_area {
 
         // Find all tags that are used for this itemtype/component and are not present in the target tag collection.
         // This query is a little complicated because Oracle does not allow to run SELECT DISTINCT on CLOB fields.
-        $sql = "SELECT id, name, rawname, description, descriptionformat, userid, isstandard, flag
+        $sql = "SELECT id, name, rawname, description, descriptionformat, userid, isstandard, flag, timemodified
                 FROM {tag} WHERE id IN
                 (SELECT t.id
                 FROM {tag_instance} ti
index 86cd213..efdba75 100644 (file)
@@ -731,6 +731,12 @@ class core_tag_taglib_testcase extends advanced_testcase {
         $tagarea = $DB->get_record('tag_area', array('itemtype' => 'user', 'component' => 'core'));
         core_tag_area::update($tagarea, array('tagcollid' => $collid2));
 
+        $tagsaftermove = $DB->get_records('tag');
+        foreach ($tagsaftermove as $tag) {
+            // Confirm that the time modified has not been unset.
+            $this->assertNotEmpty($tag->timemodified);
+        }
+
         $this->assertEquals(array('Tag4'),
                 $DB->get_fieldset_select('tag', 'rawname', 'tagcollid = ? ORDER BY name', array($collid1)));
         $this->assertEquals(array('Tag1', 'Tag2', 'Tag3', 'Tag5'),
@@ -750,6 +756,12 @@ class core_tag_taglib_testcase extends advanced_testcase {
         $tagareauser = $DB->get_record('tag_area', array('itemtype' => 'user', 'component' => 'core'));
         core_tag_area::update($tagareauser, array('tagcollid' => $collid2));
 
+        $tagsaftermove = $DB->get_records('tag');
+        foreach ($tagsaftermove as $tag) {
+            // Confirm that the time modified has not been unset.
+            $this->assertNotEmpty($tag->timemodified);
+        }
+
         $this->assertEquals(array('Tag1', 'Tag3', 'Tag4'),
                 $DB->get_fieldset_select('tag', 'rawname', 'tagcollid = ? ORDER BY name', array($collid1)));
         $this->assertEquals(array('Tag1', 'Tag2', 'Tag3', 'Tag5'),
@@ -775,6 +787,12 @@ class core_tag_taglib_testcase extends advanced_testcase {
         $tagareauser = $DB->get_record('tag_area', array('itemtype' => 'user', 'component' => 'core'));
         core_tag_area::update($tagareauser, array('tagcollid' => $collid2));
 
+        $tagsaftermove = $DB->get_records('tag');
+        foreach ($tagsaftermove as $tag) {
+            // Confirm that the time modified has not been unset.
+            $this->assertNotEmpty($tag->timemodified);
+        }
+
         $this->assertEquals(array('Tag4'),
                 $DB->get_fieldset_select('tag', 'rawname', 'tagcollid = ? ORDER BY name', array($collid1)));
         $this->assertEquals(array('TAG1', 'Tag2', 'Tag3', 'Tag5'),
@@ -802,6 +820,12 @@ class core_tag_taglib_testcase extends advanced_testcase {
         $tagarea = $DB->get_record('tag_area', array('itemtype' => 'user', 'component' => 'core'));
         core_tag_area::update($tagarea, array('tagcollid' => $collid2));
 
+        $tagsaftermove = $DB->get_records('tag');
+        foreach ($tagsaftermove as $tag) {
+            // Confirm that the time modified has not been unset.
+            $this->assertNotEmpty($tag->timemodified);
+        }
+
         $this->assertEquals(array('Tag1', 'Tag2', 'Tag4'),
                 $DB->get_fieldset_select('tag', 'rawname', 'tagcollid = ? ORDER BY name', array($collid1)));
         $this->assertEquals(array('TAG1', 'Tag2', 'Tag3', 'Tag4', 'Tag5'),
@@ -848,6 +872,12 @@ class core_tag_taglib_testcase extends advanced_testcase {
         $tagarea = $DB->get_record('tag_area', array('itemtype' => 'user', 'component' => 'core'));
         core_tag_area::update($tagarea, array('tagcollid' => $collid2));
 
+        $tagsaftermove = $DB->get_records('tag');
+        foreach ($tagsaftermove as $tag) {
+            // Confirm that the time modified has not been unset.
+            $this->assertNotEmpty($tag->timemodified);
+        }
+
         // Now all tags are correctly moved to the new collection and both tags 'Tag1' were merged.
         $user1tags = array_values(core_tag_tag::get_item_tags('core', 'user', $user1->id));
         $user2tags = array_values(core_tag_tag::get_item_tags('core', 'user', $user2->id));