by Ferenc Lengyel.
If you can run CLI scripts, then you can fix it. I only tested it on my dev environment as our test environment is now protected until we finish a big project. Still, hopefully, I will be able to test it later on a big, properly broken, almost live site and then fix our production site too.
The script is here:
admin/cli/fix_course_sequence.php
and this is how you should use it:
sudo -u www-data /usr/bin/php admin/cli/fix_course_sequence.php --courses=2,3,4 --fix
It finds all the 'orphaned' activities and moves them back to existing sections.
I hope it helps. Please let me know if it works for you.
Thanks