Ending fied/key/index PHP generators.

This commit is contained in:
stronk7
2006-11-02 23:07:44 +00:00
parent 6abfa47012
commit 98ed0ea1af
@@ -119,13 +119,12 @@ class view_table_php extends XMLDBAction {
$commands = array('Fields',
$optionspacer . 'add_field',
$optionspacer . 'drop_field',
$optionspacer . 'rename_field (not imp!)',
$optionspacer . 'rename_field',
$optionspacer . 'change_field_type',
$optionspacer . 'change_field_precision',
$optionspacer . 'change_field_unsigned',
$optionspacer . 'change_field_notnull',
$optionspacer . 'change_field_sequence (not imp!)',
$optionspacer . 'change_field_enum (not imp!)',
$optionspacer . 'change_field_enum',
$optionspacer . 'change_field_default',
'Keys',
$optionspacer . 'add_key',
@@ -229,6 +228,13 @@ class view_table_php extends XMLDBAction {
$o.= $this->str['mustselectonefield'];
}
break;
case 'change_field_enum':
if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
$o.= s($this->change_field_enum_php($structure, $tableparam, $fieldkeyindexparam));
} else {
$o.= $this->str['mustselectonefield'];
}
break;
case 'change_field_default':
if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
$o.= s($this->change_field_default_php($structure, $tableparam, $fieldkeyindexparam));
@@ -619,6 +625,53 @@ class view_table_php extends XMLDBAction {
return $result;
}
/**
* This function will generate all the PHP code needed to
* change the enum values (check constraint) of one field
* using XMLDB objects and functions
*
* @param XMLDBStructure structure object containing all the info
* @param string table table name
* @param string field field name to change its enum
*/
function change_field_enum_php($structure, $table, $field) {
$result = '';
/// Validate if we can do it
if (!$table = $structure->getTable($table)) {
return false;
}
if (!$field = $table->getField($field)) {
return false;
}
if ($table->getAllErrors()) {
return false;
}
/// Calculate the enum tip text
$enum = $field->getEnum() ? implode(', ', $field->getEnumValues()) : 'none';
/// Add the standard PHP header
$result .= XMLDB_PHP_HEADER;
/// Add contents
$result .= XMLDB_LINEFEED;
$result .= ' /// Changing list of values (enum) of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $enum . XMLDB_LINEFEED;
$result .= ' $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
$result .= ' $field = new XMLDBField(' . "'" . $field->getName() . "'" . ');' . XMLDB_LINEFEED;
$result .= ' $field->setAttributes(' . $field->getPHP(true) . ');' . XMLDB_LINEFEED;
/// Launch the proper DDL
$result .= XMLDB_LINEFEED;
$result .= ' /// Launch change of list of values for field ' . $field->getName() . XMLDB_LINEFEED;
$result .= ' $status = $status && change_field_enum($table, $field);' . XMLDB_LINEFEED;
/// Add standard PHP footer
$result .= XMLDB_PHP_FOOTER;
return $result;
}
/**
* This function will generate all the PHP code needed to
* change the default of one field using XMLDB objects and functions
@@ -776,6 +829,9 @@ class view_table_php extends XMLDBAction {
return false;
}
/// Prepend warning. This function isn't usable!
$result .= 'DON\'T USE THIS FUNCTION (IT\'S ONLY EXPERIMENTAL). SOME DBs DON\'T SUPPORT IT!' . XMLDB_LINEFEED . XMLDB_LINEFEED;
/// Add the standard PHP header
$result .= XMLDB_PHP_HEADER;
@@ -908,6 +964,9 @@ class view_table_php extends XMLDBAction {
return false;
}
/// Prepend warning. This function isn't usable!
$result .= 'DON\'T USE THIS FUNCTION (IT\'S ONLY EXPERIMENTAL). SOME DBs DON\'T SUPPORT IT!' . XMLDB_LINEFEED . XMLDB_LINEFEED;
/// Add the standard PHP header
$result .= XMLDB_PHP_HEADER;