PHP Error During Database Update

PHP Error During Database Update

by Slobodan Jovcic -
Number of replies: 12
Hi,

I'm upgrading from 1.5.2 to 1.5.3+ 2005060230 (latest CVS checkout from about an hour before this post). Database update fails on the second step with the error:

Fatal error: Call to undefined function category_parent_visible() in /web/moodle15/root/lib/datalib.php on line 2358

Page is admin/index.php. Hitting Refresh yields the same message. Update went through fine when I added:
include_once("../course/lib.php");

in the file lib/datalib.php (lines 2357 to 2359):
foreach ($categories as $key => $category) {
include_once("../course/lib.php");
if (!$category->visible || !category_parent_visible($category->parent)) {


Thoughts?
Average of ratings: -
In reply to Slobodan Jovcic

Re: PHP Error During Database Update

by Dan Eliot -

I'm getting the exact same error.  I did a CVS update and now my Moodle is broken.  Students can't use the website, any thoughts??

Exact Error I'm getting:

Fatal error: Call to undefined function: category_parent_visible() in /home_dir_here/lib/datalib.php on line 2358

In reply to Dan Eliot

Re: PHP Error During Database Update

by Timothy Takemoto -
category_parent_visible should be in the same file so I guess that the file datalib.php was only partially downloaded, or at that moment in time there was a glitch with CVS.
In reply to Slobodan Jovcic

Re: PHP Error During Database Update

by Patrick Li -
That was my fault. Those functions are now moved to datalib.

A cvs update would fix this problem.
In reply to Patrick Li

Re: PHP Error During Database Update

by Dan Eliot -

A CVS update was how I **GOT** the problem smile

Dan

In reply to Patrick Li

Re: PHP Error During Database Update

by Penny Leach -
Unfortunately, there is a delay between developer CVS and anonymous CVS, so doing a CVS update right now is not going to solve anything. I'm not sure how long this delay is, but in the meantime, attached are the correct files (course/lib.php and lib/datalib.php) .. just unzip this file into your moodle directory.

In reply to Penny Leach

Re: PHP Error During Database Update

by Dan Eliot -

Ahhhh... Thank you very much Penny... much appreciated.  My students have access now smile

Dan

In reply to Dan Eliot

Re: PHP Error During Database Update

by Penny Leach -
no problem smile

Next time you upgrade, run

cvs up -C course/lib.php lib/datalib.php

first, which will overwrite any local changes. Just in case cvs gets confused ;)

( -C means clobber )
In reply to Patrick Li

Re: PHP Error During Database Update

by Dan Eliot -

datalib.php is still Buggy.

Today, I created some new students and got the following error(s) at login:

<>

Warning

Dan


>: Invalid argument supplied for foreach()in /home/www/edhsonline/lib/datalib.php on line 2231
In reply to Dan Eliot

Re: PHP Error During Database Update

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I guess the problem is the new code that tries to hide courses marked as not visible. When the student is not enroled in any course (like your new student), that code produces the warning you are seeing (but is harmless otherwise).

I suppose something like the following might do the trick (just add the bold+underlined lines):
  if (!empty ($course)) {
      $courses = get_records_list('course', 'id', implode(',', $course));
      foreach ($courses as $k => $c) {
          if (empty($USER->admin) && (!$c->visible || !course_parent_visible($c))) {
              unset($course[$c->id]);
          }
      }
  }
Saludos. Iñaki.



In reply to Iñaki Arenaza

Re: PHP Error During Database Update

by Penny Leach -
I'm committing a patch to cvs shortly to fix this warning.

(It's benign, by the way)
In reply to Penny Leach

Re: PHP Error During Database Update

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I think the fix you commited on CVS is wrong. It tests whether count($courses) is greater than 0, but you should be testing count($course), as this is the array we fill in above the test. $courses is set below the test, from the database query. So someone should apply this to CVS:
--- datalib.php.orig    2005-12-30 14:57:15.000000000 +0100
+++ datalib.php 2005-12-30 14:57:31.000000000 +0100
@@ -2227,7 +2227,7 @@
$course[$student->course] = $student->course;
}
}
- if (count($courses) > 0) {
+ if (count($course) > 0) {
$courses = get_records_list('course', 'id', implode(',', $course));
foreach ($courses as $k => $c) {
if (empty($USER->admin) && (!$c->visible || !course_parent_visible($c))) {

Saludos. Iñaki.
In reply to Iñaki Arenaza

Re: PHP Error During Database Update

by Chin Yee -

How about:

    $courses = get_records_list('course', 'id', implode(',', $course));
    if (is_array($courses)) {
foreach ($courses as $k => $c) { if (empty($USER->admin) && (!$c->visible || !course_parent_visible($c))) { unset($course[$c->id]); } } }


My additions underlined.