Undefined constant error in restored courses

Undefined constant error in restored courses

by Peter F -
Number of replies: 9

We have recently upgraded to Moodle 4.3 from our previous version 3.1 that has been used for many years. We were performing the upgrade gradually and everything was fine till the 3.11 version. Since the 4.1, few courses were not upgraded properly, returning the following error: Exception – Undefined constant „ASSIGN_EVENT_TYPE_DUE“Now in 4.3, we try to bypass the problem by creating new courshells and restoring the content from old backups, with omitting calendar events and legacy course files. In some cases, this solves the problem, in some it does not. 

For these corrupted courses, even created as brand new in 4.3, there is no way to access them for any user, no matter the system role. The only thing admin can do through the course management is to create a course backup or restore it from backup, by deleting the previous content. Teachers who are assigned to such corrupted course will receive the very same error message -  Exception – Undefined constant „ASSIGN_EVENT_TYPE_DUE“ when trying to open their Moodle home page or Moodle Dashboard. What is absolutely weird that some courses, created in 4.3 and restored from older backups were first fine and after several days, they got corrupted on their own, showing the same error (no user made any updates to course content nor course settings).

Have not found much information on this error. The only thread where this error is mentioned is back from 2017 https://moodle.org/mod/forum/discuss.php?d=353347#p1426752.

Any suggestion what may cause the issue in 4.3? I assume there might be included some assignment, perhaps with very old due date. Nevertheless, I am surprised such an issue disables the whole course and even the dashboard. If there is anything I can specify, let me, please, know.

Thank you for any advice on this one.

Average of ratings: -
In reply to Peter F

Re: Undefined constant error in restored courses

by Ken Task -
Picture of Particularly helpful Moodlers

Advise turning on Debugging all the way to developer to see if moodle will report more info.

When you did the 'march' of your site, did you also have to upgrade PHP + extensions + add a PHP extension.

If you can, go to Site admin -> Server -> Environment and update the component.   Then look at the results below to see if moodle has any REDS or YELLOWS.

3rd party plugins have been known to create havoc ... themes are plugins.  If you are using a 3rd party theme for the site, suggest forcing the site to use boost - a theme that comes with core - by adding a line to config.php:

$CFG->theme='boost';

above the comments at the end of config.php file.

What other 3rd party plugins do you have installed?   Are they up to date with current core version as well?

'SoS', Ken

In reply to Ken Task

Re: Undefined constant error in restored courses

by Peter F -

Hello Ken!

Thank you for your prompt feedback! Find my updates below:

  • PHP extensions have been upgraded
  • I did check Site admin -> Server -> Environment as you adviced and we are in green status right now; Some PHP versions are higher than recommended, but I guess this is not a problem
  • Additional plugins - in previous version, we have used the BigBlueButton plugin. Although disabled and unavailable for instructors' use, it was included in the upgrade and now it is a part of our activity modules (still disabled). We were considering its full uninstall, however, as not being 100%-sure whether this could cause some global issue or not, we have decided to keep it in for now 
  • Theme - we use the Classic theme with adjusted theme_classic | backgroundimage and  theme_classic | brandcolor
In reply to Peter F

Re: Undefined constant error in restored courses

by Ken Task -
Picture of Particularly helpful Moodlers

Full debug turned on gives you no more info?

So originally the site was a 3.1.1 and you upgraded via steps to 4.1.highest.  

What you have now ... a 4.3.highest.   Is that right?

What steps did you take the site through in the 'march'?
http://www.syndrega.ch/blog/#php-and-dbms-compatibility-of-major-moodle-releases

I take it you did not stop at each hop upwards, check the site, then make a site backup?

Now we have a fresh 4.3 and attempting to restore course backups - which are of what type?

Full user or just course shells ... no one assigned ... mbz files have nu in the filenames?

Do you have command line access to your server?

Sorry if response isn't providing any solution, but I really can't tell where you are and what you've done ... nor what you are trying now!!!!

Even though you might now want to, am leaning to agree with Emma!    Start over ... yes, you up against crunch time ... put on some coffee! :|

'SoS', Ken

In reply to Ken Task

Re: Undefined constant error in restored courses

by Peter F -
Thanks Ken!!!

Don't worry, I was not expecting any one-step solutions, rather getting overall picture what had and what needs to be done. You have already helped a lot. As several people have been involved in the upgrade, I cannot provide all details you have been asking for. Here is what I can answer:

We are now at 4.3+ (Build: 20231201).
We did check at every stage of the upgrade and made backups at 3.6, 3.11 and 4.1.
Course backups used: both, automatically created .mbz files + private / manually created .mbz files with "nu" in the filenames

We all agree the only way to be 100%-sure things will work is to repeat the upgrade. Before that, what is your opinion on uninstalling the BigBlueButton module completely? Could it influence the system later while restoring? I mean, if the existing course backup contains BigBlueButton activities and we restore it to a version with BigBlueButton uninstalled, will it corrupt the new course shell?
In reply to Peter F

Re: Undefined constant error in restored courses

by Ken Task -
Picture of Particularly helpful Moodlers

Un-charted territory for me. :|

bigbluebuttonbn became part of core in version 4.0 of moodle

https://moodle.org/plugins/mod_bigbluebuttonbn
as an add-on-plugin:
https://moodle.org/plugins/mod_bigbluebuttonbn/versions
shows a BBB version 3.0.9 for Moodle 3.11
and part of a set:
https://moodle.org/plugins/browse.php?list=set&id=2
mod_bigbluebuttonbn and mod_recordingsbn

You said:

"We were performing the upgrade gradually and everything was fine till the 3.11 version. Since the 4.1, few courses were not upgraded properly, returning the following error: Exception – Undefined constant „ASSIGN_EVENT_TYPE_DUE“."

Error suggest something to do with calendar and mods/assignments due.

Suggest restoring your 3.11 sql dump to a new database.
Then query that database for anything related to BBB and courses that used it.  Can't tell you what issue would be, but you know the course ID's that are having issues right now so concentrate on those.   Moosh might be handy as it has a command for course info and backup info.

Comment: have never been in favor of hyperjumping.   Using git for moodle core versioning takes the pain out of hyperjumps and one can march a moodle through each higher version farily quickly.  You might catch exactly where the issue begins and address it at that point before upgrading further.

'SoS', Ken

In reply to Peter F

Re: Undefined constant error in restored courses

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

It appears to me that the problem occurred in 4.1 but you did not deal with it there and continued on upgrading a site with problems to 4.3.  I would suggest returning to 3.11 (hopefully you have backups) and then retrying the 4.1 upgrade.  Before upgrading, I would check all plugin compatibility and remove any additional themes and switch your site to boost.  4.x brought in a total ux overhaul and I would guess that maybe you have a theme or plugin that is not compatible with newer versions.

In reply to Emma Richardson

Re: Undefined constant error in restored courses

by Peter F -
Dear Emma,

I absolutely agree the problem roots in the 3.11 / 4.1 jump, unfortunately, we are in the phase where returing back to 3.11 and repeating the whole upgrade is out of the question, as the start of a new academic term is imminent.

As I have responded to Ken earlier, rather than theme, my guess is it is the BigBlueButton plugin that remained "alive" in the system. Although no longer available to users.

Anyway, I was also thinking about personal backups created by instructors throughought the years. As restoring courses is pretty frequent here, do you think such a back up file from the past (sometimes 4-5 yrs. old) could be a problem when saved in instructors' repositories and later imported to a new course shell with the backup file?
In reply to Peter F

Re: Undefined constant error in restored courses

by Danilo Nieto -

Greetings to all

The problem is in the code, in the mod/assing/lib.php file in the mod_assign_core_calendar_get_event_action_string function the file that contains the ASSIGN_EVENT_TYPE_DUE variable must be called, therefore two lines of code must be added before the switch:
global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');

image.png

In reply to Danilo Nieto

Re: Undefined constant error in restored courses

by Peter F -
Dear all,

thank you very much for your recommendations!

@Ken - based on what you have said, we decided to keep the BBB "alive". I thought this module was removed from the core after 3.11. But with these info, the complete uninstall is currently not needed.

@Danilo - we have adjusted php files as you have adviced and we will see. I regularly check courses that were previously corrupted by this issue. So far so good smile

Thanks again for your great help! As soon as I can provide any updates, I will let you know.