Skip to content

Commit

Permalink
- Important update: I did not delete categories nor comments once a g…
Browse files Browse the repository at this point in the history
…lossary has been deleted. Fixed now.
  • Loading branch information
willcast committed Oct 31, 2003
1 parent 40c9e04 commit 49210b9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
33 changes: 33 additions & 0 deletions mod/glossary/db/mysql.php
Expand Up @@ -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;
}

Expand Down
24 changes: 23 additions & 1 deletion mod/glossary/lib.php
Expand Up @@ -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;
}
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 = 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
Expand Down

0 comments on commit 49210b9

Please sign in to comment.