]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10884, import is copying all grade_items into course, creating duplicate course...
authortoyomoyo <toyomoyo>
Mon, 20 Aug 2007 04:15:49 +0000 (04:15 +0000)
committertoyomoyo <toyomoyo>
Mon, 20 Aug 2007 04:15:49 +0000 (04:15 +0000)
backup/backuplib.php
backup/restorelib.php

index a0525462e3706ad1ab0442ef4a8ed992aef1c130..9ae6e10e7aa61e7cd12812651bf78ab8e9da4568 100644 (file)
 
                 // do not restore if this grade_item is a mod, and
                 if ($grade_item->itemtype == 'mod') {
-
-                    // if no user data selected, we skip this grade_item
-                    if (!backup_userdata_selected($preferences,$grade_item->itemmodule,$grade_item->iteminstance)) {
-                        continue;
-                    }
+                    // this still needs to be included, though grades and grades_text can be ignored
                 } else if ($grade_item->itemtype == 'category') {
                     // if not all grade items are being backed up
                     // we ignore this type of grade_item and grades associated
                 fwrite ($bf,full_tag("LOCKTIME",5,false,$grade_item->locktime));
 
                 // back up the other stuff here
-                $status = backup_gradebook_grades_info($bf,$preferences,$grade_item->id);
-                $status = backup_gradebook_grades_text_info($bf,$preferences,$grade_item->id);
-
+                // mod grades should only be backed up if selected
+                if ($grade_item->itemtype == 'mod' && backup_userdata_selected($preferences,$grade_item->itemmodule,$grade_item->iteminstance)) {
+                    $status = backup_gradebook_grades_info($bf,$preferences,$grade_item->id);
+                    $status = backup_gradebook_grades_text_info($bf,$preferences,$grade_item->id);
+                }
                 //End grade_item
                 fwrite ($bf,end_tag("GRADE_ITEM",4,true));
             }
index 68d5494226fb01aade89cfaf2c06b230c7d6c79b..08d583c2860b46596dbc0d54ae783777cbb4dbb5 100644 (file)
     //about each incidence
     function restore_create_gradebook($restore,$xml_file) {
 
-        global $CFG, $db;
+        global $CFG, $db, $SESSION;
 
         $status = true;
         //Check it exists
                                             "old_id, old_id",
                                             $counteritems,
                                             $recordset_size);
+                                            
                 if ($recs) {
                     foreach ($recs as $rec) {
                         //Get the full record from backup_ids
                         $data = backup_getid($restore->backup_unique_code,'grade_items',$rec->old_id);
                         if ($data) {
-
                             //Now get completed xmlized object
                             $info = $data->info;
                             //traverse_xmlize($info);                            //Debug
                             //$GLOBALS['traverse_array']="";                     //Debug
 
                             $dbrec->courseid = $restore->course_id;
-
-                            if (!empty($info['GRADE_ITEM']['#']['CATEGORYID']['0']['#'])) {
+                            
+                            if (isset($SESSION->restore->importing)) {
+                                // if we are importing, points all grade_items to the course category
+                                $coursecat = get_record('grade_categories', 'courseid', $restore->course_id, 'depth', 1);
+                                $dbrec->categoryid = $coursecat->id;
+                            } else if (!empty($info['GRADE_ITEM']['#']['CATEGORYID']['0']['#'])) {
                                 $category = backup_getid($restore->backup_unique_code,'grade_categories',backup_todb($info['GRADE_ITEM']['#']['CATEGORYID']['0']['#']));
                                 $dbrec->categoryid = $category->new_id;
                             }
                             /// this needs to point to either the new mod id
                             /// or the category id
                             $iteminstance = backup_todb($info['GRADE_ITEM']['#']['ITEMINSTANCE']['0']['#']);
-
                             // do not restore if this grade_item is a mod, and
                             if ($dbrec->itemtype == 'mod') {
 
-                                if (!restore_userdata_selected($restore,  $dbrec->itemmodule, $iteminstance)) {
-                                    // module instance not selected when restored using granular
-                                    // skip this item
-                                    $counteritems++;
-                                    continue;
-                                }
-
                                 // iteminstance should point to new mod
 
                                 $mod = backup_getid($restore->backup_unique_code,$dbrec->itemmodule, $iteminstance);
                                 // the item instance should point to the new grade category
 
                                 // only proceed if we are restoring all grade items
-                                if ($restoreall) {
+                                // need to skip for imports
+                                if ($restoreall && !isset($SESSION->restore->importing)) {
                                     $category = backup_getid($restore->backup_unique_code,'grade_categories', $iteminstance);
                                     $dbrec->iteminstance = $category->new_id;
                                 } else {
                                     // otherwise we can safely ignore this grade item and subsequent
                                     // grade_raws, grade_finals etc
+                                    $counteritems++;
                                     continue;
                                 }
                             } elseif ($dbrec->itemtype == 'course') { // We don't restore course type to avoid duplicate course items
-                                if ($restoreall) {
+                                if ($restoreall && !isset($SESSION->restore->importing)) {
                                     // TODO any special code needed here to restore course item without duplicating it?
                                     // find the course category with depth 1, and course id = current course id
                                     // this would have been already restored
 
+                                    // need to skip for imports
                                     $cat = get_record('grade_categories', 'depth', 1, 'courseid', $restore->course_id);
                                     $dbrec->iteminstance = $cat->id;
-
+                                    //$counteritems++;
+                                    //continue;
                                 } else {
+                                    $counteritems++;
                                     continue;
                                 }
                             }
                             $dbrec->locked = backup_todb($info['GRADE_ITEM']['#']['LOCKED']['0']['#']);
                             $dbrec->locktime = backup_todb($info['GRADE_ITEM']['#']['LOCKTIME']['0']['#']);
 
-
                             // get the current sortorder, add 1 to it and use that
                             if ($lastitem = get_record_sql("SELECT sortorder, id FROM {$CFG->prefix}grade_items
                                                         WHERE courseid = $restore->course_id
                             if ($itemid) {
                                 backup_putid($restore->backup_unique_code,'grade_items', backup_todb($info['GRADE_ITEM']['#']['ID']['0']['#']), $itemid);
                             }
+                            
+                            // no need to restore grades/grades_text if user data is not selected
+                            if (!restore_userdata_selected($restore,  $dbrec->itemmodule, $iteminstance)) {
+                                // module instance not selected when restored using granular
+                                // skip this item
+                                $counteritems++;
+                                continue;
+                            }
+                            
                             /// now, restore grade_grades, grade_text
                             if (!empty($info['GRADE_ITEM']['#']['GRADE_GRADES']['0']['#']) && ($grades = $info['GRADE_ITEM']['#']['GRADE_GRADES']['0']['#']['GRADE'])) {
                                 //Iterate over items
         }
 
         // process histories
-        if ($gchcount && $continue) {
+        if ($gchcount && $continue && !isset($SESSION->restore->importing)) {
             if (!defined('RESTORE_SILENTLY')) {
                 echo '<li>'.get_string('gradecategoryhistory','grades').'</li>';
             }
         }
 
         // process histories
-        if ($gghcount && $continue) {
+        if ($gghcount && $continue && !isset($SESSION->restore->importing)) {
             if (!defined('RESTORE_SILENTLY')) {
                 echo '<li>'.get_string('gradegradeshistory','grades').'</li>';
             }
 
         // process histories
 
-        if ($ggthcount && $continue) {
+        if ($ggthcount && $continue && !isset($SESSION->restore->importing)) {
             if (!defined('RESTORE_SILENTLY')) {
                 echo '<li>'.get_string('gradegradestexthistory','grades').'</li>';
             }
         }
 
         // process histories
-        if ($gihcount && $continue) {
+        if ($gihcount && $continue && !isset($SESSION->restore->importing)) {
             if (!defined('RESTORE_SILENTLY')) {
                 echo '<li>'.get_string('gradeitemshistory','grades').'</li>';
             }
         }
 
         // process histories
-        if ($gohcount && $continue) {
+        if ($gohcount && $continue && !isset($SESSION->restore->importing)) {
             if (!defined('RESTORE_SILENTLY')) {
                 echo '<li>'.get_string('gradeoutcomeshistory','grades').'</li>';
             }
                 && !empty($restore->mods[$modname]->instances[$modid]->userinfo);
         }
 
-        print_object($restore->mods[$modname]);
+        //print_object($restore->mods[$modname]);
         return !empty($restore->mods[$modname]->userinfo);
     }