Is there a way to bulk delete courses. I have 77 to delete one at a time!

Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Angela Roberts -
Number of replies: 42
I would love to be able to delete them all at once instead of sit here for an hour and do them one at a time. Any suggestions?

thanks in advance

angela
Average of ratings: -
In reply to Angela Roberts

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Valery Fremaux -

Why couln't you identify the appropriate course_delete() course API function (highest call level), say, digging the course management API, put it in a variable, whatever it is called, and then run a loop as

include_once("../config.php");

$coursedeletefunction = '...'; // what is the right top level call

$courses = get_records('course');

foreach($courses as $acourse){

    $coursedeletefunction($acourse->id);

}

assuming this is located in a mypowerscripts directory at Moodle install root.

wink

In reply to Angela Roberts

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Valery Fremaux -

In addition, and taking a step back my previous answer...

it is a real good idea to identify, in each major entity API (groups, courses, modules, users, servers, etc...) the end_user "use cases" branch point (usually should be a function call, in most cases). In a (so) nicely designed application such as Moodle, many use cases do have their entry in the whole Moodle API. I tried to setup a student project on the theme : why not designing an administration macro language, as simple as an ultra BASIC SCRIPTING for Moodle, that sits on those high level API function, and should allow many power moves with a really simple syntax (and with the gain of having a consistent and homogeneous semantical layer of this primitive set). I came too late this year, and there are no student available for projects (they are all engaged).  

In reply to Angela Roberts

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Colin Chambers -
I had the same problem when developing Moodle so I adapted the category management page in course/category.php where the courses are managed to add a button 'delete selected courses'. The code meant I could just check each item in the list and bulk delete.

I've attached the category.php page, it should be all you need. If you use it then backup the same file on your system first because the file I have uploaded is taken from the 1.9 beta version of moodle from mid august so there may be differences with your version.

For reference the relevant code is between line 149 and 173 for deleting the submitted courses, and line 460 to 463 to create the delete button itself.

If you want to add a 'select all' button so you don't have to click each individual button examples of these can be found on the web. They literally loop through each form item and check or uncheck them.

I hope this helps
Average of ratings: Useful (1)
In reply to Colin Chambers

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Angela Roberts -
Thank you so much!

I will try it smile
In reply to Angela Roberts

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Jeff Church -
Two of our student programmers wrote a little php page that takes a txt file with course short names and deletes them. It has worked great so far but it is a little finicky about extra spaces and file headers. Have used it in 1.8. Any improvements or feedback about the script would be great since the students are learning about writing code for Moodle.
In reply to Jeff Church

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by James Rudd -
Great utility. Seemed to work fine.

Only suggestion would be a count on first page, for example,
"Are you absolutely sure you want to completely delete the following 323 courses"
In reply to Jeff Church

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Greg Rodenhiser -
Have you tried this bulk course remove in Moodle 1.9 beta 4? I can no longer get it to work (beta 3 was fine though). I have to brush up on php to find what's wrong (unless you already know??). It's shocking... and frustrating quite frankly that Moodle doesn't include any course feed support for create or removal of courses.
In reply to Greg Rodenhiser

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Art Lader -

  

Hi, Greg,

Why not post a featuure request to http://tracker.moodle.org/? If enough Moodlers vote for it, maybe this feature will show up soon.

Couldn't hurt to ask, right?

Regards,
Art

In reply to Art Lader

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I am pretty sure this issue already exists, in which case don't create another one!

Actually, I am wrong. It doesn't seem to be there, but it does not hurt to reinforce the message that before you create a new issue in the tracker, it is good if you can search first to make sure it is not already there.
In reply to Greg Rodenhiser

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Jeff Church -
We are still on 1.8.3 with no plans to change to 1.9. Our plans are to wait for 2.1 or so before changing. So we are not looking to rewrite this for 1.9 but feel free to if you get time. Thats the wonderful thing about open source. Maybe we will update your 1.9 version for 2.0.

I have found with this script that about 1000 courses at a time is the most it can do before the script times out. At lease thats what I found on our test box. I think the php max_execution_time is 300 seconds. I could have bumped up the time but I just split the file into a few parts and it went fine.
In reply to Greg Rodenhiser

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Regan Richards -
To make the bulk course delete script work in 1.9, add this on line 24:

require_once($CFG->libdir.'/uploadlib.php');

it still throws some errors, but seems to work.

Thanks for the script, BTW, it's going to be a lifesaver!
In reply to Regan Richards

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Chad Parmentier -
I have 4000+ courses to delete. We are a large institution and I would like to try this but am not sure where or how to install the file. If this works I Would like to turn this php script over to our contracted programming firm and have them write this into a more advanced script that can be automated. any help would be appreciated.
In reply to Chad Parmentier

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Marc Grober -
Jeff church posted a zip of bulk upload and bulk delete apps that seem to work fine in 1.8.4 and 1.9. Let me know if you can't find it and I will locate it for you....
In reply to Marc Grober

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Chad Parmentier -
Thanks for the info, I had found the zip file jeff posted. I was not sure where to upload the deletecourses.php file. It first seemed like it ran from root, but would not call from web. I tried the courses folder in moodle but it seemed not to work there either. ill keep searching the forums but any info on how to install or use jeff's files would be most helpful. Thanks for the reply, P.S I did submit jeffs files to our programmers to see if they could work these into an installable module with more options.
In reply to Chad Parmentier

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Chad Parmentier -
Never mind I figured it out. Im going to post the instructions and the files updated to work with 1.9 so it might pull in a search. Thanks, for the help I am still going to see if this can be improved.
In reply to Chad Parmentier

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by noemi flores -

Have you posted the files and instructions yet? I think we tried the one for version 1.8 and since we were not able to access it from the web page we removed it. We are wanting to find some solution for deleting courses in bulk.

In reply to Regan Richards

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Michael Street -
Thanks so much for posting that snippet. You saved me quite the headache trying to figure out why it wasn't working in 1.9

Also, thanks to the folks who originally developed both scripts! I hope that this functionality gets put into the core someday.
In reply to Michael Street

Need M&P entry for Bulk Deletion Tool?

by Marc Grober -
Another example of confusing forum threads..... ;=}

Michael, you indicate that someone gave you a code snippet, but there is nothing in the forum which appears to be a response to you post.

Additionally it is confusing as to whether you were using the initial code that Jeff posted or the code that Chad posted here:
http://moodle.org/mod/forum/discuss.php?d=96736

So as to clarify the situation, could you post which code you used, which posting you relied on vis-a-vis patching, and the nature of your results?

Anthony, could you perhaps ask Chad/Jeff about an M&P entry for the deletion tool Chad posted at the URL above? As I understand it, he used the tool initially posted by Jeff CHurch and then made some alterations to get it working under 1.9 - not sure of whether the 1.9 version works for any earlier version and maybe Chad and Jeff could comment?
In reply to Marc Grober

Re: Need M&P entry for Bulk Deletion Tool?

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Marc - As best as I can tell the code for deleting multiple courses is at http://moodle.org/mod/data/view.php?d=13&rid=1039. I did confirm that this feature is working and I recall seeing that MDL-13343 was resolved for 1.9 so that there are various ways of deleting multiple courses now. Let me know if you have any further questions. Peace - Anthony
In reply to Anthony Borrow

Re: Need M&P entry for Bulk Deletion Tool?

by Bob Puffer -
Your link, "http://moodle.org/mod/data/view.php?d=13&rid=1039" appears to refer to bulk "user" deletion instead of bulk "course" deletion?
In reply to Bob Puffer

Re: Need M&P entry for Bulk Deletion Tool?

by Marc Grober -
Yes, Bob you are right.... the code that Anthony references is the bulk user deletion tool, not the bulk course deletion tool

I had asked Anthony to check on this and I think with him on the run the last month this must have gotten lost as I didn't see his response until just now.

Going back through the discussion it appears that Chad posted a working enhancement to the work that Jeff Church's people did (thanks to all who contributed) and that Chad posted the zip here.

http://moodle.org/mod/forum/discuss.php?d=96736

We need a new M&P page for this tool and I don't know if Chad intends to maintain it.

Anthony, can you address this? Maybe the bulk course add and delete tools should be bundled as I think Jeff first envisioned it?

Marc
In reply to Regan Richards

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Jeff Church

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Marc Grober -
Jeff,

There are so many people asking about this would you consider pursuing a M&P page or trying to assume responsibility for Rory's page if you haven't done so already?


In reply to Marc Grober

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Robert Russo -
We have written (still in final testing) a bulk archive and delete tool for 1.9 which backs up courses to a specified folder and appends the username (or other field) of all instructors to the filename. It then allows instructors to bulk delete all courses which have been successfully backed up.

This also works in concert with our simplified restore tool, which searches for archives based on username (or other field) and allows instructors to restore these otherwise non-accessible courses.

We do this so instructors do not have the ability to download course archives onto unprotected computers.
In reply to Robert Russo

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by noemi flores -
Where can we dowload the bulk archive and delete tool. We use 1.9 and would love to give it a shot.
In reply to noemi flores

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Robert Russo -
Email elearning@lsu.edu and I will send it to you.
In reply to Robert Russo

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Marc Grober -
Robert -
Are you interested in having this in M&P and serving as the maintainer?
See http://tracker.moodle.org/browse/CONTRIB-605
In reply to Marc Grober

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Robert Russo -
I posted our latest code to the tracker along with some descriptions of what the system is and what it does.
In reply to Robert Russo

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Robert Russo -
I'd love to add bulk restores to ours, but we don't have that need as instructors like the control our system gives them. besides, they only have to click one button do restore any of their old courses into the current course.
In reply to Angela Roberts

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Jason Hardin -
Later this month Moodlerooms will also be releasing the Course Management block that was developed for Intel, which allows you to schedule bulk restores and delete multiple courses.
In reply to Jason Hardin

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Robert Russo -
We are incorporating this page into our backup and delete system (basically adding file upload ability to our query builder).

We would gladly support our system (we have to for our university anyway). Let me know if this is acceptable and I will send you the code.
In reply to Jason Hardin

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Robert Russo -
When will the restore functionality be available? We hadn't thought of that as we also built a system to allow instructors to restore ANY of their previously backed up courses (either in existing courses or backed up using our backup and delete system).
In reply to Robert Russo

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Ray Lawrence -
In 1.9.x, move the courses to be deleted to a category. Delete the category, there is an option to move or delete the courses in the category. Choose Delete. Voilla!
Average of ratings: Useful (1)
In reply to Ray Lawrence

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Robert Russo -
We have thousands (about 8000) of courses in over 100 categories, so we developed "Backup and Delete" to ease the suffering. The system allows for you to build queries and backup and delete based on those queries. You can the re-use the queries later if needed. We also just added shortname upload support for delete only. We will be adding delete only support soon as well to the query builder.

Our courses are organized by department (category) and tied to a specific semester. So at the end of each semester we backup and delete these courses. We allow restore access via a separate tool that searches the Backup and Delete backup directory for courses that the user has a right to access.

Example: we need to backup and delete all Spring Intersession courses, so we do a search for 2008SpringInt (following our shortname conventions) and schedule a backup. After the backup is completed via cron, we get an email and now the tool will allow us to delete the courses. The system updates the screen as deletes are completed using mtrace.
Average of ratings: Useful (1)
In reply to Robert Russo

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Manuel NT -
 I looking for  the  oposite , do you have any  mass course creator?  moodle 1.9.2
In reply to Manuel NT

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Robert Russo -
We are using the IMS module for course creation.

If you have a list of courses listed with shortname, fullname, description, idnumber, instructor then you can write a regex to convert it to xml for use in the included Moodle IMS enrollment system.

The best part about IMS is that it can run during cron, so you can just replace the xml file when you have new courses to add and it will automatically pick it up on the next cron run.
In reply to Robert Russo

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Alan Zaitchik -
Do you code the "recstatus" like this:
<recstatus>3</recstatus>
or like this:
<group recstatus="3">

Ditto for <person>.

I couldn't get either to work for <person> or for <group>, and neither could I get updates to work with recstatus "2" ! On the other hand I was able to get both updates and deletes for <membership> (enrollment).

This is in Moodle 1.9 with the built-in IMS Enterprise plugin. I enabled the "Delete user accounts when specified in IMS data" option in the IMS configuration page. BTW, we use LDAP for authentication, and the external DB plugin for enrollments. Our interest in IMS was for batch operations because we have other integration projects that are IMS compliant.

All help MUCH appreciated!

Alan
In reply to Robert Russo

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Alan Zaitchik -
Robert,
It has been quite a while since I posted the reply to your note, but we are returning to the IMS option and I am wondering if you might revisit this briefly.
What is the correct XML for deleting a student. I have tried
...
<person>
<recstatus>3</recstatus>
...
and even
<recstatus=3 />
but neither has any effect on the account.
I am using Moodle 1.9.4 and whatever IMS plugin is part of that build. That is, I did not install any special "mint" IMS Enterprise plugin.
Thanks for any advise you might have.
Alan
PS/ I am attaching a sample XML file in the hope you can give it a quick look.
In reply to Alan Zaitchik

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Robert Russo -
We don't use IMS for deletions at all. We have our Backup and Delete (backadel) block for that, so I cannot speak as to recstatus=3 working or not.

We also ended up rewriting the IMS enterprise plugin to better suit our needs. Unfortunately, I doubt anyone else will find our IMS mods useful and we're about to ditch it for another enrollment solution called our Course Preferences System.

I will gladly email you with the latest zip of our backadel block if you would like to use it. Please send me an email as you seem to be hiding your email address from other users.
In reply to Robert Russo

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Alan Zaitchik -
I didn't realize my email address was hidden. Thanks for alerting me. I unhid it, but anyway it's a.zaitchik@rcn.com.
Just in case you ever need to know this, I finally figured out how to delete users via IMS-- not sure why I didn't think of trying it earlier:
<person recstatus="3">
If I end up needing your solution I may take you up on your kind offer. Right now however I am srtruggling with a different issue, but I will post a new note about it (how to call the IMS importnow.php script from a browser rather than through the cron interface).
Alan
In reply to Alan Zaitchik

Re: Is there a way to bulk delete courses. I have 77 to delete one at a time!

by Robert Russo -
You could simply do this to the script and turn on your cron password.

/* Removed to not require login
require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));


if (!$site = get_site()) {
redirect("index.php");
}
*/

if (!empty($CFG->cronremotepassword)) {
$pass = optional_param('password', '', PARAM_RAW);
if($pass != $CFG->cronremotepassword) {
// wrong password.
print_error('cronerrorpassword', 'admin');
exit;
}
}

/// get language strings

In reply to Robert Russo

Re: Bulk Delete not working

by Fred Weiss -
I have installed the bulk delete on Moodle 1.9.7+ (Build: 20091209) using MS-SQL as the database.

I have tried using the bulk delete function.
I upload the course file one shortname per line but when it goes to the preview page no courses are listed.

And consequently nothing is deleted.

Any ideas appreciated?