Find empty glossaries

Find empty glossaries

by Matthias Giger -
Number of replies: 7
Picture of Particularly helpful Moodlers

I would like to find all glossaries in my installation which are empty.

Is there a special flag for that in the database? Or how could I formulate an SQL query resulting in a list of such glossaries?

(When courses are reset with the wrong options, we sometimes end up with empty glossaries.)

Average of ratings: -
In reply to Matthias Giger

Re: Find empty glossaries

by Ken Task -
Picture of Particularly helpful Moodlers

Aren't glossaries tied to users ... who submitted one/created?

Reason asked ... '... courses are reset with the wrong options,'.   That 'wrong' option is?

'empty' ... means what?   There's a concept but no definition?

Table, I would think, is glossary_entries but not sure how one would make a query showing 'empty'. :|

'SoS', Ken

In reply to Ken Task

Re: Find empty glossaries

by Matthias Giger -
Picture of Particularly helpful Moodlers

Dear Ken

Thanks a lot for your reply.

When you reset a course with standard options, glossaries end up empty.

Options for resetting courses

That means that glossaries are still there but they are purged of all the entries.

Now, that's not the problem, because I always backup glossaries before the end of the school year.

But those glossaries are linked to the crosswords (through the game plugin) and with a total of more than 100 glossaries across all the courses in our installation, it is very cumbersome to look for glossaries without definitions.

When students click on such a crossword linked to a glossary without entries, they get an error message. Not a problem in my own classes but a headache when it happens in a class of other staff. That is why I want to search for "empty glossaries" with an SQL query. Which would be a more elegant solution than doing the search manually every year.

I know that I can get a list of all glossaries in the database, but I don't know how to do a query which only shows glossaries with no entries in them. I'm trying to improve my SQL skills but at a moment, there are far from sufficient for such a query. So any help will be appreciated.

In reply to Matthias Giger

Re: Find empty glossaries

by Ken Task -
Picture of Particularly helpful Moodlers

Thanks for a more complete/accurate description of the problem. 

Moodle version?

Me thinks you have some table sluething to do ... need to find the tables for game/crossword and how those are linked/indexed, etc. with the tables for glossaries.

There is no Moodle Admin UX for such things so you'll have to use the mysql client and the DB for your Moodle.

mysql> show tables like '%glossary%';

will list:

| mdl_glossary                       |
| mdl_glossary_alias                 |
| mdl_glossary_categories            |
| mdl_glossary_entries               |
| mdl_glossary_entries_categories    |
| mdl_glossary_formats

I don't have game installed on any moodle I admin right now so you'd have to do the same type of query for 'game' I would imagine.

There is some table in games that references glossaries.

I do have a 'sandbox' 3.4,.5,.6, and .7 sites.

Could install game on which ever is compat.  That's why the question about Moodle version above.

If you could share a link to a no user backup of a course that had game and glossary in it, then I could look into it further.

Could PM me that info ... url to acquire the no user backup and version of Moodle ... and I'll take a look see.

'SoS', Ken


In reply to Ken Task

Re: Find empty glossaries

by Matthias Giger -
Picture of Particularly helpful Moodlers
Thanks again for your input. I think after some trial and error I now have what I want for Moodle 3.7.x:

SELECT mdl_glossary.name, mdl_course.shortname, COUNT(*)
FROM mdl_glossary, mdl_glossary_entries, mdl_course
WHERE mdl_glossary.id = mdl_glossary_entries.glossaryid AND mdl_glossary.course=mdl_course.id
GROUP BY mdl_glossary.id
ORDER BY 3
The resulting list looks like this:

List of glossaries in Moodle installation with number of entries

And the glossaries with a count of 1 are indeed glossaries without an entry.

Average of ratings: Useful (1)
In reply to Matthias Giger

Re: Find empty glossaries

by Ken Task -
Picture of Particularly helpful Moodlers

Congrats!  Convoluted, isn't it!   sad

Wish there was a default options for admins in reset's of courses like there is for backups.

Guess teacher education and process of reset is the only way to avoid. 

Had same kinda issue with resets and students in a course ... the reset options screen had all options 'turned up' ... hidden ... teacher wouldn't check all options ... defaults for student users was to keep users but remove their work (or some such odd combo).   After reset teacher thought ready for next session with new student users, found that wasn't so and had to be reminded about checking all options. 

Anyhoo ... took 2 years before process learned by assigned admin and teachers was down pat. :|

'SoS', Ken


In reply to Ken Task

Re: Find empty glossaries

by Matthias Giger -
Picture of Particularly helpful Moodlers
The solution presented above only counts the number of entries in each glossary which is also useful but not what I wanted because it doesn't work with empty glossaries.

So here is the query which actually finds empty glossaries:

select md_glossary.name, md_course.fullname
from md_glossary, md_course
where md_glossary.id not in (select md_glossary_entries.glossaryid from md_glossary_entries) AND md_course.id=md_glossary.course
ORDER BY md_course.fullname, md_glossary.name ASC

The result is sorted table with the name of the glossary and the course name.

empty glossaries

In reply to Ken Task

Re: Find empty glossaries

by murugan m -

Thanks for answering my question.

The problem is source of the game only. For all the games except millionaire, I have given the source glossary and for millionaire the source is quiz.

All the games are working fine.

Thanks for answering.