Moodle
  1. Moodle
  2. MDL-27696

Chart image generation fails in Participant - All logs activity report

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.3
    • Fix Version/s: 2.0.4, 2.1.1
    • Component/s: Course
    • Labels:
    • Database:
      Any
    • Testing Instructions:
      Hide

      1. Log in as an administrator or teacher
      2. Go to a course that has students enrolled
      3. Go to the participants page and pick one user
      4. In the navigation block, select the All logs activity report (Course -> Participants -> (picked user) -> Activity Reports -> All logs
      5. Check that a chart image appears above the table of activity.
      6. repeat for Today's logs

      Show
      1. Log in as an administrator or teacher 2. Go to a course that has students enrolled 3. Go to the participants page and pick one user 4. In the navigation block, select the All logs activity report (Course -> Participants -> (picked user) -> Activity Reports -> All logs 5. Check that a chart image appears above the table of activity. 6. repeat for Today's logs
    • Workaround:
      Hide

      Apply provided patches

      or

      Identify named parameters separately in get_logs_usercourse() in /lib/datalib.php and add an array called $days before the while loop in /course/report/log/graph.php

      Show
      Apply provided patches or Identify named parameters separately in get_logs_usercourse() in /lib/datalib.php and add an array called $days before the while loop in /course/report/log/graph.php
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE
    • Pull Master Branch:
      wip-MDL-27696-master
    • Rank:
      17356

      Description

      When attempting to view the All logs report under Course -> Participants -> (chosen participant) -> Activity reports -> All logs, the chart image is broken.

      This appears to be started in the call to get_logs_usercourse() at line 114 in /course/report/log/graph.php.

      Replication instructions:

      1. Log in as an administrator or teacher
      2. Go to a course that has students enrolled
      3. Go to the participants page and pick one user
      4. In the navigation block, select the All logs activity report (Course -> Participants -> (picked user) -> Activity Reports -> All logs

      The chart image appears broken (or hidden because it is broken). Viewing just the image displays the error which occurs when the image is being produced.

      1. All logs chart image patch.patch
        1 kB
        Michael de Raadt
      2. Graph fix patch.patch
        0.5 kB
        Michael de Raadt
      1. BrokenChart.png
        94 kB
      2. Error.png
        88 kB

        Issue Links

          Activity

          Hide
          Michael de Raadt added a comment -

          Broken chart image appears in Chrome but is hidden in Firefox. I'm not sure about other browsers.

          Show
          Michael de Raadt added a comment - Broken chart image appears in Chrome but is hidden in Firefox. I'm not sure about other browsers.
          Hide
          Michael de Raadt added a comment -

          I suspect this has something to do with the construction and use of the paramaters in $param for the query in get_logs_usercourse() in /lib/datalib, but I can't see where.

          Show
          Michael de Raadt added a comment - I suspect this has something to do with the construction and use of the paramaters in $param for the query in get_logs_usercourse() in /lib/datalib, but I can't see where.
          Hide
          Michael de Raadt added a comment -

          OK. The problem was that a named parameter was appearing multiple times in a query in /lib/datalib.php.

          When I fixed that problem, another appeared. In /course/report/log/graph.php, the array $days was array was not being instantiated until the loop starting at line 98. It is possible for the loop to not iterate when viewing the graph before the start of the course. The array $days must therefore be instantiated before the loop so that it exists when assigned to $graph->x_data at line 126.

          Smokin'!

          Show
          Michael de Raadt added a comment - OK. The problem was that a named parameter was appearing multiple times in a query in /lib/datalib.php. When I fixed that problem, another appeared. In /course/report/log/graph.php, the array $days was array was not being instantiated until the loop starting at line 98. It is possible for the loop to not iterate when viewing the graph before the start of the course. The array $days must therefore be instantiated before the loop so that it exists when assigned to $graph->x_data at line 126. Smokin'!
          Hide
          Sam Hemelryk added a comment -

          These is also a branch for MOODLE_21_STABLE
          branch: wip-MDL-27696-m21
          diff: https://github.com/samhemelryk/moodle/compare/MOODLE_21_STABLE...wip-MDL-27696-m21

          Show
          Sam Hemelryk added a comment - These is also a branch for MOODLE_21_STABLE branch: wip- MDL-27696 -m21 diff: https://github.com/samhemelryk/moodle/compare/MOODLE_21_STABLE...wip-MDL-27696-m21
          Hide
          Andrew Davis added a comment -

          Looks fine.

          Show
          Andrew Davis added a comment - Looks fine.
          Hide
          Petr Škoda added a comment -

          Integrated, thanks.

          Show
          Petr Škoda added a comment - Integrated, thanks.
          Hide
          Petr Škoda added a comment -

          I am getting:

          Debug info: ERROR: column "int19s_log.time" must appear in the GROUP BY clause or be used in an aggregate function
          LINE 1: SELECT FLOOR((time - $1)/86400) AS day, COUNT AS num
          ^
          SELECT FLOOR((time - $1)/86400) AS day, COUNT AS num
          FROM int19s_log
          WHERE userid = $2
          AND time > $3 AND course = $4
          GROUP BY FLOOR((time - $5)/86400)
          [array (
          0 => 1311026400,
          1 => '3',
          2 => 1311026400,
          3 => '3',
          4 => 1311026400,
          )]
          Stack trace:
          line 394 of /lib/dml/moodle_database.php: dml_read_exception thrown
          line 232 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end()
          line 678 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
          line 1855 of /lib/datalib.php: call to pgsql_native_moodle_database->get_records_sql()
          line 114 of /course/report/log/graph.php: call to get_logs_usercourse()

          I do not understand why is this happening though...

          Show
          Petr Škoda added a comment - I am getting: Debug info: ERROR: column "int19s_log.time" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: SELECT FLOOR((time - $1)/86400) AS day, COUNT AS num ^ SELECT FLOOR((time - $1)/86400) AS day, COUNT AS num FROM int19s_log WHERE userid = $2 AND time > $3 AND course = $4 GROUP BY FLOOR((time - $5)/86400) [array ( 0 => 1311026400, 1 => '3', 2 => 1311026400, 3 => '3', 4 => 1311026400, )] Stack trace: line 394 of /lib/dml/moodle_database.php: dml_read_exception thrown line 232 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end() line 678 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end() line 1855 of /lib/datalib.php: call to pgsql_native_moodle_database->get_records_sql() line 114 of /course/report/log/graph.php: call to get_logs_usercourse() I do not understand why is this happening though...
          Hide
          Petr Škoda added a comment -

          if nothing else works we may have to cast to int and embed the value in the sql directly.

          Show
          Petr Škoda added a comment - if nothing else works we may have to cast to int and embed the value in the sql directly.
          Hide
          Petr Škoda added a comment -

          I had to use (int) conversion to make it work in pg, the get_logs_userday() was broken too.

          Show
          Petr Škoda added a comment - I had to use (int) conversion to make it work in pg, the get_logs_userday() was broken too.
          Hide
          David Mudrak added a comment -

          Failed. Even with Petr's pgsql related fixes, only "Today's logs" work and display the chart. The chart is still broken in "All logs" report with the following notice in Apache error_log:

          PHP Notice: Undefined variable: days in /home/mudrd8mz/public_html/moodle21/course/report/log/graph.php on line 126, referer: http://glum/~mudrd8mz/moodle21/course/user.php?user=11&id=48&mode=alllogs

          Show
          David Mudrak added a comment - Failed. Even with Petr's pgsql related fixes, only "Today's logs" work and display the chart. The chart is still broken in "All logs" report with the following notice in Apache error_log: PHP Notice: Undefined variable: days in /home/mudrd8mz/public_html/moodle21/course/report/log/graph.php on line 126, referer: http://glum/~mudrd8mz/moodle21/course/user.php?user=11&id=48&mode=alllogs
          Hide
          David Mudrak added a comment -

          Aha. I believe the problem in "All logs" occur when it is a very fresh course and all activity happens in one day only. Adding

             $days = array();
          

          at the line 98 makes at least the empty chart displayed. But that is not enough as the actual number of record is not displayed in the course.

          Show
          David Mudrak added a comment - Aha. I believe the problem in "All logs" occur when it is a very fresh course and all activity happens in one day only. Adding $days = array(); at the line 98 makes at least the empty chart displayed. But that is not enough as the actual number of record is not displayed in the course.
          Hide
          Petr Škoda added a comment -

          arrays initialised, thanks!

          Show
          Petr Škoda added a comment - arrays initialised, thanks!
          Hide
          Petr Škoda added a comment -

          marking as tested, thanks everybody

          Show
          Petr Škoda added a comment - marking as tested, thanks everybody

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: