Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

- 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
authored October 31, 2003
33  mod/glossary/db/mysql.php
@@ -123,6 +123,39 @@ function glossary_upgrade($oldversion) {
123 123
         execute_sql( "ALTER TABLE `{$CFG->prefix}glossary`" .
124 124
                      " ADD `globalglossary` TINYINT(2) UNSIGNED NOT NULL default '0' AFTER `defaultapproval`");
125 125
     }
  126
+
  127
+    if ( $oldversion < 2003103100 ) {
  128
+        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");
  129
+        if ( $glossaries = get_records("glossary")) {
  130
+            $gids = "";
  131
+            foreach ( $glossaries as $glossary ) {
  132
+                $gids .= "$glossary->id,";
  133
+            }
  134
+            $gids = substr($gids,0,-1);  // ID's of VALID glossaries
  135
+
  136
+            if ($categories = get_records_select("glossary_categories","glossaryid NOT IN ($gids)") ) {
  137
+                $cids = "";
  138
+                foreach ( $categories as $cat ) {
  139
+                    $cids .= "$cat->id,";
  140
+                }
  141
+                $cids = substr($cids,0,-1);   // ID's of INVALID categories
  142
+                if ($cids) {
  143
+                    delete_records_select("glossary_entries_categories", "categoryid IN ($cids)");
  144
+                    delete_records_select("glossary_categories", "id in ($cids)");
  145
+                }
  146
+            }
  147
+            if ( $entries = get_records_select("glossary_entries") ) {
  148
+                $eids = "";
  149
+                foreach ( $entries as $entry ) {
  150
+                    $eids .= "$entry->id,";
  151
+                }
  152
+                $eids = substr($eids,0,-1);  // ID's of VALID entries
  153
+                if ($eids) {
  154
+                    delete_records_select("glossary_comments", "entryid NOT IN ($eids)");
  155
+                }
  156
+            }
  157
+        }
  158
+    }
126 159
     return true;
127 160
 }
128 161
 
24  mod/glossary/lib.php
@@ -73,8 +73,30 @@ function glossary_delete_instance($id) {
73 73
 
74 74
     if (! delete_records("glossary", "id", "$glossary->id")) {
75 75
         $result = false;
  76
+    } else {
  77
+        if ($categories = get_records("glossary_categories","glossaryid",$glossary->id)) {
  78
+            $cats = "";
  79
+            foreach ( $categories as $cat ) {
  80
+                $cats .= "$cat->id,";
  81
+            }
  82
+            $cats = substr($cats,0,-1);
  83
+            if ($cats) {
  84
+                delete_records_select("glossary_entries_categories", "categoryid in ($cats)");
  85
+                delete_records("glossary_categories", "glossaryid", $glossary->id);
  86
+            }
  87
+        }
  88
+        if ( $entries = get_records("glossary_entries", "glossaryid", $glossary->id) ) {
  89
+            $ents = "";
  90
+            foreach ( $entries as $entry ) {
  91
+                $ents .= "$entry->id,";
  92
+            }
  93
+            $ents = substr($ents,0,-1);
  94
+            if ($ents) {
  95
+                delete_records_select("glossary_comments", "entryid in ($ents)");
  96
+            }
  97
+        }
  98
+        delete_records("glossary_entries", "glossaryid", "$glossary->id");
76 99
     }
77  
-    delete_records("glossary_entries", "glossaryid", "$glossary->id");
78 100
 
79 101
     return $result;
80 102
 }
2  mod/glossary/version.php
@@ -5,7 +5,7 @@
5 5
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
6 6
 /////////////////////////////////////////////////////////////////////////////////
7 7
 
8  
-$module->version  = 2003102800;  // The current module version (Date: YYYYMMDDXX)
  8
+$module->version  = 2003103100;  // The current module version (Date: YYYYMMDDXX)
9 9
 $module->cron     = 0;           // Period for cron to check this module (secs)
10 10
 
11 11
 $release = "0.5 development";   // User-friendly version number

0 notes on commit 49210b9

Please sign in to comment.
Something went wrong with that request. Please try again.