Error: could not find records

Error: could not find records

by Sebastien M. -
Number of replies: 9
Hello all:

CONTEXT: I just upgraded Moodle from 1.4.3 to 1.8.2+. I had 5 lessons with 1000+ enrolled students.

PROBLEM: When students are asked if they want to continue the lesson where they were when they last quit (i.e. jump to the last page they had seen in a lesson), they get the following error message:

-----
Error: could not find records
-----

Any idea what is causing this? (the function is working for starters but not for students enrolled before the upgrade)

I thank you all in advance for your most valuable assistance.

Seb
Average of ratings: -
In reply to Sebastien M.

Re: Error: could not find records

by Sebastien M. -
It appears that the error is caused by the timer feature in lesson/view.php (around line 420)

------------------------
// clock code
// get time information for this user
$timer = new stdClass;
if(!has_capability('mod/lesson:manage', $context)) {
if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) {
error('Error: could not find records');
} else {
$timer = array_pop($timer); // this will get the latest start time record
}
}
------------------------

However all timers are disabled (0) for my lessons... I am not sure to understand the purpose of the routine...

Any thoughts would be most appreciated.

Seb
In reply to Sebastien M.

Re: Error: could not find records

by Sebastien M. -
I turns out that the script is systematically interacting with the table timer_lesson (empty) even though I have disabled the timing feature. Perhaps for statistical purposes then?

Anyhow, is there any way to prevent all references to the timer_lesson table?

Would disabling the following be enough? Where should I do that in the setup?

---
if (!has_capability('mod/lesson:manage', $context))
---

Thanks.
In reply to Sebastien M.

Re: Error: could not find records

by Sacha Brostoff -
Hi!

Did you ever solve this problem? If so, how, if you don't mind me asking?

I am getting similar error messages.

Sacha
In reply to Sacha Brostoff

Re: Error: could not find records

by Sebastien M. -
Hello Sacha,

I don’t mind at all.

I had to disable (/* comment */) all sections that were trying to update the lesson_timer table. However, this will completely disable the timer feature and will impact all your ongoing lessons so make sure that you don’t use any timers. I guess that it would be better to embed the sections below in a conditional statement (e.g. if ($lesson->timed)) instead of commenting but I didn’t have the time to try it.

This fix was tried on v1.8.2+. Make sure you use Moodle’s debug feature before implementing this in order to ensure that it is the lesson_timer feature that is causing your problem.

Try this at your own risks as I am no php guru.



====> In mod/lesson/view.php

Comment the following (around line 420)
--------------------------------
// clock code
// get time information for this user
$timer = new stdClass;
if(!has_capability('mod/lesson:manage', $context)) {
if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) {
error('Error: could not find and/or insert records in lesson_timer');
} else {
$timer = array_pop($timer); // this will get the latest start time record
}
}

$startlastseen = optional_param('startlastseen', '', PARAM_ALPHA);
if ($startlastseen == 'yes') { // continue a previous test, need to update the clock (think this option is disabled atm)
$timer->starttime = time() - ($timer->lessontime - $timer->starttime);
$timer->lessontime = time();
} else if ($startlastseen == 'no') { // starting over
// starting over, so reset the clock
$timer->starttime = time();
$timer->lessontime = time();
}
--------------------------------

and about 20 lines below, below the “update the clock” title

--------------------------------

if (!update_record('lesson_timer', $timer)) {
error('Error: could not update lesson_timer table');
}

--------------------------------
====> in mod/lesson/action/continue.php

comment the following block:

$timer = new stdClass;
if (!has_capability('mod/lesson:manage', $context)) {
if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) {
error('Error: could not find records');
} else {
$timer = array_pop($timer); // this will get the latest start time record
}

if ($lesson->timed) {
if ((($timer->starttime + $lesson->maxtime * 60) - time()) starttime + $lesson->maxtime * 60) - time()) starttime + $lesson->maxtime * 60) starttime + $lesson->maxtime * 60) - time()) wwwroot/mod/lesson/view.php?id=$cm->id&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson"));
}
}

$timer->lessontime = time();
if (!update_record("lesson_timer", $timer)) {
error("Error: could not update lesson_timer table");
}
}

--------------------------------


Hope this helps!

S

----
NOTE: This fix is only for those who upgraded Moodle with an empty lesson_timer table.
In reply to Sebastien M.

Re: Error: could not find records

by Sacha Brostoff -
Sebastian, Hi!

I've tried out the fix on Moodle 1.9 dev (2007062008), and it's exciting progress! My moodle's no longer throwing out "Error: could not find records" when you go straight to a page within the lesson. However, if you do jump to an individual page then you now get the error message on the last page of the lesson, after clicking Continue .

Has anything like this happened to you?

All the best, and thanks again. It's really great to see things improving!

p.s. I'll be trying this on moodle 1.8 tomorrow, when I've got access to it again. I'll post the results.

Sacha
In reply to Sacha Brostoff

Re: Error: could not find records

by Sebastien M. -
Hello Sacha:

You are absolutely right. I had forgotten to comment out one more reference to the lesson_timer table:

====> IN lesson/view.php

around line 822, right after:
// end of lesson reached work out grade


Comment the following (or use the conditional statement)

------------
// Update the clock / get time information for this user

if (!has_capability('mod/lesson:manage', $context)) {
unset($USER->startlesson[$lesson->id]);
if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) {
error('Error: could not find records');
} else {
$timer = array_pop($timer); // this will get the latest start time record
}
$timer->lessontime = time();

if (!update_record("lesson_timer", $timer)) {
error("Error: could not update lesson_timer table");
}

------------

Thank's for reporting this! I just went live yesterday with 1000+ students!

Seb
In reply to Sebastien M.

Re: Error: could not find records

by Sacha Brostoff -
This is all a bit new to me - so apologies for being slow - I'll be switching on debugging too, and seeing what this 'trick' tells me.

Thanks again,

Sacha
In reply to Sacha Brostoff

Re: Error: could not find records

by Sebastien M. -
Make sure to use 2 different brand of browsers before switching to the debug mod because I got locked out one time. I use IE when logged as admin and FF2 for a dummy student account. I turn to debug mode just before the anticipated error, switch to FF, do the suspect operation and then view source to see the debug message... Maybe something I am missing... I am new to 1.8.2+ as well.

S