Apologies if this is a silly question or if I have missed something, but I need a way to delete quite a lot of old questions and categories. I know that I can go into each category and select all the questions before deleting them, but this seems slow and a bit clumsy and takes a long time (especially with our server!).
Is there perhaps some way of directly editing the database to accomplish this more easily?
Thanks in advance
Actually, what you case safely do is to set the hidden column to true (1) for all the questions you want to get rid of. That has almost the same effect as deleting the questions completely, but does not break any of the places that refer to them. (This is what Moodle actually does when you delete a question that is in use.) Of course, it leaves all the data in your database.
The other option is to write a PHP script that calls the delete function for all the questions you want gone.
So people beware of deleting a course with a quiz!!
You can still delete quiz in a course and keeping the questions but when you still delelete afterwards the whole course than the questions are gone from the central database.
Besides this Moodle 1.7 has many more problems like inserting links, data,documents
What exactly is the problem?
You make a quiz with 30 questions. A colleque says hey that's a cool quiz can i use it? So he/she imports your quiz or he/she picks the SAME questions from the central database. All questions are available for every docent or people with a higher profile in moodle.
But later your colleque decided to delete the course and yes everything in that course is gone and also in yours if you used the same questions!!!
Moodle always checks if the questions are used elsewhere but this check dont work so the questions in your original course are also gone and everywhere.
So it's "dangerous" to share courses (witihn the same moodle) with the same questions or quiz if the other to decide deleting his or her course.
If this is true, it is a good catch, Patrick. Sounds like something that might belong in the tracker - http://tracker.moodle.org/
I think you are describing two different scenarios.
In the first scenario, your colleague imports (or more likely restores from backup) a quiz from your course. This makes a copy of everything (questions, categories). The copies now belong to your colleague, and anything he does with them will not affect your course.
In the second scenario, your colleague picks questions from a "central database." There's no such notion in Moodle, but the closest thing is a database belonging to a course in which all categories are published. Your colleague can very well make a quiz from the questions in such a database, but the questions will be read only in his course. He cannot change them and he cannot delete them.
Believe me John i've researched and tried it. And of course a docent cannot delete courses. But please be my guest and try the following:
Make a course, make some example questions
Make another course use the the SAME questions or import the whole quiz in it.
It don't make a difference how you do it both scenarios goes wrong (in fact every possible scenario) (using moodle 1.7)
1.6.3 hadn't this failure!!
Than delete a course ,which one it really don't matter, and than try the quiz again , you get the message no questions found!!
When i import a whole course nothing goes wrong when i delete the main course or the copy one except the quiz/questions.
And i've done it with every possible scenario.
I have just discovered the same problem. We didn't have the problem with 1.6, but ever since our upgrade to 1.8.2 the quiz questions are deleted completely if only 1 course using these questions is deleted, even though 10 other courses use the same questions.
Does anybody have an idea what the problem could be?
Now, since the backup/restore doesn't work as it should, we were forced to comment out the restore feature from <mdl-server-url>/files/files.php and we are in a situation where we are unable to restore any course because of the fear of messing up the db again (I have had to restore our postgresql db now twice because of this bug). The reason for this is exactly the same as what many of you have described: the questions are nowhere to be found when a course with quizzes is deleted. The quiz results are there, but the quiz sheets submitted by the students and the quiz templates lack questions. In many cases the non-published (we don't use the "publish categories") quiz categories are deleted, too.
Please see and vote for the issue I submitted a week ago if you feel you're suffering from the same problem:
Olli S. / FINLAND
+ // TODO: we should also consider other questions that are used by
+ // random questions in this quiz, but that is very hard.
My question is: what kind of problems can we still face with the MDL-11081 patch installed? And more: what kind of solution would fix this quiz problem permanently?
It's really awesome that 1.9 will fix many of these quiz issues. But as we cannot take 1.9 to our production sites yet, I think the only way now is to patch 1.6-1.8 as well as possibly.
In addition, if you click on the 'Version Control' link after the description, you can find out exactly how the code changed to fix this issue.
The underlying issue was that there was the function 'quiz_question_list_instances', which is supposed to return a list of all the quizzes that use a particular question, had not been implemented. That is, it always said 'this question is not used by any quizzes'. So when a course was being deleted (either really deleted, or emptied out before resotring a backup into it, Moodle thought it was safe to delete the questions when actually it wasn't.
So the solution that Janne Mikkonen worked out, and I edited slighly and committed, was to return an list of quizzes that was mostly accurate.
Why only mostly accurate? Well there are two ways a quiz can use question X. Either the quiz can include question X directly, or the quiz can include a random question, and then the random question can pick question X of one or more student's attemtpt. At the moment, we are only finding the first sort of usage. That is realy what the comment notes - that we really ought to find examples of the second sort of usage too, but we have not yet because it is too difficult (and it would be very expensive, in performace terms, to try.)
However, I am fairly sure it does not matter, because actually the delete code, which is the only place where this is important, actually makes the delete or keep decision at the category level, not the individualy question level, and as far as I can make out, the way it works means that it will never delete a questions needed by a random question. However, it would be good if someone else can study the code and confirm this. The way to start is to grep for all the places (about 5) where quiz_question_list_instances is referred to.
I should also note that this is no longer a problem in Moodle 1.9, Jamies changes to the question bank mean that questions are no longer shared between courses, so when you delete a course, all its qeustions can safely be deleted too, so life is much simpler, and hopefully more bug-free. Thanks Jamie.
I am having great difficulty deleting unwanted questions from the default category although I deleted all the quizzes I had set up and transfered all the questions to the default category. I tried creating one quiz with all the questions from the default category and deleted the quiz but the questions still remain. is there a quick way to do this rather than delete all the 900 questions one by one. Yawn!
We faced the same problem today while restoring a course (we're using 1.6.5).
We needed to have the questions used for 2 quizzes, but after restore, the quizzes were empty!
Any solution found since sept.07?
Getting back to your original question: How about creating a new "master" category and making all your existing categories children of the master category. Then delete the master category. I'm pretty sure I have done this in version 1.6.3. It should be easy to make a small experiment first.
just want to ask the same question as James Reed..is there any way that i could delete the parent category together with it child and all content in there without deleting them one by one before you could delete the category itself..
it take too long too delete one by one and could you imaging if you have more than 1000 question in one category..could anyone help me? may be could create new function that if you delete the parent category, automatically the child and its content will deleted also..
After much searching and frustration I found a way to 'easily' bulk delete categories filled with hundereds of sub-categories and thousands of questions which involves using the fact that each moodle quiz has a default category for questions. You can only see this default category when you click on Question Bank > Categories from 'within' the quiz.
To delete large numbers of questions/categories,
1. Create a new quiz.
2. From 'within' that quiz click on Question Bank > Categories.
3. Move the category or categories you would like to delete into the category "Default for <quiz name>". Make sure that they are actually 'inside' this category (i.e., the category that you would like to delete is contained within the category "Default for <quiz name>"; it should be graphically directly below this category in the GUI, and also indented to the right of it).
4. Go back to the course and delete the quiz.
The questions are 'magically' gone, as far as you the teacher are concerned. At least some are likely to still be in the database somewhere, since questions that have been used are 'just' hidden from sight. But from a teacher's perspective, they're gone.
They do not actually get deleted from the database. Another way to do this is create a category called Questions to Delete. Then start deleting all the categories with the questions that you wanted deleted. It will prompt to move the questions when you delete the category - move them all to Questions to Delete. At that point you can then go to that category, select all and delete.
As Tim mentions, it is not easy to delete from the database but it is possible. It is easier if they have never been used in a quiz (and realistically, if they have been used in a quiz, you should not be deleting them anyway....) - there are just a few tables that you need run scripts on using the quiz id in your search terms.
One step we need to take is to clean up our question Bank. I’ve done some testing and have found I can delete a question from the bank and if this question is being used in a course quiz it will NOT remove it from the quiz. If this is true across the board then we should be safe if we delete all questions and start with a clean slate.
My idea is to do the following
1. Download all quizzes that are being used in current courses. (nearly 200 courses, so this will take hours and hours of time)
2. Begin deleting questions and categories
3. Create a “best practices” as to how to create categories and question banks
4. Delete courses that are no longer needed
5. Once this is complete, upload the current quizzes that were downloaded into the correct categories
The hope here is that we would have a shiny new Moodle site without years of data just sitting around.
What has prompted this is we upgraded from 2.4 - 2.8 and the experience has been as bad as the upgrade from 1.9 - 2.4.
When we upgraded from 1.9 all data came along, nothing was removed, now with this upgrade the same data has still come along.
We are a K-12 institution and we have no down time, yet both of these upgrades have crippled our system. We have never deleted courses or questions so we have been basically data hoarders and it’s time to clean house.
I would love to do this in a bulk way but from what I understand the only way would be through the database itself. We don’t have the know how to do this, and we don’t even have access to it. We are hosted and supported by a Moodle Partner, so we don’t have access to files or the database.
Has anyone done something similar to this? Is there a better, quicker way?
We have been told we have over 400,000 questions and 10 million grade records in our database.