mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
MDL-18577 drop enums support - step2: enums out from editor, dbmanager and all upgrade scripts.
This commit is contained in:
parent
3ece3e4273
commit
2a88f626f7
32 changed files with 348 additions and 677 deletions
|
@ -468,14 +468,6 @@ 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');
|
||||
}
|
||||
|
@ -501,14 +493,6 @@ 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');
|
||||
}
|
||||
|
@ -599,11 +583,6 @@ 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');
|
||||
}
|
||||
|
@ -693,13 +672,15 @@ class database_manager {
|
|||
}
|
||||
|
||||
/**
|
||||
* This function will change the enum status of the field in the table passed as arguments
|
||||
* This function will drop the existing enum of the field in the table passed as arguments
|
||||
*
|
||||
* TODO: Moodle 2.1 - Drop drop_enum_from_field()
|
||||
*
|
||||
* @param xmldb_table table object (just the name is mandatory)
|
||||
* @param xmldb_field field object (full specs are required)
|
||||
* @return void
|
||||
*/
|
||||
public function change_field_enum(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
|
||||
public function drop_enum_from_field(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
|
||||
if (!$this->table_exists($xmldb_table)) {
|
||||
throw new ddl_table_missing_exception($xmldb_table->getName());
|
||||
}
|
||||
|
@ -708,18 +689,13 @@ class database_manager {
|
|||
throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());
|
||||
}
|
||||
|
||||
/// If enum is defined, we're going to create it, check it doesn't exist.
|
||||
if ($xmldb_field->getEnum()) {
|
||||
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() .
|
||||
' does not exist. Delete skipped', DEBUG_DEVELOPER);
|
||||
return; //Enum does not exist, nothing to delete
|
||||
}
|
||||
if (!$this->check_constraint_exists($xmldb_table, $xmldb_field)) {
|
||||
debugging('Enum for ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .
|
||||
' does not exist. Delete skipped', DEBUG_DEVELOPER);
|
||||
return; //Enum does not exist, nothing to delete
|
||||
}
|
||||
|
||||
if (!$sqlarr = $this->generator->getModifyEnumSQL($xmldb_table, $xmldb_field)) {
|
||||
if (!$sqlarr = $this->generator->getDropEnumSQL($xmldb_table, $xmldb_field)) {
|
||||
return; //Empty array = nothing to do = no error
|
||||
}
|
||||
|
||||
|
|
|
@ -79,9 +79,6 @@ abstract class sql_generator {
|
|||
public $sequence_name_small = false; //Different name for small (4byte) sequences or false if same
|
||||
public $sequence_only = false; //To avoid to output the rest of the field specs, leaving only the name and the sequence_name publiciable
|
||||
|
||||
public $enum_inline_code = true; //Does the generator need to add inline code in the column definition
|
||||
public $enum_extra_code = true; //Does the generator need to add extra code to generate code for the enums in the table
|
||||
|
||||
public $add_table_comments = true; // Does the generator need to add code for table comments
|
||||
|
||||
public $add_after_clause = false; // Does the generator need to add the after clause for fields
|
||||
|
@ -288,15 +285,6 @@ abstract class sql_generator {
|
|||
}
|
||||
}
|
||||
}
|
||||
/// Add enum extra code if needed
|
||||
if ($this->enum_extra_code) {
|
||||
/// Iterate over fields looking for enums
|
||||
foreach ($xmldb_fields as $xmldb_field) {
|
||||
if ($xmldb_field->getEnum()) {
|
||||
$table .= "\n" . $this->getEnumExtraSQL($xmldb_table, $xmldb_field) . ',';
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Table footer, trim the latest comma
|
||||
$table = trim($table,',');
|
||||
$table .= "\n)";
|
||||
|
@ -434,13 +422,8 @@ abstract class sql_generator {
|
|||
$field = $this->getEncQuoted($xmldb_field->getName());
|
||||
/// The type and length only if we don't want to skip it
|
||||
if (!$skip_type_clause) {
|
||||
/// The type and length (if the field isn't enum)
|
||||
if (!$xmldb_field->getEnum() || $this->enum_inline_code == false) {
|
||||
$field .= ' ' . $this->getTypeSQL($xmldb_field->getType(), $xmldb_field->getLength(), $xmldb_field->getDecimals());
|
||||
} else {
|
||||
/// call to custom function
|
||||
$field .= ' ' . $this->getEnumSQL($xmldb_field);
|
||||
}
|
||||
/// The type and length
|
||||
$field .= ' ' . $this->getTypeSQL($xmldb_field->getType(), $xmldb_field->getLength(), $xmldb_field->getDecimals());
|
||||
}
|
||||
/// The unsigned if supported
|
||||
if ($this->unsigned_allowed && ($xmldb_field->getType() == XMLDB_TYPE_INTEGER ||
|
||||
|
@ -651,14 +634,6 @@ abstract class sql_generator {
|
|||
}
|
||||
$results[] = $altertable;
|
||||
|
||||
/// If the DB has extra enum code
|
||||
if ($this->enum_extra_code) {
|
||||
/// If it's enum add the extra code
|
||||
if ($xmldb_field->getEnum()) {
|
||||
$results[] = 'ALTER TABLE ' . $tablename . ' ADD ' . $this->getEnumExtraSQL($xmldb_table, $xmldb_field);
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
@ -713,27 +688,6 @@ abstract class sql_generator {
|
|||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one xmldb_table and one xmldb_field, return the SQL statements needded to modify the enum of the field in the table
|
||||
*/
|
||||
public function getModifyEnumSQL($xmldb_table, $xmldb_field) {
|
||||
|
||||
$results = array();
|
||||
|
||||
/// Get the quoted name of the table and field
|
||||
$tablename = $this->getTableName($xmldb_table);
|
||||
$fieldname = $this->getEncQuoted($xmldb_field->getName());
|
||||
|
||||
/// Decide if we are going to create or to drop the enum (based exclusively in the values passed!)
|
||||
if (!$xmldb_field->getEnum()) {
|
||||
$results = $this->getDropEnumSQL($xmldb_table, $xmldb_field); //Drop
|
||||
} else {
|
||||
$results = $this->getCreateEnumSQL($xmldb_table, $xmldb_field); //Create/modify
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one xmldb_table and one xmldb_field, return the SQL statements needded to modify the default of the field in the table
|
||||
*/
|
||||
|
@ -1180,20 +1134,6 @@ abstract class sql_generator {
|
|||
*/
|
||||
public abstract function getTypeSQL($xmldb_type, $xmldb_length=null, $xmldb_decimals=null);
|
||||
|
||||
/**
|
||||
* Given one XMLDB Field, return its enum SQL to be added inline with the column definition
|
||||
*/
|
||||
public function getEnumSQL($xmldb_field) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code needed to create one enum for the xmldb_table and xmldb_field passes
|
||||
*/
|
||||
public function getEnumExtraSQL($xmldb_table, $xmldb_field) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code (array of statements) needed to execute extra statements on field rename
|
||||
*/
|
||||
|
@ -1231,15 +1171,11 @@ abstract class sql_generator {
|
|||
/**
|
||||
* Given one xmldb_table and one xmldb_field, return the SQL statements needded to drop its enum
|
||||
* (usually invoked from getModifyEnumSQL()
|
||||
*
|
||||
* TODO: Moodle 2.1 - Drop getDropEnumSQL()
|
||||
*/
|
||||
public abstract function getDropEnumSQL($xmldb_table, $xmldb_field);
|
||||
|
||||
/**
|
||||
* Given one xmldb_table and one xmldb_field, return the SQL statements needded to add its enum
|
||||
* (usually invoked from getModifyEnumSQL()
|
||||
*/
|
||||
public abstract function getCreateEnumSQL($xmldb_table, $xmldb_field);
|
||||
|
||||
/**
|
||||
* Given one xmldb_table and one xmldb_field, return the SQL statements needded to drop its default
|
||||
* (usually invoked from getModifyDefaultSQL()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue