General developer forum

Orpahned activities in Moodle 3.3

 
Picture of Lea Cohen
Orpahned activities in Moodle 3.3
 

We are upgrading our  Moodle instance from version 3.1 to 3.3.

We have many courses (more than 100) with orphaned activities (hundreds of them) . I understand that after the upgrade their sections will be visible. I've read about Stealth_activities, but it's not feasible for us to do the conversion one activity at a time for so many activities and courses.

Is there a script, or DB query, that can help us do this in bulk?

Alternatively, I see that in the get_last_section_number function in course/format/lib.php there is a check for $course->numsections:

$course = $this->get_course();
if (isset($course->numsections)) {
return $course->numsections;
}
But I event though these courses do have numsections defined in the DB, the check returns FALSE because apparently the code does'n't return them. Is there any way I can override some function and make the check return TRUE?



 
Average of ratings: Useful (1)
Picture of Marina Glancy
Re: Orpahned activities in Moodle 3.3
Core developersMoodle HQParticularly helpful MoodlersPlugin developersTesters

Lea, can you please explain what are you trying to convert?

 
Average of ratings: -
Picture of Lea Cohen
Re: Orpahned activities in Moodle 3.3
 
Hi Marina,

Thanks for your answer. I'll try to explain:

In our Moodle, which is run on version 3.1, we have courses in which there are many sections, but only a few of them are displayed. The rest of the sections have activities in them, and they are linked to from the visible sections (there were pedagogical reasons for building the sections  that way). The hiding of the rest of the sections is done by using the numsections attribute in the course.
For example, one of our courses has 6 sections, but numsections is set to 0 since all the activities in those sections are reached via links from the first section.

Now, we want to upgrade our Moodle to 3.3, and in that version, the numsections attribute is obsolete, which means that all those "orpahned" sections are now visible. If we want to keep them hidden, we have to go section by section and hide the sections, and then, for each activity, we have to make it available via the edit menu.

That's a lot of manual work, and I was wondering whether either of the following options is possible:
  1. Is there a script, or DB query, that can help us do this in bulk?
  2. I see that the get_last_section_number function in course/format/lib.php still has a check for $course->numsections, but it returns false (I quoted the code in my original question). Is there any way to override some function and make the check return TRUE?
Thank you
 
Average of ratings: -
Picture of Marina Glancy
Re: Orpahned activities in Moodle 3.3
Core developersMoodle HQParticularly helpful MoodlersPlugin developersTesters

Hi Lea,

Your message confused me so I have actually installed 3.1, created a course in it and then upgraded to 3.3 to check what happens.

As I expected, the sections that contained orphaned activities became invisible. However you say:

Now, we want to upgrade our Moodle to 3.3, and in that version, the 
numsections attribute is obsolete, which means that all those "orpahned"
 sections are now visible.

I do not see it. These sections are hidden and they should be hidden. Activities inside them are "stealth" which means that students can access them by following the URL - exactly the way orphaned activities used to behave.

At the same time the course settings the setting "Hidden sections" by default is "Hidden sections are shown in collapsed form". So the names of the hidden sections are shown to the students - they see something like "Topic 3 is not available".

Can you please confirm that you see the same? If so, try going to the course settings and, under "Course format" section, change "Hidden sections" to "Hidden sections are completely invisible". Will this solve the issue for you?

 
Average of ratings: Useful (3)
Picture of Lea Cohen
Re: Orpahned activities in Moodle 3.3
 

Hi Marina,


Wow, thank you so much for going to all that trouble!

I tried to follow your instructions regarding the "Hidden sections" setting, but unfortunately that didn't help.

I do think there might be a difference in the way I upgraded the system: I installed a fresh 3.3, made some modifications (mainly a theme and a few plugins), and then attached it to the DB of the 3.1 instance we had. Then I logged into the Moodle, and the system upgraded the DB.

Do you think that could that explain the different behavior in the hidden sections?

Thank you

 
Average of ratings: -
Picture of Lea Cohen
Re: Orpahned activities in Moodle 3.3
 

Hi Marina

I decided to check the upgrade doing it the way you described: upgrading the same site instead of creating a new site. I ran 2 tests, and I have conflicting results.

The first test:

  1. Installed a fresh copy of Moodle 3.1
  2. Imported from our site 3 courses which have orphaned sections. The import was successful, the sections stayed orphaned.
  3. Switched branch (git) and got latest version of 3.3 from Moodle on Github
  4. Installed (via FTP or CLI) a couple of course formats and themes that the courses needed.
  5. Went to the site and did the upgrade process successfully
  6. The sections became hidden and their activities are available to students. Success!
The second test:
  1. On our current site (3.1)
  2. I switched branch (git) and got latest version of 3.3 from Moodle on Github
  3. Installed (via FTP or CLI) all formats, themes, question types, etc. and assorted plugins that the courses needed.
  4. Went to the site and did the upgrade process successfully
  5. The sections stayed visible. Failure.
Since the process of getting the 3.3 version was the same in both tests, and the change was in the plugins installed (in the first test only about 5 plugins were installed, but in the second test we installed dozens of plugins), I'm thinking that some plugin was at fault. I don't know which plugin, and the process of elimination would be too tedious, but just updating this info here, in case someone has an insight on the issue.

 
Average of ratings: -