From a72529c73fc81e491a3fd978f155b37f2ffd746d Mon Sep 17 00:00:00 2001 From: scyrma Date: Mon, 7 Jul 2008 06:40:35 +0000 Subject: [PATCH] =?utf8?q?MDL-14772:=20Prevent=20official=20tags=20from=20?= =?utf8?q?being=20deleted=20when=20tag=5Finstance=20table=20is=20empty.=20?= =?utf8?q?(Patch=20by=20Hynek=20=C4=8Cernoch)=20(Merge=20from=201.9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- tag/lib.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 { -- 2.39.5