From cac526294c2eebde8d29a4d83774fe450f0d17d8 Mon Sep 17 00:00:00 2001 From: mudrd8mz Date: Mon, 2 Mar 2009 21:36:50 +0000 Subject: [PATCH] MDL-17492 Reset flag did not work in PostgreSQL Postgres does not seem to support table alias in UPDATE statement. Therefore the SQL like UPDATE mdl_tag tg SET tg.flag = 0, tg.timemodified = 1236027984 WHERE tg.id IN (4) ends with an ERROR: column "tg" of relation "mdl_tag" does not exist The fix is quite easy - just do not use table alias as it makes no sense here anyway. Besides this, the commit also fixes: * do not try to access the array key [0] in case of empty array (no tags exist yet) * do not require_capability() at the function level - it is already checked at the caller script level --- tag/lib.php | 4 +--- tag/locallib.php | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tag/lib.php b/tag/lib.php index bc14eeba4bc..9f723408ea8 100644 --- a/tag/lib.php +++ b/tag/lib.php @@ -992,13 +992,11 @@ function tag_set_flag($tagids) { function tag_unset_flag($tagids) { global $CFG; - require_capability('moodle/tag:manage', get_context_instance(CONTEXT_SYSTEM)); - if ( is_array($tagids) ) { $tagids = implode(',', $tagids); } $timemodified = time(); - return execute_sql("UPDATE {$CFG->prefix}tag tg SET tg.flag = 0, tg.timemodified = $timemodified WHERE tg.id IN ($tagids)", false); + return execute_sql("UPDATE {$CFG->prefix}tag SET flag = 0, timemodified = $timemodified WHERE id IN ($tagids)", false); } ?> diff --git a/tag/locallib.php b/tag/locallib.php index bef8a7e2fd0..615d189af1f 100644 --- a/tag/locallib.php +++ b/tag/locallib.php @@ -30,8 +30,10 @@ function tag_print_cloud($nr_of_tags=150, $return=false) { } $tagkeys = array_keys($tagsincloud); - $firsttagkey = $tagkeys[0]; - $maxcount = $tagsincloud[$firsttagkey]->count; + if (!empty($tagkeys)) { + $firsttagkey = $tagkeys[0]; + $maxcount = $tagsincloud[$firsttagkey]->count; + } $etags = array();