Quantcast
Channel: Backup and restore
Viewing all articles
Browse latest Browse all 6815

Re: Issue with Course Restoration in Moodle 4.5.1

$
0
0
by Omar Ramon.  

Hi,

I had the same problem, but I'm not sure if commenting out those lines will always work. Course sections can be merged, and section numbers must be reorganized.

I'm testing a different temporary approach. In /backup/moodle2/restore_stepslib.php:1853, I modified the displace_delegated_sections_after function to update all section numbers in two steps: first assigning them temporary negative values to avoid conflicts, and then assigning the correct positive values in a second pass.


protected function displace_delegated_sections_after(int $sectionnum): void {
    global $DB;
 
    $sectionstomove = $DB->get_records_select(
        'course_sections',
        'course = ? AND component IS NOT NULL',
        [$this->get_courseid()],
        'section DESC', 'id, section'
    );
 
    $idxSection = $sectionnum;
    foreach ($sectionstomove as $section) {
        $sectionnum++;
        $section->section = -$sectionnum; // Temporary negative value to avoid conflicts
        $DB->update_record('course_sections', $section);
    }
 
    $sectionnum = $idxSection;
    foreach ($sectionstomove as $section) {
        $sectionnum++;
        $section->section = $sectionnum; // Assign correct positive value
        $DB->update_record('course_sections', $section);
    }
}

Activities are imported with their respective sub-sections, and sometimes a new sub-section is created instead of using an already existing one.

I would appreciate any feedback or suggestions on whether this approach will work reliably or if there’s a better way to handle this.


Viewing all articles
Browse latest Browse all 6815

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>