]> git.mjollnir.org Git - moodle.git/commitdiff
Now STAMP fiel is supported in backup & restore.
authorstronk7 <stronk7>
Wed, 27 Aug 2003 17:09:01 +0000 (17:09 +0000)
committerstronk7 <stronk7>
Wed, 27 Aug 2003 17:09:01 +0000 (17:09 +0000)
If it exists in backup-file used, else, old search-by-name is used.
When inserting new categories, stamp is filled it it doesn't exist.
Updated version to 1.1 Beta +++ !!

backup/version.php
mod/quiz/backuplib.php
mod/quiz/restorelib.php

index b50d1d00c5cd525ba8f57b348e8285e6c12bde9e..26cb98170854724840885dcff45b600342a1a74e 100644 (file)
@@ -5,6 +5,6 @@
 // database (backup_version) to determine whether upgrades should
 // be performed (see db/backup_*.php)
 
-$backup_version = 2003082700;   // The current version is a date (YYYYMMDDXX)
+$backup_version = 2003082701;   // The current version is a date (YYYYMMDDXX)
 
-$backup_release = "1.1 Beta++";  // User-friendly version number
+$backup_release = "1.1 Beta +++";  // User-friendly version number
index 1f6cc1b55688d20568a704ed1b8e8f814693013f..75633a67995f4343c44c17c11174178f852486ca 100644 (file)
                 fwrite($bf,full_tag("NAME",4,false,$category->name));
                 fwrite($bf,full_tag("INFO",4,false,$category->info));
                 fwrite($bf,full_tag("PUBLISH",4,false,$category->publish));
+                fwrite($bf,full_tag("STAMP",4,false,$category->stamp));
                 //Now, backup their questions
                 $status = quiz_backup_question($bf,$preferences,$category->id);
                 //End category
index 22852b18adb5ec5569e642d394be75070255a1a5..505825a7af8ece17a17fdd9dd67035879909cbf4 100644 (file)
             $quiz_cat->name = backup_todb($info['QUESTION_CATEGORY']['#']['NAME']['0']['#']);
             $quiz_cat->info = backup_todb($info['QUESTION_CATEGORY']['#']['INFO']['0']['#']);
             $quiz_cat->publish = backup_todb($info['QUESTION_CATEGORY']['#']['PUBLISH']['0']['#']);
+            $quiz_cat->stamp = backup_todb($info['QUESTION_CATEGORY']['#']['STAMP']['0']['#']);
 
             //Now, we are going to do some calculations to decide when to create the category or no.
             //Based in the next logic:
             //Eloy's NOTE: I could be done code below more compact, but I've preffered do this to allow
             //easy future modifications.
 
-            //Check for categories and their properties, storing in temporary variables
-            //Count categories with the same name
-
-            $count_cat = count_records("quiz_categories","name",$quiz_cat->name);
-            //Count categories with the same name in the same course
-            $count_cat_same_course = count_records("quiz_categories","course",$restore->course_id,"name",$quiz_cat->name);
-            //Count categories with the same name in other course
-            $count_cat_other_course = $count_cat - $count_cat_same_course;
-
-            //Get categories with the same name in the same course
-            //The last record will be the oldest category
-            if ($count_cat_same_course > 0) {
-                $cats_same_course = get_records_sql("SELECT c.* FROM {$CFG->prefix}quiz_categories c
-                                                     WHERE c.course = '$restore->course_id' AND 
-                                                           c.name = '$quiz_cat->name'
-                                                     ORDER BY c.id DESC");
-            } else {
-                $cats_same_course = false;
-            }
-            //Get categories with the same name in other course
-            //The last record will be the oldest category with publish=1
-            if ($count_cat_other_course > 0) {
-                $cats_other_course = get_records_sql("SELECT c.* FROM {$CFG->prefix}quiz_categories c                           
-                                                      WHERE c.course != '$restore->course_id' AND 
-                                                            c.name = '$quiz_cat->name'
-                                                      ORDER BY c.publish ASC, c.id DESC");
-            } else {
-                $cats_other_course = false;
-            }
+            //If backup contains category_stamps then everythig is done by stamp (current approach from 1.1 final)
+            //else, everything is done by name (old approach). This mantains backward compatibility.
 
-            if ($count_cat == 0) {
-                //The category doesn't exist, create it.
-                //The structure is equal to the db, so insert the quiz_categories
-                $newid = insert_record ("quiz_categories",$quiz_cat);
-            } else {
-                //The category exist, check if it belongs to the same course
+            if ($quiz_cat->stamp) {
+                $restored_by = "(STAMP)";                          //Debug
+                //STAMP exists, do things using it (1.1)
+
+                //Check for categories and their properties, storing in temporary variables
+                //Count categories with the same stamp
+   
+                $count_cat = count_records("quiz_categories","stamp",$quiz_cat->stamp);
+                //Count categories with the same stamp in the same course
+                $count_cat_same_course = count_records("quiz_categories","course",$restore->course_id,"stamp",$quiz_cat->stamp);
+                //Count categories with the same stamp in other course
+                $count_cat_other_course = $count_cat - $count_cat_same_course;
+   
+                //Get categories with the same stamp in the same course 
                 if ($count_cat_same_course > 0) {
-                    //The category belongs to the same course, get the last record (oldest)
-                    foreach ($cats_same_course as $cat) {
-                        $newid = $cat->id;
-                    }
-                } else if ($count_cat_other_course > 0) {
-                    //The category belongs to other course, get the last record (oldest)
-                    foreach ($cats_other_course as $cat) {
-                        $other_course_cat = $cat;
-                    }
-                    //Now check th publish field
-                    if ($other_course_cat->publish == 0) {
-                        //The category has its publish to No (0). Create a new local one.
-                        $newid = insert_record ("quiz_categories",$quiz_cat);
+                    //Eloy's NOTE: Due to this select *must* be retrive only one record, we could have used get_record(), but
+                    //             mantain this to be as simmilar as possible with old code (comparing by name) to be
+                    //             able to modify both in the same manner.
+                    $cats_same_course = get_records_sql("SELECT c.* FROM {$CFG->prefix}quiz_categories c
+                                                         WHERE c.course = '$restore->course_id' AND
+                                                               c.stamp = '$quiz_cat->stamp'
+                                                         ORDER BY c.id DESC");
+
+                } else {
+                    $cats_same_course = false;
+                }
+                //Get category with the same stamp in other course
+                //The last record will be the oldest category with publish=1
+                if ($count_cat_other_course > 0) {
+                    $cats_other_course = get_records_sql("SELECT c.* FROM {$CFG->prefix}quiz_categories c
+                                                          WHERE c.course != '$restore->course_id' AND
+                                                                c.stamp = '$quiz_cat->stamp'
+                                                          ORDER BY c.publish ASC, c.id DESC");
+                } else {
+                    $cats_other_course = false;
+                }
+   
+                if ($count_cat == 0) {
+                    //The category doesn't exist, create it.
+                    //The structure is equal to the db, so insert the quiz_categories
+                    $newid = insert_record ("quiz_categories",$quiz_cat);
+                } else {
+                    //The category exist, check if it belongs to the same course
+                    if ($count_cat_same_course > 0) {
+                        //The category belongs to the same course, get the last record (oldest)
+                        foreach ($cats_same_course as $cat) {
+                            $newid = $cat->id;
+                        }
+                    } else if ($count_cat_other_course > 0) {
+                        //The category belongs to other course, get the last record (oldest)
+                        foreach ($cats_other_course as $cat) {
+                            $other_course_cat = $cat;
+                        }
+                        //Now check the publish field
+                        if ($other_course_cat->publish == 0) {
+                            //The category has its publish to No (0). Create a new local one.
+                            $newid = insert_record ("quiz_categories",$quiz_cat);
+                        } else {
+                            //The category has its publish to Yes(1). Use it.
+                            $newid = $other_course_cat->id;
+                        }
                     } else {
-                        //The category has its publish to Yes(1). Use it.
-                        $newid = $other_course_cat->id;
+                        //We must never arrive here !!
+                        $status = false;
                     }
+                }
+            } else {
+                $restored_by = "(NAME)";                          //Debug
+                //STAMP doesn't exists, do things by name (pre 1.1)
+                //and calculate and insert STAMP too !!
+    
+                //Check for categories and their properties, storing in temporary variables
+                //Count categories with the same name
+    
+                $count_cat = count_records("quiz_categories","name",$quiz_cat->name);
+                //Count categories with the same name in the same course
+                $count_cat_same_course = count_records("quiz_categories","course",$restore->course_id,"name",$quiz_cat->name);
+                //Count categories with the same name in other course
+                $count_cat_other_course = $count_cat - $count_cat_same_course;
+    
+                //Get categories with the same name in the same course
+                //The last record will be the oldest category
+                if ($count_cat_same_course > 0) {
+                    $cats_same_course = get_records_sql("SELECT c.* FROM {$CFG->prefix}quiz_categories c
+                                                         WHERE c.course = '$restore->course_id' AND 
+                                                               c.name = '$quiz_cat->name'
+                                                         ORDER BY c.id DESC");
                 } else {
-                    //We must never arrive here !!
-                    $status = false;
+                    $cats_same_course = false;
+                }
+                //Get categories with the same name in other course
+                //The last record will be the oldest category with publish=1
+                if ($count_cat_other_course > 0) {
+                    $cats_other_course = get_records_sql("SELECT c.* FROM {$CFG->prefix}quiz_categories c                           
+                                                          WHERE c.course != '$restore->course_id' AND 
+                                                                c.name = '$quiz_cat->name'
+                                                          ORDER BY c.publish ASC, c.id DESC");
+                } else {
+                    $cats_other_course = false;
+                }
+    
+                if ($count_cat == 0) {
+                    //The category doesn't exist, create it.
+                    //First, calculate the STAMP field
+                    $quiz_cat->stamp = make_unique_id_code();
+                    //The structure is equal to the db, so insert the quiz_categories
+                    $newid = insert_record ("quiz_categories",$quiz_cat);
+                } else {
+                    //The category exist, check if it belongs to the same course
+                    if ($count_cat_same_course > 0) {
+                        //The category belongs to the same course, get the last record (oldest)
+                        foreach ($cats_same_course as $cat) {
+                            $newid = $cat->id;
+                        }
+                    } else if ($count_cat_other_course > 0) {
+                        //The category belongs to other course, get the last record (oldest)
+                        foreach ($cats_other_course as $cat) {
+                            $other_course_cat = $cat;
+                        }
+                        //Now check the publish field
+                        if ($other_course_cat->publish == 0) {
+                            //The category has its publish to No (0). Create a new local one.
+                            //First, calculate the STAMP field
+                            $quiz_cat->stamp = make_unique_id_code();
+                            //The structure is equal to the db, so insert the quiz_categories
+                            $newid = insert_record ("quiz_categories",$quiz_cat);
+                        } else {
+                            //The category has its publish to Yes(1). Use it.
+                            $newid = $other_course_cat->id;
+                        }
+                    } else {
+                        //We must never arrive here !!
+                        $status = false;
+                    }
                 }
             }
 
             //Do some output
-            echo "<ul><li>".get_string("category")." \"".$quiz_cat->name."\"<br>";
+            if ($status) {
+                echo "<ul><li>".get_string("category")." \"".$quiz_cat->name."\"".$restored_by."<br>";
+            } else {
+                //We must never arrive here !!
+                echo "<ul><li>".get_string("category")." \"".$quiz_cat->name."\" Error!<br>";
+            }
             backup_flush(300);
 
+            //Here category has been created or selected, so save results in backup_ids and start with questions
             if ($newid and $status) {
                 //We have the newid, update backup_ids
                 backup_putid($restore->backup_unique_code,"quiz_categories",