MDL-45439 reports Don't send contextlevel to legacy logging.
authorEric Merrill <merrill@oakland.edu>
Wed, 7 May 2014 01:43:32 +0000 (21:43 -0400)
committerDan Poltawski <dan@moodle.com>
Wed, 7 May 2014 03:10:19 +0000 (11:10 +0800)
It doesn't support the column.

report/log/classes/table_log.php

index 9c7fbee..f95c463 100644 (file)
@@ -340,6 +340,30 @@ class report_log_table_log extends table_sql {
         return array($sql, $params);
     }
 
+    /**
+     * Helper function which is used by build logs to get course module sql and param.
+     *
+     * @return array sql and param for action.
+     */
+    public function get_cm_sql() {
+        $joins = array();
+        $params = array();
+
+        if ($this->filterparams->logreader instanceof logstore_legacy\log\store) {
+            // The legacy store doesn't support context level.
+            $joins[] = "cmid = :cmid";
+            $params['cmid'] = $this->filterparams->modid;
+        } else {
+            $joins[] = "contextinstanceid = :contextinstanceid";
+            $joins[] = "contextlevel = :contextmodule";
+            $params['contextinstanceid'] = $this->filterparams->modid;
+            $params['contextmodule'] = CONTEXT_MODULE;
+        }
+
+        $sql = implode(' AND ', $joins);
+        return array($sql, $params);
+    }
+
     /**
      * Query the reader. Store results in the object for use by build_table.
      *
@@ -371,10 +395,9 @@ class report_log_table_log extends table_sql {
         }
 
         if (!empty($this->filterparams->modid)) {
-            $joins[] = "contextinstanceid = :contextinstanceid";
-            $joins[] = "contextlevel = :contextmodule";
-            $params['contextinstanceid'] = $this->filterparams->modid;
-            $params['contextmodule'] = CONTEXT_MODULE;
+            list($actionsql, $actionparams) = $this->get_cm_sql();
+            $joins[] = $actionsql;
+            $params = array_merge($params, $actionparams);
         }
 
         if (!empty($this->filterparams->action) || $useextendeddbindex) {