- Important update: I did not delete categories nor comments once a glossary has...
authorwillcast <willcast>
Fri, 31 Oct 2003 15:26:28 +0000 (15:26 +0000)
committerwillcast <willcast>
Fri, 31 Oct 2003 15:26:28 +0000 (15:26 +0000)
mod/glossary/db/mysql.php
mod/glossary/lib.php
mod/glossary/version.php

index e996b6ba9bc4512c004b46234fa0ce8ddf5ad8af..b1b5a15c81edb9e0174db309e0c6b1816e60602b 100644 (file)
@@ -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;
 }
 
index 09f70b0f95295023ad22235fc4e9b04affd75c8f..3c34c2b8dfd490517fb8013f4559a3f0fc87e14d 100644 (file)
@@ -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;
 }
index eac0bd7f6c539aba58eaf9c49f8dad90db8c0264..9234157f99874827c53de44c0d131fc9c4113dd2 100644 (file)
@@ -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