Skip to content

Commit

Permalink
MDL-50851 core_tag: fix db query failure on oracle (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Jan 14, 2016
1 parent 4bc9112 commit 721d665
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tag/classes/area.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,17 @@ public static function move_tags($component, $itemtype, $tagcollid) {
$cleanupcollections = $DB->get_fieldset_sql($sql, $params);

// Find all tags that are related to the tags being moved and make sure they are present in the target tagcoll.
$sql = "SELECT DISTINCT r.name, r.rawname, r.description, r.descriptionformat, ".
" r.userid, r.tagtype, r.flag ".
// 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, tagtype, flag ".
"FROM {tag} WHERE id IN ".
"(SELECT r.id ".
"FROM {tag_instance} ti ". // Instances that need moving.
"JOIN {tag} t ON t.id = ti.tagid AND t.tagcollid <> :tagcollid1 ". // Tags that need moving.
"JOIN {tag_instance} tr ON tr.itemtype = 'tag' and tr.component = 'core' AND tr.itemid = t.id ".
"JOIN {tag} r ON r.id = tr.tagid ". // Tags related to the tags that need moving.
"LEFT JOIN {tag} re ON re.name = r.name AND re.tagcollid = :tagcollid2 ". // Existing tags in the target tagcoll with the same name as related tags.
"WHERE ti.itemtype = :itemtype2 AND ti.component = :component2 ".
" AND re.id IS NULL"; // We need related tags that ARE NOT present in the target tagcoll.
" AND re.id IS NULL)"; // We need related tags that ARE NOT present in the target tagcoll.
$result = $DB->get_records_sql($sql, $params);
foreach ($result as $tag) {
$tag->tagcollid = $tagcollid;
Expand Down

0 comments on commit 721d665

Please sign in to comment.