Best practice forum (Archived)

Fatal error: Class 'totara_dialog_content_courses' not found

 
Easter Island / Rapa Nui
Fatal error: Class 'totara_dialog_content_courses' not found
von Russell England – Friday, 29 August 2014, 7:43 AM
 

This is baffliing me, any ideas what could be wrong?

Its when I go to site admin -> users -> accounts -> audiences

Create a dynamic audience, go to the enrolled learning tab and click on add course or add programs

It will work initially if I restart the web server but then will fail again.

I've tried it on 2 servers and get the same error

PHP 5.5.3 with Apache 2.4.6

PHP 5.5.9 with nginx 1.4.6

Its a Totara 2.5.12.1 installation

The file is /totara/cohort/rules/ui.php 

require_once($CFG->dirroot.'/totara/core/dialogs/dialog_content_courses.class.php')

// Fatal error: Class 'totara_dialog_content_courses' not found in .../totara/cohort/rules/ui.php on line 1050
class totara_dialog_content_cohort_rules_courses extends totara_dialog_content_courses {

 

require_once($CFG->dirroot.'/totara/core/dialogs/dialog_content_courses.class.php')
// If I add this I get another error
if (!class_exists('totara_dialog_content_courses')) {

    // Fatal error: Cannot redeclare class totara_dialog_content_courses in
    // ../totara/core/dialogs/dialog_content_courses.class.php on line 43
    require($CFG->dirroot.'/totara/core/dialogs/dialog_content_courses.class.php');
}
class totara_dialog_content_cohort_rules_courses extends totara_dialog_content_courses {

Maria Torres
Re: Fatal error: Class 'totara_dialog_content_courses' not found
von Maria Torres – Monday, 1 September 2014, 2:26 PM
Gruppe Totara

Hi Russell,

Have you done some customization to the code or is it a new installation of T-2.5.12.1?

 

Regards,

Maria

 

 

Easter Island / Rapa Nui
Re: Fatal error: Class 'totara_dialog_content_courses' not found
von Russell England – Monday, 1 September 2014, 9:56 PM
 

Hi Maria, yes there has been customisation.

Maria Torres
Re: Fatal error: Class 'totara_dialog_content_courses' not found
von Maria Torres – Monday, 1 September 2014, 10:31 PM
Gruppe Totara

Hi Russell,

I came across the same original issue "Fatal error: Class 'totara_dialog_content_courses' not found in .../totara/cohort/rules/ui.php on line 1050" while modifying some things in programs. I was using a require_once($CFG->dirroot . '/totara/cohort/lib.php'); function at the top of the totara/program/lib.php file.

Could you please check if you have a reference to the cohort/lib(require_once($CFG->dirroot . '/totara/cohort/lib.php')) in one of your customised files? if so, could you please include the file only in the function you need and see if that solves the problem?.

To be honest, I don't know what could cause the issue, perhaps a wrong order of the included files.

Regards,
Maria

Easter Island / Rapa Nui
Re: Fatal error: Class 'totara_dialog_content_courses' not found
von Russell England – Monday, 1 September 2014, 11:24 PM
 

Spot on Maria!!

It's because of this - see comment #2 - https://bugs.totaralms.com/show_bug.cgi?id=12749#c2

I had put the require_once at the top of the file /totara/program/program.class.php

I've moved the require_once inside the function display_current_status() and the add courses popup now works

// Notify if there are courses in this program which don't have audience visibility to all.
if (!empty($CFG->audiencevisibility)) {
    require_once($CFG->dirroot . '/totara/cohort/lib.php'); // VISION - needed for constants.
    $coursesnovisible = $this->content->get_visibility_coursesets(TOTARA_SEARCH_OP_NOT_EQUAL, COHORT_VISIBLE_ALL);

? ?
Re: Fatal error: Class 'totara_dialog_content_courses' not found
von ? ? – Monday, 1 September 2014, 2:54 PM
 

"Fatal error: Cannot redeclare class totara_dialog_content_courses" would suggest that one of the includes before require_once($CFG->dirroot.'/totara/core/dialogs/dialog_content_courses.class.php') is already including and declaring the totara_dialog_content_courses class.

This shouldn't normally happen though. You could add a debug_print_backtrace() just before the totara_dialog_content_courses declaration to try and find out where it is being included from?

Easter Island / Rapa Nui
Re: Fatal error: Class 'totara_dialog_content_courses' not found
von Russell England – Monday, 1 September 2014, 10:51 PM
 

Hiya Ciaran

If I add the debug just before the declaration in /totara/core/dialogs/dialog_content_courses.class.php 

debug_print_backtrace();
class totara_dialog_content_courses extends totara_dialog_content {

and use

require_once($CFG->dirroot.'/totara/core/dialogs/dialog_content_courses.class.php');
class totara_dialog_content_cohort_rules_courses extends totara_dialog_content_courses {

then refresh the page at /totara/cohort/enrolledlearning.php?id=9 it displays the following at the top of the page

#0 require_once() called at [/var/www/totara/cohort/rules/ui.php:1044]
#1 require_once(/var/www/totara/cohort/rules/ui.php) called at [/var/www/totara/cohort/rules/settings.php:30]
#2 require_once(/var/www/totara/cohort/rules/settings.php) called at [/var/www/totara/cohort/rules/lib.php:32]
#3 require_once(/var/www/totara/cohort/rules/lib.php) called at [/var/www/cohort/lib.php:29]
#4 require_once(/var/www/cohort/lib.php) called at [/var/www/totara/cohort/enrolledlearning.php:31]

Then when I click add courses I get this error in the popup

( ! ) Fatal error: Class 'totara_dialog_content_courses' not found in /var/www/totara/cohort/rules/ui.php on line 1052
Call Stack
# Time Memory Function Location
1 0.0003 247912 {main}( ) ../browselearning.php:0
2 0.1011 17394816 require_once( '/var/www/totara/core/dialogs/dialog_content_courses.class.php' ) ../browselearning.php:26
3 0.1079 18374688 require_once( '/var/www/course/lib.php' ) ../dialog_content_courses.class.php:32
4 0.1096 18678856 require_once( '/var/www/lib/completionlib.php' ) ../lib.php:29
5 0.1112 18964920 require_once( '/var/www/completion/completion_completion.php' ) ../completionlib.php:36
6 0.1137 19463416 require_once( '/var/www/totara/plan/lib.php' ) ../completion_completion.php:50
7 0.1225 21166392 require_once( '/var/www/totara/program/lib.php' ) ../lib.php:33
8 0.1349 23723456 require_once( '/var/www/totara/program/program.class.php' ) ../lib.php:29
9 0.1801 32968400 require_once( '/var/www/totara/cohort/lib.php' ) ../program.class.php:38
10 0.1807 33081904 require_once( '/var/www/cohort/lib.php' ) ../lib.php:30
11 0.1824 33422800 require_once( '/var/www/totara/cohort/rules/lib.php' ) ../lib.php:29
12 0.1830 33572192 require_once( '/var/www/totara/cohort/rules/settings.php' ) ../lib.php:32
13 0.1857 34211336 require_once( '/var/www/totara/cohort/rules/ui.php' ) ../settings.php:30

If I try this

require_once($CFG->dirroot.'/totara/core/dialogs/dialog_content_courses.class.php');
if (!class_exists('totara_dialog_content_courses')) {
    require($CFG->dirroot.'/totara/core/dialogs/dialog_content_courses.class.php');
}
class totara_dialog_content_cohort_rules_courses extends totara_dialog_content_courses {

Refreshing the page gives the same trace as the refresh page above but clicking add courses gives me this in the popup

#0 require() called at [/var/www/totara/cohort/rules/ui.php:1049]
#1 require_once(/var/www/totara/cohort/rules/ui.php) called at [/var/www/totara/cohort/rules/settings.php:30]
#2 require_once(/var/www/totara/cohort/rules/settings.php) called at [/var/www/totara/cohort/rules/lib.php:32]
#3 require_once(/var/www/totara/cohort/rules/lib.php) called at [/var/www/cohort/lib.php:29]
#4 require_once(/var/www/cohort/lib.php) called at [/var/www/totara/cohort/lib.php:30]
#5 require_once(/var/www/totara/cohort/lib.php) called at [/var/www/totara/program/program.class.php:38]
#6 require_once(/var/www/totara/program/program.class.php) called at [/var/www/totara/program/lib.php:29]
#7 require_once(/var/www/totara/program/lib.php) called at [/var/www/totara/plan/lib.php:33]
#8 require_once(/var/www/totara/plan/lib.php) called at [/var/www/completion/completion_completion.php:50]
#9 require_once(/var/www/completion/completion_completion.php) called at [/var/www/lib/completionlib.php:36]
#10 require_once(/var/www/lib/completionlib.php) called at [/var/www/course/lib.php:29]
#11 require_once(/var/www/course/lib.php) called at [/var/www/totara/core/dialogs/dialog_content_courses.class.php:32]
#12 require_once(/var/www/totara/core/dialogs/dialog_content_courses.class.php) called at [/var/www/totara/cohort/dialog/browselearning.php:26]

#0 require_once() called at [/var/www/totara/cohort/dialog/browselearning.php:26]
( ! ) Fatal error: Cannot redeclare class totara_dialog_content_courses in /var/www/totara/core/dialogs/dialog_content_courses.class.php on line 43
Call Stack
# Time Memory Function Location
1 0.0003 247912 {main}( ) ../browselearning.php:0
2 0.0997 17394816 require_once( '/var/www/totara/core/dialogs/dialog_content_courses.class.php' ) ../browselearning.php:26

I put the question on stack overflow and one answer was that it could be because of a namespace? But I couldn't see any namespaces being used - http://stackoverflow.com/questions/25571045/require-once-fatal-error-class-not-found

Not sure this is related but I've switched off opcache in php.ini - http://stackoverflow.com/questions/25199912/redeclare-class-condition-info

[opcache]
opcache.enable = 0

Clutching at straws but if I replace require with require_once I get class not found

require_once($CFG->dirroot.'/totara/core/dialogs/dialog_content_courses.class.php');
if (!class_exists('totara_dialog_content_courses')) {
    require_once($CFG->dirroot.'/totara/core/dialogs/dialog_content_courses.class.php');

}
class totara_dialog_content_cohort_rules_courses extends totara_dialog_content_courses {

If I try replacing require_once with require I get the cannot redeclare class error

require($CFG->dirroot.'/totara/core/dialogs/dialog_content_courses.class.php');
class totara_dialog_content_cohort_rules_courses extends totara_dialog_content_courses {

I'm baffled...