mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +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
|
@ -1,7 +1,8 @@
|
|||
<!ELEMENT FIELD EMPTY >
|
||||
<!ATTLIST FIELD DECIMALS NMTOKEN #IMPLIED >
|
||||
<!ATTLIST FIELD DEFAULT NMTOKEN #IMPLIED >
|
||||
<!ATTLIST FIELD ENUM ( false | true ) #REQUIRED >
|
||||
<!-- TODO: Moodle 2.1 - Drop ENUM and ENUMVALUES attributes -->
|
||||
<!ATTLIST FIELD ENUM ( false | true ) #IMPLIED >
|
||||
<!ATTLIST FIELD ENUMVALUES CDATA #IMPLIED >
|
||||
<!ATTLIST FIELD LENGTH NMTOKEN #REQUIRED >
|
||||
<!ATTLIST FIELD NAME NMTOKEN #REQUIRED >
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
<xs:attribute name="NOTNULL" type="trueFalse" use="required" />
|
||||
<xs:attribute name="DECIMALS" type="xs:positiveInteger" use="optional" />
|
||||
<xs:attribute name="UNSIGNED" type="trueFalse" use="optional" />
|
||||
<!-- TODO: Moodle 2.1 - Drop ENUM and ENUMVALUES attributes -->
|
||||
<xs:attribute name="ENUM" type="trueFalse" use="optional" />
|
||||
<xs:attribute name="ENUMVALUES" type="xs:string" use="optional" />
|
||||
<xs:attribute name="DEFAULT" type="xs:string" use="optional" />
|
||||
|
@ -199,4 +200,4 @@
|
|||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
</xs:schema>
|
||||
</xs:schema>
|
||||
|
|
|
@ -63,7 +63,6 @@
|
|||
define ('XMLDB_UNSIGNED', true); //If the field is going to be unsigned
|
||||
define ('XMLDB_NOTNULL', true); //If the field is going to be not null
|
||||
define ('XMLDB_SEQUENCE', true); //If the field is going to be a sequence
|
||||
define ('XMLDB_ENUM', true); //If the field is going to be a enumeration of possible fields
|
||||
define ('XMLDB_INDEX_UNIQUE', true); //If the index is going to be unique
|
||||
define ('XMLDB_INDEX_NOTUNIQUE',false); //If the index is NOT going to be unique
|
||||
|
||||
|
|
|
@ -34,25 +34,21 @@ class xmldb_field extends xmldb_object {
|
|||
var $notnull;
|
||||
var $default;
|
||||
var $sequence;
|
||||
var $enum;
|
||||
var $enumvalues;
|
||||
var $decimals;
|
||||
|
||||
/**
|
||||
* Creates one new xmldb_field
|
||||
*/
|
||||
function __construct($name, $type=null, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $enum=null, $enumvalues=null, $default=null, $previous=null) {
|
||||
function __construct($name, $type=null, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $default=null, $previous=null) {
|
||||
$this->type = NULL;
|
||||
$this->length = NULL;
|
||||
$this->unsigned = true;
|
||||
$this->notnull = false;
|
||||
$this->default = NULL;
|
||||
$this->sequence = false;
|
||||
$this->enum = false;
|
||||
$this->enumvalues = NULL;
|
||||
$this->decimals = NULL;
|
||||
parent::__construct($name);
|
||||
$this->set_attributes($type, $precision, $unsigned, $notnull, $sequence, $enum, $enumvalues, $default, $previous);
|
||||
$this->set_attributes($type, $precision, $unsigned, $notnull, $sequence, $default, $previous);
|
||||
}
|
||||
|
||||
/// TODO: Delete for 2.1 (deprecated in 2.0).
|
||||
|
@ -61,8 +57,11 @@ class xmldb_field extends xmldb_object {
|
|||
function setAttributes($type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $enum=null, $enumvalues=null, $default=null, $previous=null) {
|
||||
|
||||
debugging('XMLDBField->setAttributes() has been deprecated in Moodle 2.0. Will be out in Moodle 2.1. Please use xmldb_field->set_attributes() instead.', DEBUG_DEVELOPER);
|
||||
if ($enum) {
|
||||
debugging('Also, ENUMs support has been dropped in Moodle 2.0. Your fields specs are incorrect because you are trying to introduce one new ENUM. Created DB estructures will ignore that.');
|
||||
}
|
||||
|
||||
return $this->set_attributes($type, $precision, $unsigned, $notnull, $sequence, $enum, $enumvalues, $default, $previous);
|
||||
return $this->set_attributes($type, $precision, $unsigned, $notnull, $sequence, $default, $previous);
|
||||
}
|
||||
/// Deprecated API ends here
|
||||
|
||||
|
@ -74,11 +73,9 @@ class xmldb_field extends xmldb_object {
|
|||
* @param string unsigned XMLDB_UNSIGNED or null (or false)
|
||||
* @param string notnull XMLDB_NOTNULL or null (or false)
|
||||
* @param string sequence XMLDB_SEQUENCE or null (or false)
|
||||
* @param string enum XMLDB_ENUM or null (or false)
|
||||
* @param array enumvalues an array of possible values if XMLDB_ENUM is set
|
||||
* @param string default meaningful default o null (or false)
|
||||
*/
|
||||
function set_attributes($type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $enum=null, $enumvalues=null, $default=null, $previous=null) {
|
||||
function set_attributes($type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $default=null, $previous=null) {
|
||||
$this->type = $type;
|
||||
/// Try to split the precision into length and decimals and apply
|
||||
/// each one as needed
|
||||
|
@ -93,18 +90,6 @@ class xmldb_field extends xmldb_object {
|
|||
$this->unsigned = !empty($unsigned) ? true : false;
|
||||
$this->notnull = !empty($notnull) ? true : false;
|
||||
$this->sequence = !empty($sequence) ? true : false;
|
||||
$this->enum = !empty($enum) ? true : false;
|
||||
/// Accept both quoted and non-quoted vales (quoting them)a
|
||||
if (is_array($enumvalues)) {
|
||||
$this->enumvalues = array();
|
||||
foreach ($enumvalues as $value) {
|
||||
/// trim each value quotes
|
||||
$value = trim($value, "'");
|
||||
/// add them back
|
||||
$value = "'" . $value . "'";
|
||||
$this->enumvalues[] = $value;
|
||||
}
|
||||
}
|
||||
$this->setDefault($default);
|
||||
|
||||
$this->previous = $previous;
|
||||
|
@ -152,20 +137,6 @@ class xmldb_field extends xmldb_object {
|
|||
return $this->sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the enum
|
||||
*/
|
||||
function getEnum() {
|
||||
return $this->enum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the enumvalues
|
||||
*/
|
||||
function getEnumValues() {
|
||||
return $this->enumvalues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default
|
||||
*/
|
||||
|
@ -215,29 +186,6 @@ class xmldb_field extends xmldb_object {
|
|||
$this->sequence = $sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field enum
|
||||
*/
|
||||
function setEnum($enum=true) {
|
||||
$this->enum = $enum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field enumvalues, quoting unquoted values
|
||||
*/
|
||||
function setEnumValues($enumvalues) {
|
||||
if (is_array($enumvalues)) {
|
||||
$this->enumvalues = array();
|
||||
foreach ($enumvalues as $value) {
|
||||
/// trim each value quotes
|
||||
$value = trim($value, "'");
|
||||
/// add them back
|
||||
$value = "'" . $value . "'";
|
||||
$this->enumvalues[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field default
|
||||
*/
|
||||
|
@ -265,8 +213,7 @@ class xmldb_field extends xmldb_object {
|
|||
/// $GLOBALS['traverse_array']=""; //Debug
|
||||
|
||||
/// Process table attributes (name, type, length, unsigned,
|
||||
/// notnull, sequence, enum, enumvalues, decimals, comment,
|
||||
/// previous, next)
|
||||
/// notnull, sequence, decimals, comment, previous, next)
|
||||
if (isset($xmlarr['@']['NAME'])) {
|
||||
$this->name = trim($xmlarr['@']['NAME']);
|
||||
} else {
|
||||
|
@ -368,62 +315,6 @@ class xmldb_field extends xmldb_object {
|
|||
$this->setDefault(trim($xmlarr['@']['DEFAULT']));
|
||||
}
|
||||
|
||||
if (isset($xmlarr['@']['ENUM'])) {
|
||||
$enum = strtolower(trim($xmlarr['@']['ENUM']));
|
||||
if ($enum == 'true') {
|
||||
$this->enum = true;
|
||||
} else if ($enum == 'false') {
|
||||
$this->enum = false;
|
||||
} else {
|
||||
$this->errormsg = 'Incorrect ENUM attribute (true/false allowed)';
|
||||
$this->debug($this->errormsg);
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($xmlarr['@']['ENUMVALUES'])) {
|
||||
$enumvalues = trim($xmlarr['@']['ENUMVALUES']);
|
||||
if (!$this->enum) {
|
||||
$this->errormsg = 'Wrong ENUMVALUES attribute (not ENUM)';
|
||||
$this->debug($this->errormsg);
|
||||
$result = false;
|
||||
$this->enumvalues = $enumvalues;
|
||||
} else {
|
||||
/// Check we have a valid list (comma separated of quoted values)
|
||||
$enumarr = explode(',',$enumvalues);
|
||||
if ($enumarr) {
|
||||
foreach ($enumarr as $key => $enumelement) {
|
||||
/// Clear some spaces
|
||||
$enumarr[$key] = trim($enumelement);
|
||||
$enumelement = trim($enumelement);
|
||||
/// Skip if under error
|
||||
if (!$result) {
|
||||
continue;
|
||||
}
|
||||
/// Look for quoted strings
|
||||
if (substr($enumelement, 0, 1) != "'" ||
|
||||
substr($enumelement, -1, 1) != "'") {
|
||||
$this->errormsg = 'Incorrect ENUMVALUES attribute (some value is not properly quoted)';
|
||||
$this->debug($this->errormsg);
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->errormsg = 'Incorrect ENUMVALUES attribute (comma separated of quoted values)';
|
||||
$this->debug($this->errormsg);
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
} else if ($this->enum) {
|
||||
$this->errormsg = 'Incorrect ENUMVALUES attribute (field is not declared as ENUM)';
|
||||
$this->debug($this->errormsg);
|
||||
$result = false;
|
||||
}
|
||||
/// Finally, set the value
|
||||
if ($this->enum) {
|
||||
$this->enumvalues = $enumarr;
|
||||
}
|
||||
|
||||
$decimals = NULL;
|
||||
if (isset($xmlarr['@']['DECIMALS'])) {
|
||||
$decimals = trim($xmlarr['@']['DECIMALS']);
|
||||
|
@ -555,9 +446,6 @@ class xmldb_field extends xmldb_object {
|
|||
$key = $this->name . $this->type . $this->length .
|
||||
$this->unsigned . $this->notnull . $this->sequence .
|
||||
$this->decimals . $this->comment;
|
||||
if ($this->enum) {
|
||||
$key .= implode(', ',$this->enumvalues);
|
||||
}
|
||||
$this->hash = md5($key);
|
||||
}
|
||||
}
|
||||
|
@ -602,15 +490,6 @@ class xmldb_field extends xmldb_object {
|
|||
$sequence = 'false';
|
||||
}
|
||||
$o.= ' SEQUENCE="' . $sequence . '"';
|
||||
if ($this->enum) {
|
||||
$enum = 'true';
|
||||
} else {
|
||||
$enum = 'false';
|
||||
}
|
||||
$o.= ' ENUM="' . $enum . '"';
|
||||
if ($this->enum) {
|
||||
$o.= ' ENUMVALUES="' . implode(', ', $this->enumvalues) . '"';
|
||||
}
|
||||
if ($this->decimals !== NULL) {
|
||||
$o.= ' DECIMALS="' . $this->decimals . '"';
|
||||
}
|
||||
|
@ -745,11 +624,6 @@ class xmldb_field extends xmldb_object {
|
|||
/// Sequence fields are always unsigned
|
||||
$this->unsigned = true;
|
||||
}
|
||||
/// Calculate the enum and enumvalues field
|
||||
if ($adofield->type == 'enum') {
|
||||
$this->enum = true;
|
||||
$this->enumvalues = $adofield->enums;
|
||||
}
|
||||
/// Some more fields
|
||||
$this->loaded = true;
|
||||
$this->changed = true;
|
||||
|
@ -823,20 +697,6 @@ class xmldb_field extends xmldb_object {
|
|||
} else {
|
||||
$result .= 'null, ';
|
||||
}
|
||||
/// Enum
|
||||
$enum = $this->getEnum();
|
||||
if (!empty($enum)) {
|
||||
$result .= 'XMLDB_ENUM' . ', ';
|
||||
} else {
|
||||
$result .= 'null, ';
|
||||
}
|
||||
/// Enumvalues
|
||||
$enumvalues = $this->getEnumValues();
|
||||
if (!empty($enumvalues)) {
|
||||
$result .= 'array(' . implode(', ', $enumvalues) . '), ';
|
||||
} else {
|
||||
$result .= 'null, ';
|
||||
}
|
||||
/// Default
|
||||
$default = $this->getDefault();
|
||||
if ($default !== null && !$this->getSequence()) {
|
||||
|
@ -884,10 +744,6 @@ class xmldb_field extends xmldb_object {
|
|||
$this->type == XMLDB_TYPE_BINARY) {
|
||||
$o .= ' (' . $this->length . ')';
|
||||
}
|
||||
/// enum
|
||||
if ($this->enum) {
|
||||
$o .= ' enum(' . implode(', ', $this->enumvalues) . ')';
|
||||
}
|
||||
/// unsigned
|
||||
if ($this->type == XMLDB_TYPE_INTEGER ||
|
||||
$this->type == XMLDB_TYPE_NUMBER ||
|
||||
|
|
|
@ -700,8 +700,11 @@ class xmldb_table extends xmldb_object {
|
|||
function addFieldInfo($name, $type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $enum=null, $enumvalues=null, $default=null, $previous=null) {
|
||||
|
||||
debugging('XMLDBTable->addFieldInfo() has been deprecated in Moodle 2.0. Will be out in Moodle 2.1. Please use xmldb_table->add_field() instead', DEBUG_DEVELOPER);
|
||||
if ($enum) {
|
||||
debugging('Also, ENUMs support has been dropped in Moodle 2.0. Your fields specs are incorrect because you are trying to introduce one new ENUM. Created DB estructures will ignore that.');
|
||||
}
|
||||
|
||||
return $this->add_field($name, $type, $precision, $unsigned, $notnull, $sequence, $enum, $enumvalues, $default, $previous);
|
||||
return $this->add_field($name, $type, $precision, $unsigned, $notnull, $sequence, $default, $previous);
|
||||
|
||||
}
|
||||
/// Deprecated API ends here
|
||||
|
@ -716,13 +719,11 @@ class xmldb_table extends xmldb_object {
|
|||
* @param string unsigned XMLDB_UNSIGNED or null (or false)
|
||||
* @param string notnull XMLDB_NOTNULL or null (or false)
|
||||
* @param string sequence XMLDB_SEQUENCE or null (or false)
|
||||
* @param string enum XMLDB_ENUM or null (or false)
|
||||
* @param array enumvalues an array of possible values if XMLDB_ENUM is set
|
||||
* @param string default meaningful default o null (or false)
|
||||
* @param string previous name of the previous field in the table or null (or false)
|
||||
*/
|
||||
function add_field($name, $type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $enum=null, $enumvalues=null, $default=null, $previous=null) {
|
||||
$field = new xmldb_field($name, $type, $precision, $unsigned, $notnull, $sequence, $enum, $enumvalues, $default);
|
||||
function add_field($name, $type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $default=null, $previous=null) {
|
||||
$field = new xmldb_field($name, $type, $precision, $unsigned, $notnull, $sequence, $default);
|
||||
$this->addField($field, $previous);
|
||||
|
||||
return $field;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue