General cleanup of backup users. Part of MDL-10721 ; merged from 19_STABLE

This commit is contained in:
stronk7 2008-01-25 00:50:08 +00:00
parent dd97c32868
commit c648a2259c

View File

@ -3,81 +3,77 @@
//except the mod-related funtions that are into every backuplib.php inside //except the mod-related funtions that are into every backuplib.php inside
//every mod directory //every mod directory
//Calculate the number of users to backup and put their ids in backup_ids /**
//Return an array of info (name,value) * This function calculates the users to be added to backup based in the
function user_check_backup($course,$backup_unique_code,$backup_users,$backup_messages) { * settings defined at backup. All the resulting user ids are sent to
//$backup_users=0-->all * backup_ids for later usage.
// 1-->course (needed + enrolled) * @param int $courseid id of the course to backup
// 2-->none * @param int $backup_unique_code unique code of the backup being executed
* @param int $backup_unique_code setting specifying what users to export (0=all, 1=needed, 2=none)
* @param int $backup_messages flag (true/false) defining if messages must be
* considered to extract needed users
* @return array one array (key, value) sumarizing the result of the function (number of users)
*/
function user_check_backup($courseid,$backup_unique_code,$backup_users,$backup_messages) {
global $db, $CFG; $context = get_context_instance(CONTEXT_COURSE, $courseid);
$context = get_context_instance(CONTEXT_COURSE, $course);
$count_users = 0; $count_users = 0;
$backupable_users = array();
//If we've selected none, simply return 0 if ($backup_users == 0) { /// All users
if ($backup_users == 0 or $backup_users == 1) { $backupable_users = backup_get_all_users();
//Now, depending of parameters, create $backupable_users } else if ($backup_users == 1) { /// Needed users
if ($backup_users == 0) {
//Calculate all users (every record in users table)
$all_users = backup_get_all_users();
$backupable_users = $all_users; /// Calculate needed users (calling every xxxx_get_participants function + scales users)
} else { $needed_users = backup_get_needed_users($courseid, $backup_messages);
//Calculate needed users (calling every xxxx_get_participants function + scales users)
$needed_users = backup_get_needed_users($course, $backup_messages);
//Calculate enrolled users (students + teachers) /// Calculate enrolled users (having course:view cap)
$enrolled_users = backup_get_enrolled_users($course); $enrolled_users = backup_get_enrolled_users($courseid);
//Calculate course users (needed + enrolled) /// Calculate backupable users (needed + enrolled)
//First, needed /// First, needed
$course_users = $needed_users; $backupable_users = $needed_users;
//Now, enrolled /// Now, enrolled
if ($enrolled_users) { if ($enrolled_users) {
foreach ($enrolled_users as $enrolled_user) { foreach ($enrolled_users as $enrolled_user) {
$course_users[$enrolled_user->id]->id = $enrolled_user->id; $backupable_users[$enrolled_user->id]->id = $enrolled_user->id;
}
} }
$backupable_users = $course_users;
}
//If we have backupable users
if ($backupable_users) {
//Iterate over users putting their roles
foreach ($backupable_users as $backupable_user) {
$backupable_user->info = "";
//Is needed user (exists in needed_users)
if (isset($needed_users[$backupable_user->id])) {
$backupable_user->info .= "needed";
} else if (isset($course_users[$backupable_user->id])) {
$backupable_user->info .= "needed";
} // Yu: also needed because they can view course
// might need another variable
//Now create the backup_id record
$backupids_rec = new stdClass;
$backupids_rec->backup_code = $backup_unique_code;
$backupids_rec->table_name = "user";
$backupids_rec->old_id = $backupable_user->id;
$backupids_rec->info = $backupable_user->info;
//Insert the record id. backup_users decide it.
//When all users
$status = insert_record('backup_ids', $backupids_rec, false);
$count_users++;
}
//Do some output
backup_flush(30);
} }
} }
//Prepare Info /// If we have backupable users
//Gets the user data if ($backupable_users) {
/// Iterate over users putting their roles
foreach ($backupable_users as $backupable_user) {
$backupable_user->info = "";
/// Is needed user or enrolled user, mark it as needed
if (isset($needed_users[$backupable_user->id]) || isset($enrolled_users[$backupable_user->id])) {
$backupable_user->info .= "needed";
} /// Yu: also needed because they can view course
/// might need another variable
/// Now create the backup_id record
$backupids_rec->backup_code = $backup_unique_code;
$backupids_rec->table_name = "user";
$backupids_rec->old_id = $backupable_user->id;
$backupids_rec->info = $backupable_user->info;
/// TODO: Change this call inserting to a standard backup_putid() call
/// And read data acordingly with backup_getid() when needed.
/// TODO: Also analyse it the "needed" info is really needed for anything. Drop if not.
/// Insert the user to the backup_ids table. backup_user_info() will use that info
$status = insert_record('backup_ids', $backupids_rec, false);
$count_users++;
}
/// Do some output
backup_flush(30);
}
/// Prepare Info
/// Gets the user data
$info[0][0] = get_string("users"); $info[0][0] = get_string("users");
$info[0][1] = $count_users; $info[0][1] = $count_users;
@ -1225,26 +1221,10 @@
/// write assign/override code for context_userid /// write assign/override code for context_userid
$user->isneeded = strpos($user->info,"needed"); $user->isneeded = strpos($user->info,"needed");
//Output every user role (with its associated info)
/*
$user->isadmin = strpos($user->info,"admin");
$user->iscoursecreator = strpos($user->info,"coursecreator");
$user->isteacher = strpos($user->info,"teacher");
$user->isstudent = strpos($user->info,"student");
if ($user->isadmin!==false or
$user->iscoursecreator!==false or
$user->isteacher!==false or
$user->isstudent!==false or
$user->isneeded!==false) {
*/
fwrite ($bf,start_tag("ROLES",4,true)); fwrite ($bf,start_tag("ROLES",4,true));
if ($user->info != "needed" && $user->info!="") { if ($user->info != "needed" && $user->info!="") {
//Begin ROLES tag
//PRINT ROLE INFO //PRINT ROLE INFO
//Admins
$roles = explode(",", $user->info); $roles = explode(",", $user->info);
foreach ($roles as $role) { foreach ($roles as $role) {
if ($role!="" && $role!="needed") { if ($role!="" && $role!="needed") {