MDL-18577 drop enums support - step1: transforming all enums to nomal varchar + prevent creation of new ones

This commit is contained in:
stronk7 2009-04-27 20:29:01 +00:00
parent b3d965212e
commit e37cd84ad4
14 changed files with 111 additions and 19 deletions

View File

@ -7,7 +7,7 @@
<TABLE NAME="enrol_authorize" COMMENT="Holds all known information about authorize.net transactions" NEXT="enrol_authorize_refunds">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="paymentmethod"/>
<FIELD NAME="paymentmethod" TYPE="char" LENGTH="6" NOTNULL="true" DEFAULT="cc" SEQUENCE="false" ENUM="true" ENUMVALUES="'cc', 'echeck'" PREVIOUS="id" NEXT="refundinfo"/>
<FIELD NAME="paymentmethod" TYPE="char" LENGTH="6" NOTNULL="true" DEFAULT="cc" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="refundinfo"/>
<FIELD NAME="refundinfo" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="paymentmethod" NEXT="ccname"/>
<FIELD NAME="ccname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="refundinfo" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="ccname" NEXT="userid"/>

View File

@ -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;
}

View File

@ -1,6 +1,6 @@
<?php // $Id$
$plugin->version = 2008092700;
$plugin->version = 2009042700;
$plugin->requires = 2007101507;
?>

View File

@ -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';

View File

@ -680,7 +680,7 @@
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="timeend"/>
<FIELD NAME="timeend" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="courseid" NEXT="roleid"/>
<FIELD NAME="roleid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="id of role for the aggregates" PREVIOUS="timeend" NEXT="stattype"/>
<FIELD NAME="stattype" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="activity" SEQUENCE="false" ENUM="true" ENUMVALUES="'enrolments', 'activity', 'logins'" COMMENT="type of stat" PREVIOUS="roleid" NEXT="stat1"/>
<FIELD NAME="stattype" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="activity" SEQUENCE="false" ENUM="false" COMMENT="type of stat" PREVIOUS="roleid" NEXT="stat1"/>
<FIELD NAME="stat1" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="stat1. usually used for reads" PREVIOUS="stattype" NEXT="stat2"/>
<FIELD NAME="stat2" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="stat2. usually used for writes." PREVIOUS="stat1"/>
</FIELDS>
@ -699,7 +699,7 @@
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="timeend"/>
<FIELD NAME="timeend" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="courseid" NEXT="roleid"/>
<FIELD NAME="roleid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="id of role for the aggregates" PREVIOUS="timeend" NEXT="stattype"/>
<FIELD NAME="stattype" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="activity" SEQUENCE="false" ENUM="true" ENUMVALUES="'enrolments', 'activity', 'logins'" COMMENT="type of stat" PREVIOUS="roleid" NEXT="stat1"/>
<FIELD NAME="stattype" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="activity" SEQUENCE="false" ENUM="false" COMMENT="type of stat" PREVIOUS="roleid" NEXT="stat1"/>
<FIELD NAME="stat1" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="stat1. usually used for reads" PREVIOUS="stattype" NEXT="stat2"/>
<FIELD NAME="stat2" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="stat2. usually used for writes." PREVIOUS="stat1"/>
</FIELDS>
@ -718,7 +718,7 @@
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="timeend"/>
<FIELD NAME="timeend" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="courseid" NEXT="roleid"/>
<FIELD NAME="roleid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="id of role for the aggregates" PREVIOUS="timeend" NEXT="stattype"/>
<FIELD NAME="stattype" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="activity" SEQUENCE="false" ENUM="true" ENUMVALUES="'enrolments', 'activity', 'logins'" COMMENT="type of stat" PREVIOUS="roleid" NEXT="stat1"/>
<FIELD NAME="stattype" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="activity" SEQUENCE="false" ENUM="false" COMMENT="type of stat" PREVIOUS="roleid" NEXT="stat1"/>
<FIELD NAME="stat1" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="stat1. usually used for reads" PREVIOUS="stattype" NEXT="stat2"/>
<FIELD NAME="stat2" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="stat2. usually used for writes." PREVIOUS="stat1"/>
</FIELDS>
@ -810,7 +810,7 @@
<FIELD NAME="rating" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="uniquehash" NEXT="format"/>
<FIELD NAME="format" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="rating" NEXT="attachment"/>
<FIELD NAME="attachment" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="attachment" PREVIOUS="format" NEXT="publishstate"/>
<FIELD NAME="publishstate" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="draft" SEQUENCE="false" ENUM="true" ENUMVALUES="'draft', 'site', 'public'" PREVIOUS="attachment" NEXT="lastmodified"/>
<FIELD NAME="publishstate" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="draft" SEQUENCE="false" ENUM="false" PREVIOUS="attachment" NEXT="lastmodified"/>
<FIELD NAME="lastmodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="publishstate" NEXT="created"/>
<FIELD NAME="created" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="lastmodified" NEXT="usermodified"/>
<FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="created"/>
@ -2209,4 +2209,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>

View File

@ -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;
}

View File

@ -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() .

View File

@ -8,7 +8,7 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="course"/>
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="type"/>
<FIELD NAME="type" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="general" SEQUENCE="false" ENUM="true" ENUMVALUES="'single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'" PREVIOUS="course" NEXT="name"/>
<FIELD NAME="type" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="general" SEQUENCE="false" ENUM="false" PREVIOUS="course" NEXT="name"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="type" NEXT="intro"/>
<FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="introformat"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="text format of intro field" PREVIOUS="intro" NEXT="assessed"/>
@ -168,4 +168,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>

View File

@ -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;
}

View File

@ -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;

View File

@ -12,7 +12,7 @@
<FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="introformat"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="intro text field format" PREVIOUS="intro" NEXT="pagename"/>
<FIELD NAME="pagename" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="introformat" NEXT="wtype"/>
<FIELD NAME="wtype" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="group" SEQUENCE="false" ENUM="true" ENUMVALUES="'teacher', 'group', 'student'" PREVIOUS="pagename" NEXT="ewikiprinttitle"/>
<FIELD NAME="wtype" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="group" SEQUENCE="false" ENUM="false" PREVIOUS="pagename" NEXT="ewikiprinttitle"/>
<FIELD NAME="ewikiprinttitle" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="wtype" NEXT="htmlmode"/>
<FIELD NAME="htmlmode" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="ewikiprinttitle" NEXT="ewikiacceptbinary"/>
<FIELD NAME="ewikiacceptbinary" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="htmlmode" NEXT="disablecamelcase"/>
@ -95,4 +95,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>

View File

@ -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;
}

View File

@ -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)

View File

@ -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