]> git.mjollnir.org Git - moodle.git/commitdiff
- Backup/restore and Import/export aliases.
authorwillcast <willcast>
Fri, 7 Nov 2003 15:58:29 +0000 (15:58 +0000)
committerwillcast <willcast>
Fri, 7 Nov 2003 15:58:29 +0000 (15:58 +0000)
mod/glossary/backuplib.php
mod/glossary/import.php
mod/glossary/lib.php
mod/glossary/restorelib.php

index 03ce86b6b554fbb4d7cc6b030dfdbb86792238f3..834c9cc71900634ca11695f328178fd864c95927 100644 (file)
     //                        |                                       |
     //                        |                                       |
     //                  glossary_entries -------------- glossary_entries_categories
-    //         (UL,pk->id, fk->glossaryid, files)      (UL, [pk->categoryid,entryid]
-    //                        |                                       
-    //                        |                                       
-    //                        |                                       
-    //                  glossary_comments
-    //              (UL,pk->id, fk->entryid)
+    //         (UL,pk->id, fk->glossaryid, files)      (UL, pk->categoryid,entryid]
+    //                        |             \                          
+    //                        |              \                         
+    //                        |               \                        
+    //                  glossary_comments      --------- glossary_alias 
+    //              (UL,pk->id, fk->entryid)            (UL, pk->id, pk->entryid)
     //
     //
     // Meaning: pk->primary key field of the table
                     fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$glo_ent->timemodified));
                     fwrite ($bf,full_tag("TEACHERENTRY",6,false,$glo_ent->teacherentry));
 
+                    $status = backup_glossary_aliases ($bf,$preferences,$glo_ent->id);
+
                     if ( $userinfo ) {
                         $status = backup_glossary_comments ($bf,$preferences,$glo_ent->id);
                     }
         return $status;
     }
    
+    //Backup glossary_alias contents (executed from backup_glossary_entries)
+    function backup_glossary_aliases ($bf,$preferences,$entryid) {
+
+        global $CFG;
+
+        $status = true;
+
+        $aliases = get_records("glossary_alias","entryid",$entryid);
+        if ($aliases) {
+            $status =fwrite ($bf,start_tag("ALIASES",6,true));
+            foreach ($aliases as $alias) {
+                $status =fwrite ($bf,start_tag("ALIAS",7,true));
+
+                fwrite ($bf,full_tag("NAME",8,false,$comment->id));
+
+                $status =fwrite ($bf,end_tag("ALIAS",7,true));        
+            }
+            $status =fwrite ($bf,end_tag("ALIASES",6,true));
+        }
+        return $status;
+    }
+
     //Backup glossary files because we've selected to backup user info
     //or current entry is a teacher entry
     function backup_glossary_files($bf,$preferences,$glossary,$entry) {
index a78f951cf6722182b7a39ca929ddf9d0d2e042cb..194520e172d5aca0435477d78aee731dafdd4405 100644 (file)
 
                 if ( $newentry->id = insert_record("glossary_entries",$newentry) )  {
                     $importedentries++;
+
+                    $xmlaliases = $xmlentry['#']['ALIASES'][0]['#']['ALIAS'];
+                    for($k = 0; $k < sizeof($xmlaliases); $k++) {
+                    /// Importing aliases
+                        $xmlalias = $xmlaliases[$k];
+                        unset($newalias);
+        
+                        $newalias->entryid = $newentry->id;
+                        $newalias->alias = $xmlalias['#']['NAME'][0]['#'];
+                        $newalias->id = insert_record("glossary_alias",$newalias));
+                    }
+
                     if ( $catsincl ) {
                         // If the categories must be imported...
                         $xmlcats = $xmlentry['#']['CATEGORIES'][0]['#']['CATEGORY'];
index 18f827097509ecaac2b8dfac53ec6928ae2d1196..ac6c2d37de4e4eb901d175eac81e4ada51033151 100644 (file)
@@ -1191,6 +1191,15 @@ global $CFG;
                     fwrite($h,glossary_full_tag("FULLMATCH",4,false,$entry->fullmatch));
                     fwrite($h,glossary_full_tag("TEACHERENTRY",4,false,$entry->teacherentry));
 
+                    if ( $aliases = get_records("glossary_alias","entryid",$entry->id) ) {
+                        $status = fwrite ($h,glossary_start_tag("ALIASES",4,true));
+                        foreach ($aliases as $alias) {
+                            $status = fwrite ($h,glossary_start_tag("ALIAS",5,true));
+                                fwrite($h,glossary_full_tag("NAME",6,false,$alias->alias));
+                            $status = fwrite($h,glossary_end_tag("ALIAS",5,true));
+                        }
+                        $status = fwrite($h,glossary_end_tag("CATEGORIES",4,true));
+                    }
                     if ( $catentries = get_records("glossary_entries_categories","entryid",$entry->id) ) {
                         $status = fwrite ($h,glossary_start_tag("CATEGORIES",4,true));
                         foreach ($catentries as $catentry) {
index 7d495a3efeb882a2cdfada60144c486ed0f9c8ae..c40d65268598de7218f59eb160225ba5cef6c4ed 100644 (file)
     //                        |                                       |
     //                  glossary_entries -------------- glossary_entries_categories
     //         (UL,pk->id, fk->glossaryid, files)      (UL, [pk->categoryid,entryid]
-    //                        |
-    //                        |
-    //                        |
-    //                  glossary_comments
-    //              (UL,pk->id, fk->entryid)
+    //                        |               \
+    //                        |                \
+    //                        |                 \
+    //                  glossary_comments        ------ glossary_alias
+    //              (UL,pk->id, fk->entryid)            (UL, pk->id, pk->entryid)
     //
     //
     // Meaning: pk->primary key field of the table
                 }
                 if ($newid) {
                    //We have the newid, update backup_ids
-                   backup_putid($restore->backup_unique_code,"glossary_entries",$oldid,$newid);
+                    backup_putid($restore->backup_unique_code,"glossary_entries",$oldid,$newid);
+                    //Restore glossary_alias
+                    $status = glossary_alias_restore_mods($oldid,$newid,$ent_info,$restore);
                     //Now restore glossary_comments
                     $status = glossary_comments_restore_mods($oldid,$newid,$ent_info,$restore);
                     //Now copy moddata associated files if needed
         return $status;
     }
 
+    //This function restores the glossary_alias table
+    function glossary_alias_restore_mods($old_entry_id,$new_entry_id,$info,$restore) {
+
+        global $CFG;
+
+        $status = true;    
+
+        //Get the comments array
+        $aliases = $info['#']['ALIASES']['0']['#']['ALIAS'];
+
+        //Iterate over comments
+        for($i = 0; $i < sizeof($aliases); $i++) {
+            $alias_info = $aliases[$i];
+
+            //Now, build the GLOSSARY_ALIAS record structure
+            $alias->entryid = $new_entry_id;
+            $alias->name = backup_todb($alias_info['#']['NAME']['0']['#']);
+
+            //The structure is equal to the db, so insert the glossary_comments
+            $newid = insert_record ("glossary_alias",$alias);
+
+            //Do some output
+            if (($i+1) % 50 == 0) {
+                echo ".";
+                if (($i+1) % 1000 == 0) {
+                    echo "<br>";
+                }
+                backup_flush(300);
+            }
+
+            if (!$newid) {
+                $status = false;
+            }
+        }
+
+        return $status;
+    }
+
     //This function restores the glossary_categories
     function glossary_categories_restore_mods($old_glossary_id,$new_glossary_id,$info,$restore) {