]> git.mjollnir.org Git - moodle.git/commitdiff
- Backup of categories and its entries
authorwillcast <willcast>
Sun, 21 Sep 2003 18:09:54 +0000 (18:09 +0000)
committerwillcast <willcast>
Sun, 21 Sep 2003 18:09:54 +0000 (18:09 +0000)
- Working on the restore process... Eloy will gives me a hand this (hopefully!)

mod/glossary/backuplib.php
mod/glossary/restorelib.php

index d3dac4a6f7663dcf8554a4fb4b73623bb76d56f1..5a8996c479d6c1df4cc1e114f86c07d064bc3331 100644 (file)
@@ -4,13 +4,13 @@
 
     //This is the "graphical" structure of the glossary mod:
     //
-    //                     glossary                                      
-    //                    (CL,pk->id)
-    //                        |
-    //                        |
-    //                        |
-    //                  glossary_entries 
-    //         (UL,pk->id, fk->glossaryid, files)
+    //                     glossary ---------------------- glossary_categories
+    //                    (CL,pk->id)                  (CL,pk->id,fk->glossaryid)
+    //                        |                                       |
+    //                        |                                       |
+    //                        |                                       |
+    //                  glossary_entries -------------- glossary_entries_categories
+    //         (UL,pk->id, fk->glossaryid, files)      (UL, [pk->categoryid,entryid]
     //
     // Meaning: pk->primary key field of the table
     //          fk->foreign key to link with parent
@@ -19,7 +19,7 @@
     //          UL->user level info
     //          files->table may have files)
     //
-    //-----------------------------------------------------------
+    //----------------------------------------------------------------------------------
 
     function glossary_backup_mods($bf,$preferences) {
         
                 fwrite ($bf,full_tag("SHOWALL",4,false,$glossary->showall));
                 fwrite ($bf,full_tag("TIMECREATED",4,false,$glossary->timecreated));
                 fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$glossary->timemodified));
-
+                
                 backup_glossary_entries($bf,$preferences,$glossary->id, $preferences->mods["glossary"]->userinfo);
 
+                backup_glossary_categories($bf,$preferences,$glossary->id, $preferences->mods["glossary"]->userinfo);
+
                 //End mod
                 $status =fwrite ($bf,end_tag("MOD",3,true));
             }
         return $status;
     }
 
+    //Backup glossary_categories and entries_categories contents (executed from glossary_backup_mods)
+    function backup_glossary_categories ($bf,$preferences,$glossary, $userinfo) {
+
+        global $CFG;
+
+        $status = true;
+
+        $glossary_categories = get_records("glossary_categories","glossaryid",$glossary,"id");
+        //If there is submissions
+        if ($glossary_categories) {
+            $status =fwrite ($bf,start_tag("CATEGORIES",4,true));
+
+            //Iterate over each category
+            foreach ($glossary_categories as $glo_cat) {
+                //Start category
+                //Print submission contents
+               $status =fwrite ($bf,start_tag("CATEGORY",5,true));
+
+               fwrite ($bf,full_tag("ID",6,false,$glo_cat->id));
+               fwrite ($bf,full_tag("GLOSSARYID",6,false,$glo_cat->glossaryid));
+               fwrite ($bf,full_tag("NAME",6,false,$glo_cat->name));
+
+                    $entries = get_records("glossary_entries_categories","categoryid",$glo_cat->id,"glossaryid");
+                    if ($entries) {
+                         $status =fwrite ($bf,start_tag("ENTRIES",6,true));
+                         foreach ($entries -> $entry) {
+                              fwrite ($bf,full_tag("ENTRYID",7,false,$entry->entryid));
+                         }
+                         $status =fwrite ($bf,end_tag("ENTRIES",6,true));
+                    }
+               $status =fwrite ($bf,end_tag("CATEGORY",5,true));
+
+            }
+               //Write end tag
+              $status =fwrite ($bf,end_tag("CATEGORIES",4,true));
+        }
+        return $status;
+    }
+
     //Backup glossary_entries contents (executed from glossary_backup_mods)
     function backup_glossary_entries ($bf,$preferences,$glossary, $userinfo) {
 
index 220a6ae87376f96d1154628c4fd4baee8c577a67..facf02c1c309e10d5b12381f6a317b5a83f08c93 100644 (file)
@@ -65,6 +65,7 @@
                 //Now check if want to restore user data and do it.
                 //Restore glossary_entries
                 $status = glossary_entries_restore_mods($mod->id,$newid,$info,$restore);
+//                $status = glossary_categories_restore_mods($mod->id,$newid,$info,$restore);
             } else {
                 $status = false;
             }
         return $status;
     }
 
+    //This function restores the glossary_categories and entries_categories
+    function glossary_categories_restore_mods($old_glossary_id,$new_glossary_id,$info,$restore) {
+
+        global $CFG;
+
+        $status = true;
+
+        //Get the categories array
+        $categories = $info['MOD']['#']['CATEGORIES']['0']['#']['CATEGORY'];
+
+        //Iterate over entries
+        for($i = 0; $i < sizeof($categories); $i++) {
+               $cat_info = $categories[$i];
+
+            //We'll need this later!!
+               $oldid = backup_todb($cat_info['#']['ID']['0']['#']);
+
+            //Now, build the GLOSSARY_CATEGORIES record structure
+               $category->glossaryid = $new_glossary_id;
+               $category->name = backup_todb($cat_info['#']['NAME']['0']['#']);
+
+               $newid = insert_record ("glossary_categories",$category);
+
+               //Do some output
+               if (($i+1) % 50 == 0) {
+                    echo ".";
+                    if (($i+1) % 1000 == 0) {
+                         echo "<br>";
+                    }
+                         backup_flush(300);
+                    }
+                    if ($newid) {
+                         //We have the newid, update backup_ids
+                         backup_putid($restore->backup_unique_code,"glossary_categories",$oldid,$newid);
+                         //Now copy moddata associated files if needed
+                    } else {
+                         $status = false;
+                    }
+
+               }
+        }
+
+        return $status;
+    }
+
     //This function copies the glossary related info from backup temp dir to course moddata folder,
     //creating it if needed and recoding everything (glossary id and entry id)
     function glossary_restore_files ($oldgloid, $newgloid, $oldentryid, $newentryid, $restore) {