From: stronk7 Date: Tue, 11 Jan 2005 12:40:41 +0000 (+0000) Subject: Delete orphaned categories remaining in server. Bug 2140 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=420158ba419a56aa249545b1ed82a880b345bd85;p=moodle.git Delete orphaned categories remaining in server. Bug 2140 (http://moodle.org/bugs/bug.php?op=show&bugid=2140) --- diff --git a/mod/glossary/db/mysql.php b/mod/glossary/db/mysql.php index 830e6949bc..a292eb2ab2 100644 --- a/mod/glossary/db/mysql.php +++ b/mod/glossary/db/mysql.php @@ -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; } diff --git a/mod/glossary/db/postgres7.php b/mod/glossary/db/postgres7.php index 88e053565f..f3a6130ac4 100644 --- a/mod/glossary/db/postgres7.php +++ b/mod/glossary/db/postgres7.php @@ -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; } diff --git a/mod/glossary/version.php b/mod/glossary/version.php index 8cc0e8513c..78079afcc9 100644 --- a/mod/glossary/version.php +++ b/mod/glossary/version.php @@ -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)