Skip to content

Commit

Permalink
MDL-18577 drop enums support - step1: transforming all enums to nomal…
Browse files Browse the repository at this point in the history
… varchar + prevent creation of new ones
  • Loading branch information
stronk7 committed Apr 27, 2009
1 parent b3d9652 commit e37cd84
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 19 deletions.
2 changes: 1 addition & 1 deletion enrol/authorize/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
11 changes: 11 additions & 0 deletions enrol/authorize/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion enrol/authorize/version.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php // $Id$

$plugin->version = 2008092700;
$plugin->version = 2009042700;
$plugin->requires = 2007101507;

?>
1 change: 1 addition & 0 deletions lang/en_utf8/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
$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';
Expand Down
10 changes: 5 additions & 5 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -2209,4 +2209,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
35 changes: 35 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,41 @@ function xmldb_main_upgrade($oldversion) {
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;
}

Expand Down
27 changes: 22 additions & 5 deletions lib/ddl/database_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,14 @@ public function create_table(xmldb_table $xmldb_table) {
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');
}
Expand All @@ -493,6 +501,14 @@ public function create_temp_table(xmldb_table $xmldb_table) {
$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');
}
Expand Down Expand Up @@ -583,6 +599,11 @@ public function add_field(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
' 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');
}
Expand Down Expand Up @@ -689,11 +710,7 @@ public function change_field_enum(xmldb_table $xmldb_table, xmldb_field $xmldb_f

/// 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() .
Expand Down
4 changes: 2 additions & 2 deletions mod/forum/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down Expand Up @@ -168,4 +168,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
14 changes: 14 additions & 0 deletions mod/forum/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion mod/forum/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions mod/wiki/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down Expand Up @@ -95,4 +95,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
14 changes: 14 additions & 0 deletions mod/wiki/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion mod/wiki/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e37cd84

Please sign in to comment.