<commit_before><?PHP //$Id$
    //This php script contains all the stuff to backup/restore
    //forum mods

    //This is the "graphical" structure of the forum mod:
    //
    //                           forum                                      
    //                        (CL,pk->id)
    //                            |
    //             -----------------------------------        
    //             |                                 |
    //        subscriptions                    forum_discussions
    //    (UL,pk->id, fk->forum)             (UL,pk->id, fk->forum)
    //                                               |
    //                                               |
    //                                               |
    //                                           forum_posts
    //                             (UL,pk->id,fk->discussion,nt->parent,files) 
    //                                               |
    //                                               |
    //                                               |
    //                                          forum_ratings
    //                                      (UL,pk->id,fk->post)
    //
    // Meaning: pk->primary key field of the table
    //          fk->foreign key to link with parent
    //          nt->nested field (recursive data)
    //          CL->course level info
    //          UL->user level info
    //          files->table may have files)
    //
    //-----------------------------------------------------------

    function forum_restore_mods($mod,$restore) {

        global $CFG,$db;

        $status = true;

        //Get record from backup_ids
        $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);

        if ($data) {
            //Now get completed xmlized object
            $info = $data->info;
            //traverse_xmlize($info);                                                                     //Debug
            //print_object ($GLOBALS['traverse_array']);                                                  //Debug
            //$GLOBALS['traverse_array']="";                                                              //Debug

            //Now, build the FORUM record structure
            $forum->course = $restore->course_id;
            $forum->type = backup_todb($info['MOD']['#']['TYPE']['0']['#']);
            $forum->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
            $forum->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
            $forum->open = backup_todb($info['MOD']['#']['OPEN']['0']['#']);
            $forum->assessed = backup_todb($info['MOD']['#']['ASSESSED']['0']['#']);
            $forum->assesstimestart = backup_todb($info['MOD']['#']['ASSESSTIMESTART']['0']['#']);
            $forum->assesstimefinish = backup_todb($info['MOD']['#']['ASSESSTIMEFINISH']['0']['#']);
            $forum->scale = backup_todb($info['MOD']['#']['SCALE']['0']['#']);
            $forum->forcesubscribe = backup_todb($info['MOD']['#']['FORCESUBSCRIBE']['0']['#']);
            $forum->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);

            //We have to recode the scale field
            $scale = backup_getid($restore->backup_unique_code,"scale",$forum->scale);
            if ($scale) {
                $forum->scale = $scale->new_id;
            }

            //The structure is equal to the db, so insert the forum
            $newid = insert_record ("forum",$forum);

            //Do some output
            echo "<ul><li>".get_string("modulename","forum")." \"".$forum->name."\"<br>";
            backup_flush(300);

            if ($newid) {
                //We have the newid, update backup_ids<commit_msg>Changed to support "negative" values in scale field.<commit_after><?PHP //$Id$
    //This php script contains all the stuff to backup/restore
    //forum mods

    //This is the "graphical" structure of the forum mod:
    //
    //                           forum                                      
    //                        (CL,pk->id)
    //                            |
    //             -----------------------------------        
    //             |                                 |
    //        subscriptions                    forum_discussions
    //    (UL,pk->id, fk->forum)             (UL,pk->id, fk->forum)
    //                                               |
    //                                               |
    //                                               |
    //                                           forum_posts
    //                             (UL,pk->id,fk->discussion,nt->parent,files) 
    //                                               |
    //                                               |
    //                                               |
    //                                          forum_ratings
    //                                      (UL,pk->id,fk->post)
    //
    // Meaning: pk->primary key field of the table
    //          fk->foreign key to link with parent
    //          nt->nested field (recursive data)
    //          CL->course level info
    //          UL->user level info
    //          files->table may have files)
    //
    //-----------------------------------------------------------

    function forum_restore_mods($mod,$restore) {

        global $CFG,$db;

        $status = true;

        //Get record from backup_ids
        $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);

        if ($data) {
            //Now get completed xmlized object
            $info = $data->info;
            //traverse_xmlize($info);                                                                     //Debug
            //print_object ($GLOBALS['traverse_array']);                                                  //Debug
            //$GLOBALS['traverse_array']="";                                                              //Debug

            //Now, build the FORUM record structure
            $forum->course = $restore->course_id;
            $forum->type = backup_todb($info['MOD']['#']['TYPE']['0']['#']);
            $forum->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
            $forum->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
            $forum->open = backup_todb($info['MOD']['#']['OPEN']['0']['#']);
            $forum->assessed = backup_todb($info['MOD']['#']['ASSESSED']['0']['#']);
            $forum->assesstimestart = backup_todb($info['MOD']['#']['ASSESSTIMESTART']['0']['#']);
            $forum->assesstimefinish = backup_todb($info['MOD']['#']['ASSESSTIMEFINISH']['0']['#']);
            $forum->scale = backup_todb($info['MOD']['#']['SCALE']['0']['#']);
            $forum->forcesubscribe = backup_todb($info['MOD']['#']['FORCESUBSCRIBE']['0']['#']);
            $forum->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);

            //We have to recode the scale field if it's <0 (default now always)
            if ($forum->scale < 0) {
                $scale = backup_getid($restore->backup_unique_code,"scale",abs($forum->scale));
                if ($scale) {
                    $forum->scale = -($scale->new_id);
                }
            }

            //The structure is equal to the db, so insert the forum
            $newid = insert_record ("forum",$forum);

            //Do some output
            echo "<ul><li>".get_string("modulename","forum")." \"".$forum->name."\"<br>";
            backup_flush(300);

            if ($newid) {
                //We have the newid, update backup_ids
{'fraction_non_alphanumeric': 0.18687924725561944, 'fraction_numerical': 0.0036591740721380033, 'mean_word_length': 1.043524699599466, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 58, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5361887', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1799, 'n_words': 333}