]> git.mjollnir.org Git - moodle.git/commitdiff
filters: MDL-19000 don't do ORDER BY in subqueries (thanks Eloy)
authortjhunt <tjhunt>
Wed, 29 Apr 2009 03:12:31 +0000 (03:12 +0000)
committertjhunt <tjhunt>
Wed, 29 Apr 2009 03:12:31 +0000 (03:12 +0000)
Problem introduced by MDL-7336.

lib/filterlib.php

index 6639534ecad7b9b3d277c19507ecef9e155c2ed4..b9fbfec95b3d63a8054f9476a0ab411cf68d6109 100644 (file)
@@ -664,15 +664,16 @@ function filter_get_active_in_context($context) {
     // The following SQL is tricky. It is explained on
     // http://docs.moodle.org/en/Development:Filter_enable/disable_by_context
     $sql = "SELECT active.filter, fc.name, fc.value
-         FROM (SELECT f.filter
+         FROM (SELECT f.filter, MAX(f.sortorder) AS sortorder
              FROM {filter_active} f
              JOIN {context} ctx ON f.contextid = ctx.id
              WHERE ctx.id IN ($contextids)
              GROUP BY filter
              HAVING MAX(f.active * " . $DB->sql_cast_2signed('ctx.depth') .
                     ") > -MIN(f.active * " . $DB->sql_cast_2signed('ctx.depth') . ")
-             ORDER BY MAX(f.sortorder)) active
-         LEFT JOIN {filter_config} fc ON fc.filter = active.filter AND fc.contextid = $context->id";
+         ) active
+         LEFT JOIN {filter_config} fc ON fc.filter = active.filter AND fc.contextid = $context->id
+         ORDER BY active.sortorder";
     $rs = $DB->get_recordset_sql($sql);
 
     // Masssage the data into the specified format to return.
@@ -718,7 +719,7 @@ function filter_get_available_in_context($context) {
                 CASE WHEN fa.active IS NULL THEN " . TEXTFILTER_INHERIT . "
                 ELSE fa.active END AS localstate,
              parent_states.inheritedstate
-         FROM (SELECT f.filter,
+         FROM (SELECT f.filter, MAX(f.sortorder) AS sortorder,
                     CASE WHEN MAX(f.active * " . $DB->sql_cast_2signed('ctx.depth') .
                             ") > -MIN(f.active * " . $DB->sql_cast_2signed('ctx.depth') . ") THEN " . TEXTFILTER_ON . "
                     ELSE " . TEXTFILTER_OFF . " END AS inheritedstate
@@ -727,8 +728,9 @@ function filter_get_available_in_context($context) {
              WHERE ctx.id IN ($contextids)
              GROUP BY f.filter
              HAVING MIN(f.active) > " . TEXTFILTER_DISABLED . "
-             ORDER BY MAX(f.sortorder)) parent_states
-         LEFT JOIN {filter_active} fa ON fa.filter = parent_states.filter AND fa.contextid = $context->id";
+         ) parent_states
+         LEFT JOIN {filter_active} fa ON fa.filter = parent_states.filter AND fa.contextid = $context->id
+         ORDER BY parent_states.sortorder";
     return $DB->get_records_sql($sql);
 }