]> git.mjollnir.org Git - moodle.git/commitdiff
Delete orphaned categories remaining in server. Bug 2140
authorstronk7 <stronk7>
Tue, 11 Jan 2005 12:40:41 +0000 (12:40 +0000)
committerstronk7 <stronk7>
Tue, 11 Jan 2005 12:40:41 +0000 (12:40 +0000)
(http://moodle.org/bugs/bug.php?op=show&bugid=2140)

mod/glossary/db/mysql.php
mod/glossary/db/postgres7.php
mod/glossary/version.php

index 830e6949bcc4f0e7ab0fbc2ce682e8d01f54eaa4..a292eb2ab2569d9179a6ecaa307cd5ba9c24d173 100644 (file)
@@ -373,6 +373,19 @@ function glossary_upgrade($oldversion) {
       modify_database('','ALTER TABLE prefix_glossary_ratings ADD INDEX entryid (entryid);');
 
   }
+
+  //Delete orphaned categories (bug 2140)
+  if ($oldversion < 2005011100) {
+      $categories = get_records('glossary_categories', '', '', '', 'id, glossaryid');
+      if ($categories) {
+          foreach ($categories as $category) {
+              $glossary = get_record('glossary', 'id', "$category->glossaryid");
+              if (!$glossary) {
+                  delete_records('glossary_categories', 'id', "$category->id");
+              }
+          }
+      }
+  }
     
   return true;
 }
index 88e053565f5fdf22e323bf2e5cb4ef2862a851f7..f3a6130ac4085674e9fd172d52bd897c5cebf1e9 100644 (file)
@@ -134,6 +134,19 @@ function glossary_upgrade($oldversion) {
       modify_database('','CREATE INDEX prefix_glossary_ratings_entryid_idx ON prefix_glossary_ratings (entryid);');
   }
 
+  //Delete orphaned categories (bug 2140)
+  if ($oldversion < 2005011100) {
+      $categories = get_records('glossary_categories', '', '', '', 'id, glossaryid');
+      if ($categories) {
+          foreach ($categories as $category) {
+              $glossary = get_record('glossary', 'id', "$category->glossaryid");
+              if (!$glossary) {
+                  delete_records('glossary_categories', 'id', "$category->id");
+              }
+          }
+      }
+  }
+
   return true;
 }
 
index 8cc0e8513c63bcf2605749f9845341718b03b824..78079afcc98c78e120a7c5b75d5c8ef6566ca729 100644 (file)
@@ -5,7 +5,7 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004111200;
+$module->version  = 2005011100;
 $module->requires = 2004112300;  // Requires this Moodle version
 $module->cron     = 0;           // Period for cron to check this module (secs)