Skip to content

Commit

Permalink
MDL-54630 core_tags: preserve 'timemodified' when moving tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed May 19, 2016
1 parent 33892ed commit 1e03d74
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tag/classes/area.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public static function move_tags($component, $itemtype, $tagcollid) {

// 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.
Expand Down Expand Up @@ -424,7 +424,7 @@ public static function move_tags($component, $itemtype, $tagcollid) {

// 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
Expand Down
30 changes: 30 additions & 0 deletions tag/tests/taglib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,12 @@ public function test_move_tags_simple() {
$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'),
Expand All @@ -750,6 +756,12 @@ public function test_move_tags_split_tag() {
$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'),
Expand All @@ -775,6 +787,12 @@ public function test_move_tags_merge_tag() {
$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'),
Expand Down Expand Up @@ -802,6 +820,12 @@ public function test_move_tags_with_related() {
$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'),
Expand Down Expand Up @@ -848,6 +872,12 @@ public function test_move_tags_corrupted() {
$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));
Expand Down

0 comments on commit 1e03d74

Please sign in to comment.