From e37cd84ad4a7abb4fcd51a9c6a762c43ca196bb0 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Mon, 27 Apr 2009 20:29:01 +0000 Subject: [PATCH] MDL-18577 drop enums support - step1: transforming all enums to nomal varchar + prevent creation of new ones --- enrol/authorize/db/install.xml | 2 +- enrol/authorize/db/upgrade.php | 11 +++++++++++ enrol/authorize/version.php | 2 +- lang/en_utf8/error.php | 1 + lib/db/install.xml | 10 +++++----- lib/db/upgrade.php | 35 ++++++++++++++++++++++++++++++++++ lib/ddl/database_manager.php | 27 +++++++++++++++++++++----- mod/forum/db/install.xml | 4 ++-- mod/forum/db/upgrade.php | 14 ++++++++++++++ mod/forum/version.php | 2 +- mod/wiki/db/install.xml | 4 ++-- mod/wiki/db/upgrade.php | 14 ++++++++++++++ mod/wiki/version.php | 2 +- version.php | 2 +- 14 files changed, 111 insertions(+), 19 deletions(-) diff --git a/enrol/authorize/db/install.xml b/enrol/authorize/db/install.xml index f559023bb1..54e643eef1 100644 --- a/enrol/authorize/db/install.xml +++ b/enrol/authorize/db/install.xml @@ -7,7 +7,7 @@ - + diff --git a/enrol/authorize/db/upgrade.php b/enrol/authorize/db/upgrade.php index 64a75bbb09..4966fe9efb 100644 --- a/enrol/authorize/db/upgrade.php +++ b/enrol/authorize/db/upgrade.php @@ -74,6 +74,17 @@ function xmldb_enrol_authorize_upgrade($oldversion) { $dbman->add_index($table, $index); } + /// Dropping all enums/check contraints from core. MDL-18577 + if ($result && $oldversion < 2009042700) { + + /// Changing list of values (enum) of field paymentmethod on table enrol_authorize to none + $table = new xmldb_table('enrol_authorize'); + $field = new xmldb_field('paymentmethod', XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, null, null, 'cc', 'id'); + + /// Launch change of list of values for field paymentmethod + $dbman->change_field_enum($table, $field); + } + return $result; } diff --git a/enrol/authorize/version.php b/enrol/authorize/version.php index 13afaaaa21..d5270fd7d1 100755 --- a/enrol/authorize/version.php +++ b/enrol/authorize/version.php @@ -1,6 +1,6 @@ version = 2008092700; +$plugin->version = 2009042700; $plugin->requires = 2007101507; ?> diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index 2afdc6d16c..3c09409f38 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -195,6 +195,7 @@ $string['ddlfieldnotexist'] = 'Field \"$a->fieldname\" does not exist in table \ $string['ddltablealreadyexists'] = 'Table \"$a\" already exists'; $string['ddltablenotexist'] = 'Table \"$a\" does not exist'; $string['ddlunknownerror'] = 'Unknown DDL library error'; +$string['ddlunsupportedenums'] = 'Field \"$a\" contains enum info. Enums support has been dropped in Moodle 2.0. Please modify your code to avoid them completely. If you are already using them, please use \$dbman->change_field_enum(\$table, \$field); in your upgrade scripts to drop them ASAP'; $string['ddlxmlfileerror'] = 'XML database file errors found'; $string['dmlreadexception'] = 'Error reading from database'; $string['dmlwriteexception'] = 'Error writing to database'; diff --git a/lib/db/install.xml b/lib/db/install.xml index afe17d3e6c..5d2a59deb2 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -680,7 +680,7 @@ - + @@ -699,7 +699,7 @@ - + @@ -718,7 +718,7 @@ - + @@ -810,7 +810,7 @@ - + @@ -2209,4 +2209,4 @@
- \ No newline at end of file + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 8e5cc3d2e7..bcda99f833 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1667,6 +1667,41 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint($result, 2009042600); } + /// Dropping all enums/check contraints from core. MDL-18577 + if ($result && $oldversion < 2009042700) { + + /// Changing list of values (enum) of field stattype on table stats_daily to none + $table = new xmldb_table('stats_daily'); + $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'activity', 'roleid'); + + /// Launch change of list of values for field stattype + $dbman->change_field_enum($table, $field); + + /// Changing list of values (enum) of field stattype on table stats_weekly to none + $table = new xmldb_table('stats_weekly'); + $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'activity', 'roleid'); + + /// Launch change of list of values for field stattype + $dbman->change_field_enum($table, $field); + + /// Changing list of values (enum) of field stattype on table stats_monthly to none + $table = new xmldb_table('stats_monthly'); + $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'activity', 'roleid'); + + /// Launch change of list of values for field stattype + $dbman->change_field_enum($table, $field); + + /// Changing list of values (enum) of field publishstate on table post to none + $table = new xmldb_table('post'); + $field = new xmldb_field('publishstate', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'draft', 'attachment'); + + /// Launch change of list of values for field publishstate + $dbman->change_field_enum($table, $field); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042700); + } + return $result; } diff --git a/lib/ddl/database_manager.php b/lib/ddl/database_manager.php index b048f8d148..fc5a849a91 100644 --- a/lib/ddl/database_manager.php +++ b/lib/ddl/database_manager.php @@ -468,6 +468,14 @@ class database_manager { throw new ddl_exception('ddltablealreadyexists', $xmldb_table->getName()); } + /// Iterate over all fields in table, finding any attempt to add one field with enum info, throw exception + $xmldb_fields = $xmldb_table->getFields(); + foreach ($xmldb_fields as $xmldb_field) { + if ($xmldb_field->getEnum()) { + throw new ddl_exception('ddlunsupportedenums', $xmldb_table->getName() . '->' . $xmldb_field->getName()); + } + } + if (!$sqlarr = $this->generator->getCreateTableSQL($xmldb_table)) { throw new ddl_exception('ddlunknownerror', null, 'table create sql not generated'); } @@ -493,6 +501,14 @@ class database_manager { $this->drop_temp_table($xmldb_table); } + /// Iterate over all fields in table, finding any attempt to add one field with enum info, throw exception + $xmldb_fields = $xmldb_table->getFields(); + foreach ($xmldb_fields as $xmldb_field) { + if ($xmldb_field->getEnum()) { + throw new ddl_exception('ddlunsupportedenums', $xmldb_table->getName() . '->' . $xmldb_field->getName()); + } + } + if (!$sqlarr = $this->generator->getCreateTempTableSQL($xmldb_table)) { throw new ddl_exception('ddlunknownerror', null, 'temp table create sql not generated'); } @@ -583,6 +599,11 @@ class database_manager { ' cannot be added. Not null fields added to non empty tables require default value. Create skipped'); } + /// Detect any attempt to add one field with enum info, throw exception + if ($xmldb_field->getEnum()) { + throw new ddl_exception('ddlunsupportedenums', $xmldb_table->getName() . '->' . $xmldb_field->getName()); + } + if (!$sqlarr = $this->generator->getAddFieldSQL($xmldb_table, $xmldb_field)) { throw new ddl_exception('ddlunknownerror', null, 'addfield sql not generated'); } @@ -689,11 +710,7 @@ class database_manager { /// If enum is defined, we're going to create it, check it doesn't exist. if ($xmldb_field->getEnum()) { - if ($this->check_constraint_exists($xmldb_table, $xmldb_field)) { - debugging('Enum for ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() . - ' already exists. Create skipped', DEBUG_DEVELOPER); - return; //Enum exists, nothing to do - } + throw new ddl_exception('ddlunsupportedenums', $xmldb_table->getName() . '->' . $xmldb_field->getName()); } else { /// Else, we're going to drop it, check it exists if (!$this->check_constraint_exists($xmldb_table, $xmldb_field)) { debugging('Enum for ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() . diff --git a/mod/forum/db/install.xml b/mod/forum/db/install.xml index d07b8e5c2f..29d53f62e3 100644 --- a/mod/forum/db/install.xml +++ b/mod/forum/db/install.xml @@ -8,7 +8,7 @@ - + @@ -168,4 +168,4 @@ - \ No newline at end of file + diff --git a/mod/forum/db/upgrade.php b/mod/forum/db/upgrade.php index 8a1e4a5842..9aa009d9f5 100644 --- a/mod/forum/db/upgrade.php +++ b/mod/forum/db/upgrade.php @@ -241,6 +241,20 @@ function xmldb_forum_upgrade($oldversion) { upgrade_mod_savepoint($result, 2009042004, 'forum'); } + /// Dropping all enums/check contraints from core. MDL-18577 + if ($result && $oldversion < 2009042700) { + + /// Changing list of values (enum) of field type on table forum to none + $table = new xmldb_table('forum'); + $field = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course'); + + /// Launch change of list of values for field type + $dbman->change_field_enum($table, $field); + + /// forum savepoint reached + upgrade_mod_savepoint($result, 2009042700, 'forum'); + } + return $result; } diff --git a/mod/forum/version.php b/mod/forum/version.php index 11567b9981..20aab4ba68 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2009042004; +$module->version = 2009042700; $module->requires = 2009041700; // Requires this Moodle version $module->cron = 60; diff --git a/mod/wiki/db/install.xml b/mod/wiki/db/install.xml index 21095d0a8e..d079818edb 100644 --- a/mod/wiki/db/install.xml +++ b/mod/wiki/db/install.xml @@ -12,7 +12,7 @@ - + @@ -95,4 +95,4 @@ - \ No newline at end of file + diff --git a/mod/wiki/db/upgrade.php b/mod/wiki/db/upgrade.php index 0120a1aa58..37663d5e43 100644 --- a/mod/wiki/db/upgrade.php +++ b/mod/wiki/db/upgrade.php @@ -54,6 +54,20 @@ function xmldb_wiki_upgrade($oldversion) { upgrade_mod_savepoint($result, 2009042001, 'wiki'); } +/// Dropping all enums/check contraints from core. MDL-18577 + if ($result && $oldversion < 2009042700) { + + /// Changing list of values (enum) of field wtype on table wiki to none + $table = new xmldb_table('wiki'); + $field = new xmldb_field('wtype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'group', 'pagename'); + + /// Launch change of list of values for field wtype + $dbman->change_field_enum($table, $field); + + /// wiki savepoint reached + upgrade_mod_savepoint($result, 2009042700, 'wiki'); + } + return $result; } diff --git a/mod/wiki/version.php b/mod/wiki/version.php index a452a7e55e..70bca1d4e0 100644 --- a/mod/wiki/version.php +++ b/mod/wiki/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2009042001; // The current module version (Date: YYYYMMDDXX) +$module->version = 2009042700; // The current module version (Date: YYYYMMDDXX) $module->requires = 2009041700; // The current module version (Date: YYYYMMDDXX) $module->cron = 3600; // Period for cron to check this module (secs) diff --git a/version.php b/version.php index 6e9adc9ab8..1969f6e729 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2009042600; // YYYYMMDD = date of the last version bump + $version = 2009042700; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20090427)'; // Human-friendly version name -- 2.39.5