简体   繁体   中英

How do I delete course enrolments in moodle in bulk?

Moodle has a built in per course reset ability. I want to reset all my courses.

Sorry to bring this old post back but after a long struggle I finally got that code to work. I've tested it on a Moodle 1.9.7 enviroment

<?php
require('../config.php');
require_once('reset_form.php');

$courseids = array(8,9,11);

foreach ($courseids as &$value) {
    $data->MAX_FILE_SIZE = 8097152;
    $data->reset_start_date = 1251781200;
    $data->reset_events = 1;
    $data->reset_logs = 1;
    $data->reset_notes = 1;
    $data->reset_roles = Array(5);
    $data->mform_showadvanced_last = 0;
    $data->reset_roles_local = 1;
    $data->reset_gradebook_grades = 1;
    $data->reset_assignment_submissions = 1;
    $data->reset_forum_all = 1;
    $data->reset_quiz_attempts = 1;
    $data->id = $value;

    require_login($value);      
    require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $value));

    $status = reset_course_userdata($data);
}
?>

Ok, I figued it out, but be very carful. If you do not know what you are doing do not use this code, you could do a lot of damage to your DB. This does the "default" course reset to all course ids in the array.

 <?php
require('../config.php');
require_once('reset_form.php');

$courseids = array(8,9,11);

foreach ($courseids as &$value) {


    $data->MAX_FILE_SIZE = 8097152;
    $data->reset_start_date = 1251781200;
    $data->reset_events = 1;
    $data->reset_logs = 1;
    $data->reset_notes = 1;
    $data->reset_roles = Array(5);
    $data->mform_showadvanced_last = 0;
    $data->reset_roles_local = 1;
    $data->reset_gradebook_grades = 1;
    $data->reset_assignment_submissions = 1;
    $data->reset_forum_all = 1;
    $data->id = $value;

    $status = reset_course_userdata($data);
}
?>

You should not reset courses this way, its too risky. Use the Course administration feature Choose the course, find the course admin. block, click the reset button, very simple. If you have only 3 courses, this takes about 30 seconds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM