]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14772: Prevent official tags from being deleted when tag_instance table is empty...
authorscyrma <scyrma>
Mon, 7 Jul 2008 06:40:35 +0000 (06:40 +0000)
committerscyrma <scyrma>
Mon, 7 Jul 2008 06:40:35 +0000 (06:40 +0000)
tag/lib.php

index 4e2b1e27fa0f0a61eb5d17eb0b26706541540829..0933f431d973c03399a2174278e80edc5d8bfb6f 100644 (file)
@@ -536,7 +536,7 @@ function tag_delete($tagids) {
 
 /**
  * Delete one instance of a tag.  If the last instance was deleted, it will
- * also delete the tag, unless it's type is 'official'.
+ * also delete the tag, unless its type is 'official'.
  *
  * @param string $record_type the type of the record for which to remove the instance
  * @param int $record_id the id of the record for which to remove the instance
@@ -547,11 +547,13 @@ function tag_delete_instance($record_type, $record_id, $tagid) {
     global $CFG, $DB;
 
     if ($DB->delete_records('tag_instance', array('tagid'=>$tagid, 'itemtype'=>$record_type, 'itemid'=>$record_id))) {
-        if (!$DB->record_exists_sql("SELECT *
-                                       FROM {tag} tg, {tag_instance} ti
-                                      WHERE (tg.id = ti.tagid AND ti.tagid = ? )
-                                            OR (tg.id = ? AND tg.tagtype = 'official')",
-                                     array($tagid, $tagid)) ) {
+        if (!$DB->record_exists_sql("SELECT * ".
+                                      "FROM {tag} tg ".
+                                     "WHERE tg.id = ? AND ( tg.tagtype = 'official' OR ".
+                                        "EXISTS (SELECT 1 
+                                                   FROM {tag_instance} ti 
+                                                  WHERE ti.tagid = ?) )", 
+                                     array($tagid, $tagid))) { 
             return tag_delete($tagid);
         }
     } else {