Skip to content

Commit

Permalink
MDL-25227 glossary - fix delete_instance() and clean orphaned entries
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Nov 15, 2010
1 parent f3cc571 commit 3b95347
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions mod/glossary/db/upgrade.php
Expand Up @@ -299,6 +299,16 @@ function xmldb_glossary_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2010042800, 'glossary');
}

if ($oldversion < 2010111500) {
// Delete orphaned glossary_entries not belonging to any glossary (MDL-25227)
$sql = "DELETE FROM {glossary_entries}
WHERE NOT EXISTS (
SELECT 'x' FROM {glossary} g
WHERE g.id = glossaryid)";
$DB->execute($sql);

upgrade_mod_savepoint(true, 2010111500, 'glossary');
}
return true;
}

Expand Down
1 change: 1 addition & 0 deletions mod/glossary/lib.php
Expand Up @@ -194,6 +194,7 @@ function glossary_delete_instance($id) {
$category_select = "SELECT id FROM {glossary_categories} WHERE glossaryid = ?";
$DB->delete_records_select('glossary_entries_categories', "categoryid IN ($category_select)", array($id));
$DB->delete_records('glossary_categories', array('glossaryid'=>$id));
$DB->delete_records('glossary_entries', array('glossaryid'=>$id));

// delete all files
$fs->delete_area_files($context->id);
Expand Down
2 changes: 1 addition & 1 deletion mod/glossary/version.php
Expand Up @@ -5,7 +5,7 @@
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////

$module->version = 2010080300;
$module->version = 2010111500;
$module->requires = 2010080300; // Requires this Moodle version
$module->cron = 0; // Period for cron to check this module (secs)

Expand Down

0 comments on commit 3b95347

Please sign in to comment.