## General developer forum

### Automatically resetting a course

Automatically resetting a course

So I want to automatically reset a course.  I know .. moosh... (I think that is what is called can do it).  However, I did not want to rely on a 3rd party program because I was worried I would not be able to install it on a live server.  After searching through the different sources I was able to come up with what I think reset_course_userdata(...) is expecting as a parameter.   However, when I plug it in I get: "Can not find data record in database table course."

I have verified my course ID is 2 and I have manually found it through mysql so I know it is in the table "mdl_course".

1st) any ideas what I may be doing wrong.  (This is sandbox code so please excuse the mess).

2nd) Is there an easier way of resetting a course without involving human interaction?

Thanks,
BAT

$START_D_A = explode('/',$START_TIME);

$END_D_A = explode('/',$END_TIME);

echo "The course id is ".$COURSEID;$data = array(

'id' => $COURSEID, 'reset_start_date'=>array('day'=>$START_D_A[1],'month'=>$START_D_A[0],'year'=>$START_D_A[2]),

'reset_end_date'=>array('day'=>$END_D_A[1],'month'=>$END_D_A[0],'year'=>$END_D_A[2]), 'reset_events' => '1', 'reset_notes' => '1', 'reset_comments' =>'1', 'reset_blog_associations'=>'1', 'unenrol_users'=> array('5'=>'Student'), 'reset_gradebook_items' => '1', 'reset_forum_all'=> '1', 'reset_quiz_attempts' => '1', 'reset_quiz_user_overrides'=>'1', 'reset_quiz_group_overrides'=>'1' ); reset_course_userdata($data);  //error thrown on this line

Average of ratings: -
Re: Automatically resetting a course

Hi BAT,

I don't know the rest of your code but \$data must be an instance of stdClass() and you have an array.

Andreas

Average of ratings: Useful (1)
Re: Automatically resetting a course

Thank you very much.

I had to do a var dump to see how the object was formed but that did the trick.  Thanks!

BAT

Average of ratings: -
Re: Automatically resetting a course

Hi BAT,

are you aware of https://moodle.org/plugins/local_sandbox which you could use out of the box or where you could extract some code?

Cheers,
Alex

Average of ratings: -