From 57aad2a02a6329f4be085070ac75e0b214559765 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 30 Jan 2005 11:39:12 +0000 Subject: [PATCH] added support for: - user->policyagreed: if the destination server is different, reset it - user_students->enrol and user_teachers->enrol if not set or the destination server is different, set it to $CFG->enrol somethings should be modified in the rest of moodle: - update all the 'manual' entries to 'internal' - modify the enrol_teacher() to use $CFG->enrol by default - make every enrol method set this field properly. - perhaps, mark metadata users with a new value too. --- backup/CHANGES_14_15.txt | 6 +++--- backup/backuplib.php | 3 +++ backup/restorelib.php | 42 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/backup/CHANGES_14_15.txt b/backup/CHANGES_14_15.txt index b87ff97bcc..54df8b31b2 100644 --- a/backup/CHANGES_14_15.txt +++ b/backup/CHANGES_14_15.txt @@ -11,9 +11,9 @@ Now I show the specific detailed status of every item in the process: 1. DONE: check user->idnumber 2. DONE: check user->lang (at restore set mi_nt where ma_nt). 3. DONE: check course->lang (at restore set mi_nt where ma_nt). - 4. TODO: user_students->enrol (analyse and proceed). - 5. TODO: user_teachers->enrol (analyse and proceed). - 6. TODO: user->policyagreed (analyse and proceed). + 4. DONE: user_students->enrol (analyse and proceed). + 5. DONE: user_teachers->enrol (analyse and proceed). + 6. DONE: user->policyagreed (analyse and proceed). 7. TODO: groups->password 8. TODO: assignment->emailteachers 9. TODO: exercise->usepassword and exercise->password diff --git a/backup/backuplib.php b/backup/backuplib.php index a8b453b67a..58f4674475 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -770,6 +770,7 @@ fwrite ($bf,full_tag("AUTH",4,false,$user_data->auth)); fwrite ($bf,full_tag("GUID",4,false,$user_data->guid)); fwrite ($bf,full_tag("CONFIRMED",4,false,$user_data->confirmed)); + fwrite ($bf,full_tag("POLICYAGREED",4,false,$user_data->policyagreed)); fwrite ($bf,full_tag("DELETED",4,false,$user_data->deleted)); fwrite ($bf,full_tag("USERNAME",4,false,$user_data->username)); fwrite ($bf,full_tag("PASSWORD",4,false,$user_data->password)); @@ -851,6 +852,7 @@ fwrite ($bf,full_tag("TIMEEND",6,false,$tea->timeend)); fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$tea->timemodified)); fwrite ($bf,full_tag("TIMEACCESS",6,false,$tea->timeaccess)); + fwrite ($bf,full_tag("ENROL",6,false,$tea->enrol)); //Print ROLE end fwrite ($bf,end_tag("ROLE",5,true)); } @@ -866,6 +868,7 @@ fwrite ($bf,full_tag("TIMEEND",6,false,$stu->timeend)); fwrite ($bf,full_tag("TIME",6,false,$stu->time)); fwrite ($bf,full_tag("TIMEACCESS",6,false,$stu->timeaccess)); + fwrite ($bf,full_tag("ENROL",6,false,$stu->enrol)); //Print ROLE end fwrite ($bf,end_tag("ROLE",5,true)); } diff --git a/backup/restorelib.php b/backup/restorelib.php index 2149597a95..0d4d9fa27d 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -935,6 +935,16 @@ $user->auth = $CFG->auth; } + //We need to process the POLICYAGREED field to recalculate it: + // - if the destination site is different (by wwwroot) reset it. + // - if the destination site is the same (by wwwroot), leave it unmodified + + if ($restore->original_wwwroot != $CFG->wwwroot) { + $user->policyagreed = 0; + } else { + //Nothing to do, we are in the same server + } + //We are going to create the user //The structure is exactly as we need $newid = insert_record ("user",$user); @@ -982,6 +992,19 @@ //Set course and user $user->roles['teacher']->course = $restore->course_id; $user->roles['teacher']->userid = $newid; + + //Need to analyse the enrol field + // - if it isn't set, set it to $CFG->enrol + // - if we are in a different server (by wwwroot), set it to $CFG->enrol + // - if we are in the same server (by wwwroot), maintain it unmodified. + if (empty($user->roles['teacher']->enrol)) { + $user->roles['teacher']->enrol = $CFG->enrol; + } else if ($restore->original_wwwroot != $CFG->wwwroot) { + $user->roles['teacher']->enrol = $CFG->enrol; + } else { + //Nothing to do. Leave it unmodified + } + //Insert data in user_teachers //The structure is exactly as we need $status = insert_record("user_teachers",$user->roles['teacher']); @@ -996,6 +1019,19 @@ //Set course and user $user->roles['student']->course = $restore->course_id; $user->roles['student']->userid = $newid; + + //Need to analyse the enrol field + // - if it isn't set, set it to $CFG->enrol + // - if we are in a different server (by wwwroot), set it to $CFG->enrol + // - if we are in the same server (by wwwroot), maintain it unmodified. + if (empty($user->roles['student']->enrol)) { + $user->roles['student']->enrol = $CFG->enrol; + } else if ($restore->original_wwwroot != $CFG->wwwroot) { + $user->roles['student']->enrol = $CFG->enrol; + } else { + //Nothing to do. Leave it unmodified + } + //Insert data in user_students //The structure is exactly as we need $status = insert_record("user_students",$user->roles['student']); @@ -2642,6 +2678,9 @@ case "CONFIRMED": $this->info->tempuser->confirmed = $this->getContents(); break; + case "POLICYAGREED": + $this->info->tempuser->policyagreed = $this->getContents(); + break; case "DELETED": $this->info->tempuser->deleted = $this->getContents(); break; @@ -2792,6 +2831,9 @@ case "TIMEACCESS": $this->info->temprole->timeaccess = $this->getContents(); break; + case "ENROL": + $this->info->temprole->enrol = $this->getContents(); + break; case "NAME": $this->info->tempuserpreference->name = $this->getContents(); break; -- 2.39.5