How do I delete course enrolments in moodle in bulk?

只谈情不闲聊 提交于 2019-12-25 04:08:33

问题


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


回答1:


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);
}
?>



回答2:


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);
}
?>



回答3:


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.



来源:https://stackoverflow.com/questions/1061563/how-do-i-delete-course-enrolments-in-moodle-in-bulk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!