Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Important update: I did not delete categories nor comments once a g…

…lossary has been deleted. Fixed now.
  • Loading branch information...
commit 49210b9085cd7731d0d4633289b0981db0484f0b 1 parent 40c9e04
willcast authored
33 mod/glossary/db/mysql.php
View
@@ -123,6 +123,39 @@ function glossary_upgrade($oldversion) {
execute_sql( "ALTER TABLE `{$CFG->prefix}glossary`" .
" ADD `globalglossary` TINYINT(2) UNSIGNED NOT NULL default '0' AFTER `defaultapproval`");
}
+
+ if ( $oldversion < 2003103100 ) {
+ print_simple_box("This update might take several seconds.<p>The more glossaries, entries and categories you have created, the more it will take so please be patient.","center", "50%", "$THEME->cellheading", "20", "noticebox");
+ if ( $glossaries = get_records("glossary")) {
+ $gids = "";
+ foreach ( $glossaries as $glossary ) {
+ $gids .= "$glossary->id,";
+ }
+ $gids = substr($gids,0,-1); // ID's of VALID glossaries
+
+ if ($categories = get_records_select("glossary_categories","glossaryid NOT IN ($gids)") ) {
+ $cids = "";
+ foreach ( $categories as $cat ) {
+ $cids .= "$cat->id,";
+ }
+ $cids = substr($cids,0,-1); // ID's of INVALID categories
+ if ($cids) {
+ delete_records_select("glossary_entries_categories", "categoryid IN ($cids)");
+ delete_records_select("glossary_categories", "id in ($cids)");
+ }
+ }
+ if ( $entries = get_records_select("glossary_entries") ) {
+ $eids = "";
+ foreach ( $entries as $entry ) {
+ $eids .= "$entry->id,";
+ }
+ $eids = substr($eids,0,-1); // ID's of VALID entries
+ if ($eids) {
+ delete_records_select("glossary_comments", "entryid NOT IN ($eids)");
+ }
+ }
+ }
+ }
return true;
}
24 mod/glossary/lib.php
View
@@ -73,8 +73,30 @@ function glossary_delete_instance($id) {
if (! delete_records("glossary", "id", "$glossary->id")) {
$result = false;
+ } else {
+ if ($categories = get_records("glossary_categories","glossaryid",$glossary->id)) {
+ $cats = "";
+ foreach ( $categories as $cat ) {
+ $cats .= "$cat->id,";
+ }
+ $cats = substr($cats,0,-1);
+ if ($cats) {
+ delete_records_select("glossary_entries_categories", "categoryid in ($cats)");
+ delete_records("glossary_categories", "glossaryid", $glossary->id);
+ }
+ }
+ if ( $entries = get_records("glossary_entries", "glossaryid", $glossary->id) ) {
+ $ents = "";
+ foreach ( $entries as $entry ) {
+ $ents .= "$entry->id,";
+ }
+ $ents = substr($ents,0,-1);
+ if ($ents) {
+ delete_records_select("glossary_comments", "entryid in ($ents)");
+ }
+ }
+ delete_records("glossary_entries", "glossaryid", "$glossary->id");
}
- delete_records("glossary_entries", "glossaryid", "$glossary->id");
return $result;
}
2  mod/glossary/version.php
View
@@ -5,7 +5,7 @@
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
-$module->version = 2003102800; // The current module version (Date: YYYYMMDDXX)
+$module->version = 2003103100; // The current module version (Date: YYYYMMDDXX)
$module->cron = 0; // Period for cron to check this module (secs)
$release = "0.5 development"; // User-friendly version number
Please sign in to comment.
Something went wrong with that request. Please try again.