From: scyrma Date: Mon, 7 Jul 2008 06:40:35 +0000 (+0000) Subject: MDL-14772: Prevent official tags from being deleted when tag_instance table is empty... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a72529c73fc81e491a3fd978f155b37f2ffd746d;p=moodle.git MDL-14772: Prevent official tags from being deleted when tag_instance table is empty. (Patch by Hynek Černoch) (Merge from 1.9) --- diff --git a/tag/lib.php b/tag/lib.php index 4e2b1e27fa..0933f431d9 100644 --- a/tag/lib.php +++ b/tag/lib.php @@ -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 {