mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
General cleanup of backup users. Part of MDL-10721 ; merged from 19_STABLE
This commit is contained in:
parent
dd97c32868
commit
c648a2259c
@ -3,81 +3,77 @@
|
||||
//except the mod-related funtions that are into every backuplib.php inside
|
||||
//every mod directory
|
||||
|
||||
//Calculate the number of users to backup and put their ids in backup_ids
|
||||
//Return an array of info (name,value)
|
||||
function user_check_backup($course,$backup_unique_code,$backup_users,$backup_messages) {
|
||||
//$backup_users=0-->all
|
||||
// 1-->course (needed + enrolled)
|
||||
// 2-->none
|
||||
/**
|
||||
* This function calculates the users to be added to backup based in the
|
||||
* settings defined at backup. All the resulting user ids are sent to
|
||||
* backup_ids for later usage.
|
||||
* @param int $courseid id of the course to backup
|
||||
* @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, $course);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$count_users = 0;
|
||||
$backupable_users = array();
|
||||
|
||||
//If we've selected none, simply return 0
|
||||
if ($backup_users == 0 or $backup_users == 1) {
|
||||
if ($backup_users == 0) { /// All users
|
||||
$backupable_users = backup_get_all_users();
|
||||
|
||||
//Now, depending of parameters, create $backupable_users
|
||||
if ($backup_users == 0) {
|
||||
//Calculate all users (every record in users table)
|
||||
$all_users = backup_get_all_users();
|
||||
} else if ($backup_users == 1) { /// Needed users
|
||||
|
||||
$backupable_users = $all_users;
|
||||
} else {
|
||||
//Calculate needed users (calling every xxxx_get_participants function + scales users)
|
||||
$needed_users = backup_get_needed_users($course, $backup_messages);
|
||||
/// Calculate needed users (calling every xxxx_get_participants function + scales users)
|
||||
$needed_users = backup_get_needed_users($courseid, $backup_messages);
|
||||
|
||||
//Calculate enrolled users (students + teachers)
|
||||
$enrolled_users = backup_get_enrolled_users($course);
|
||||
/// Calculate enrolled users (having course:view cap)
|
||||
$enrolled_users = backup_get_enrolled_users($courseid);
|
||||
|
||||
//Calculate course users (needed + enrolled)
|
||||
//First, needed
|
||||
$course_users = $needed_users;
|
||||
|
||||
//Now, enrolled
|
||||
if ($enrolled_users) {
|
||||
foreach ($enrolled_users as $enrolled_user) {
|
||||
$course_users[$enrolled_user->id]->id = $enrolled_user->id;
|
||||
}
|
||||
/// Calculate backupable users (needed + enrolled)
|
||||
/// First, needed
|
||||
$backupable_users = $needed_users;
|
||||
|
||||
/// Now, enrolled
|
||||
if ($enrolled_users) {
|
||||
foreach ($enrolled_users as $enrolled_user) {
|
||||
$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
|
||||
//Gets the user data
|
||||
/// 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 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][1] = $count_users;
|
||||
|
||||
@ -1225,26 +1221,10 @@
|
||||
/// write assign/override code for context_userid
|
||||
|
||||
$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));
|
||||
if ($user->info != "needed" && $user->info!="") {
|
||||
//Begin ROLES tag
|
||||
|
||||
//PRINT ROLE INFO
|
||||
//Admins
|
||||
$roles = explode(",", $user->info);
|
||||
foreach ($roles as $role) {
|
||||
if ($role!="" && $role!="needed") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user