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
This commit is contained in:
mudrd8mz
2009-03-02 21:36:50 +00:00
parent 9d86cefba4
commit cac526294c
2 changed files with 5 additions and 5 deletions
+1 -3
View File
@@ -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);
}
?>
+4 -2
View File
@@ -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();