"Error reading from database" on Admin and Course pages after upgrade

"Error reading from database" on Admin and Course pages after upgrade

by Jason Fehr -
Number of replies: 6

I just completed the upgrade to Moodle 2.0.3+ (Build: 20110616) and all the pages under Site Administration and every course but one so far gives me the "Error reading from database" message with nothing else on the page.

I am comfortable working directly with the database if need be and have been playing with it trying to track down the problem. Even changing each field of a broken course in the the mdl_course table to the same entries of the one that isn't broken doesn't get past the "Error reading from database" message.

I was able to turn debugging on in the database and I get this message now as well:


Warning: array_key_exists() expects parameter 2 to be array, null given in /home/train/sites/moodle.gprc.ab.ca/www/moodle/lib/navigationlib.php on line 1298

 

Any help would be greatly appreciated, as I am lost here.

Average of ratings: -
In reply to Jason Fehr

Re: "Error reading from database" on Admin and Course pages after upgrade

by Jason Fehr -

Narrowed this down a little further. The pages I can see all have guest access. So for some reason although I am an administrator, and logged in, I don't have access to anything.

I tried resetting the password with the CLI tool to see if there was a salting issue. New password works, but still have the same issues.

Also for some reason after restarting my brower I am no longer getting the "array_key_exists()" error.

In reply to Jason Fehr

Re: "Error reading from database" on Admin and Course pages after upgrade

by Jason Fehr -

My problem was the non-standard Quickmail block. It worked fine on 2.02 running on my test server but no with 2.03 on my live server.

In reply to Jason Fehr

Re: "Error reading from database" on Admin and Course pages after upgrade

by John White -

Jason,
The bug you see in array_key_exists() is because the second parameter sent to the function is not always an array, its sometimes NULL I think!
But as yet I can't figure whether that's the navigation algorithm's fault or the data after conversion... I get the same bug. And I'm now leaning heavily towards the idea that its the data!
I can get rid of the bug by wrapping the two sections (that line and higher up) that make the call to array_key_exists() with
if (!empty($parentref['children'])) {
/// call here
}

Like this...

foreach ($parents as $parent) {
// test added to remove bug
if (!empty($parentref['children'])) {
if (!array_key_exists($parent, $parentref['children'])) {
$parentref['children'][$parent] = array('category'=>$categories[$parent], 'children'=>array());
}

$parentref = &$parentref['children'][$parent];
}
}
// test added to remove bug
if (!empty($parentref['children'])) {
if (!array_key_exists($category->id, $parentref['children'])) {
$parentref['children'][$category->id] = array('category'=>$category, 'children'=>array());
}
}

But I don't know what harm I'm masking with this, and I think it makes the navigator behave strangely!! HOWEVER, I think a big clue could be in the existence of a non-standard block or more likely activity pre-exisiting in 1.9+ before your upgrade, that you have not been able to upgrade the code for because that code doesn't yet exist!

I'll explore this idea a bit further with my own troubled dataset!

John

In reply to John White

Re: "Error reading from database" on Admin and Course pages after upgrade

by John White -

Jason,

I'm going to correct myself straight away: It's nothing to do with missing blocks or activities (as far as I can tell) as the navigation routine is not setting any such up at this stage. I'm narrowing it down by putting in loads of echos and var_dumps!

John

In reply to John White

Re: "Error reading from database" on Admin and Course pages after upgrade

by John White -

Jason,

The bug we both found in 2.0.3 navigation is a flaw in the navigation algorithm, although it has taken me all weekend to understand the algorithm and its bug! It certainly isn't related to your data, or its conversion, or missing old blocks or activities! I have reported the fault in a separate tracker entry as it does not relate to the PHP version supporting array_key_exists() either. So look at MDL-28040 to see the new report and a fix for it.

The if statements I suggested in this thread (above) do indeed only mask the problem and so they still leave the navigation tree emasculated by the bug effect... so don't use that route. The real problem is that using only the category's 'sortorder' field for sorting, as the algorithm currently does, means that parent categories can shift below their children, in the $categories array ...resulting in all the upper children being lost to the error.

A one line fix to /lib/navigationlib.php is given in the tracker.

Regards, John

In reply to John White

Re: "Error reading from database" on Admin and Course pages after upgrade

by John White -

Jason, In the same tracker MDL-28040 I have shown that even the one-line fix is not sufficient under particular circumstances, and hence I have supplied an alternative algorthim replacing one function in navigationlib.php for Moodle 2.0.3

Regards, John