]> git.mjollnir.org Git - moodle.git/commitdiff
Now restoring groups is cross-db (the detection of existing groups)
authorstronk7 <stronk7>
Wed, 5 Sep 2007 19:19:34 +0000 (19:19 +0000)
committerstronk7 <stronk7>
Wed, 5 Sep 2007 19:19:34 +0000 (19:19 +0000)
(NOTE: There is one pending bug about restoring old groups to 1.9.
       Commented to Petr. Added here because I've to go NOW!)

Merged from MOODLE_18_STABLE

backup/restorelib.php

index 30d6de457a07ba12db71491c8b3ddb7f84ac4653..60616b1b480a6ea02ff5b1cc30e261b6acec0dd8 100644 (file)
     //This function creates all the groups
     function restore_create_groups($restore,$xml_file) {
 
+        global $CFG;
+
         //Check it exists
         if (!file_exists($xml_file)) {
             return false;
                 $gro->timemodified     = backup_todb($info['GROUP']['#']['TIMEMODIFIED']['0']['#']);
 
                 //Now search if that group exists (by name and description field) in
-                if (!$gro_db = get_record('groups', 'courseid', $restore->course_id, 'name', $gro->name, 'description', $gro->description)) {
+                //restore->course_id course
+                //Going to compare LOB columns so, use the cross-db sql_compare_text() in both sides.
+                $description_clause = '';
+                if (!empty($gro->description)) { /// Only for groups having a description
+                    $literal_description = "'" . $gro->description . "'";
+                    $description_clause = " AND " .
+                                          sql_compare_text('description') . " = " .
+                                          sql_compare_text($literal_description);
+                }
+                if ($gro_db = get_record_sql("SELECT *
+                                          FROM {$CFG->prefix}groups
+                                          WHERE courseid = $restore->course_id AND
+                                                name = '{$gro->name}'" . $description_clause)) {
                     //If it doesn't exist, create
                     $newid = insert_record('groups', $gro);