mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 12:45:04 +01:00
3rd iteration committed: xmldb_table "public" methods changed + debugging of deprecated ones until Moodle 2.1 . MDL-14863
This commit is contained in:
parent
6d75dcf537
commit
5eaa41e8bc
@ -88,31 +88,31 @@ class test extends XMLDBAction {
|
||||
|
||||
/// 1st test. Complete table creation.
|
||||
$table = new xmldb_table('testtable');
|
||||
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
|
||||
$table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general');
|
||||
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null);
|
||||
$table->addFieldInfo('intro', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
|
||||
$table->addFieldInfo('logo', XMLDB_TYPE_BINARY, 'big', null, XMLDB_NOTNULL, null, null, null);
|
||||
$table->addFieldInfo('assessed', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('assesstimestart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('assesstimefinish', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('scale', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('maxbytes', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('forcesubscribe', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('trackingtype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1');
|
||||
$table->addFieldInfo('rsstype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('rssarticles', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('grade', XMLDB_TYPE_NUMBER, '20,0', XMLDB_UNSIGNED, null, null, null, null, null);
|
||||
$table->addFieldInfo('percent', XMLDB_TYPE_NUMBER, '5,2', null, null, null, null, null, null);
|
||||
$table->addFieldInfo('warnafter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('blockafter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('blockperiod', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->addKeyInfo('type-name', XMLDB_KEY_UNIQUE, array('type', 'name'));
|
||||
$table->addIndexInfo('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
|
||||
$table->addIndexInfo('rsstype', XMLDB_INDEX_UNIQUE, array('rsstype'));
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
|
||||
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general');
|
||||
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null);
|
||||
$table->add_field('intro', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
|
||||
$table->add_field('logo', XMLDB_TYPE_BINARY, 'big', null, XMLDB_NOTNULL, null, null, null);
|
||||
$table->add_field('assessed', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('assesstimestart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('assesstimefinish', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('scale', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('maxbytes', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('forcesubscribe', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('trackingtype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1');
|
||||
$table->add_field('rsstype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('rssarticles', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('grade', XMLDB_TYPE_NUMBER, '20,0', XMLDB_UNSIGNED, null, null, null, null, null);
|
||||
$table->add_field('percent', XMLDB_TYPE_NUMBER, '5,2', null, null, null, null, null, null);
|
||||
$table->add_field('warnafter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('blockafter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('blockperiod', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('type-name', XMLDB_KEY_UNIQUE, array('type', 'name'));
|
||||
$table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
|
||||
$table->add_index('rsstype', XMLDB_INDEX_UNIQUE, array('rsstype'));
|
||||
|
||||
$table->setComment("This is a test'n drop table. You can drop it safely");
|
||||
|
||||
@ -140,14 +140,14 @@ class test extends XMLDBAction {
|
||||
/// 3rd test. creating another, smaller table
|
||||
if ($test->status) {
|
||||
$table = new xmldb_table ('anothertest');
|
||||
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
|
||||
$table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle');
|
||||
$table->addFieldInfo('secondname', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
|
||||
$table->addFieldInfo('intro', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
|
||||
$table->addFieldInfo('avatar', XMLDB_TYPE_BINARY, 'medium', null, null, null, null, null, null);
|
||||
$table->addFieldInfo('grade', XMLDB_TYPE_NUMBER, '20,10', null, null, null, null, null);
|
||||
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
|
||||
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
|
||||
$table->add_field('name', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle');
|
||||
$table->add_field('secondname', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
|
||||
$table->add_field('intro', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
|
||||
$table->add_field('avatar', XMLDB_TYPE_BINARY, 'medium', null, null, null, null, null, null);
|
||||
$table->add_field('grade', XMLDB_TYPE_NUMBER, '20,10', null, null, null, null, null);
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
/// Get SQL code and execute it
|
||||
$test = new stdClass;
|
||||
$test->sql = $gen->getCreateTableSQL($table);
|
||||
|
@ -176,7 +176,7 @@ class view_structure_php extends XMLDBAction {
|
||||
/// Iterate over each field
|
||||
foreach ($table->getFields() as $field) {
|
||||
/// The field header, with name
|
||||
$result .= ' $table->addFieldInfo(' . "'" . $field->getName() . "', ";
|
||||
$result .= ' $table->add_field(' . "'" . $field->getName() . "', ";
|
||||
/// The field PHP specs
|
||||
$result .= $field->getPHP(false);
|
||||
/// The end of the line
|
||||
@ -188,7 +188,7 @@ class view_structure_php extends XMLDBAction {
|
||||
$result .= ' /// Adding keys to table ' . $table->getName() . XMLDB_LINEFEED;
|
||||
foreach ($keys as $key) {
|
||||
/// The key header, with name
|
||||
$result .= ' $table->addKeyInfo(' . "'" . $key->getName() . "', ";
|
||||
$result .= ' $table->add_key(' . "'" . $key->getName() . "', ";
|
||||
/// The key PHP specs
|
||||
$result .= $key->getPHP();
|
||||
/// The end of the line
|
||||
@ -201,7 +201,7 @@ class view_structure_php extends XMLDBAction {
|
||||
$result .= ' /// Adding indexes to table ' . $table->getName() . XMLDB_LINEFEED;
|
||||
foreach ($indexes as $index) {
|
||||
/// The index header, with name
|
||||
$result .= ' $table->addIndexInfo(' . "'" . $index->getName() . "', ";
|
||||
$result .= ' $table->add_index(' . "'" . $index->getName() . "', ";
|
||||
/// The index PHP specs
|
||||
$result .= $index->getPHP();
|
||||
/// The end of the line
|
||||
|
@ -706,6 +706,17 @@ class xmldb_table extends xmldb_object {
|
||||
return $o;
|
||||
}
|
||||
|
||||
/// TODO: Delete for 2.1 (deprecated in 2.0).
|
||||
/// Deprecated API starts here
|
||||
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);
|
||||
|
||||
return $this->add_field($name, $type, $precision, $unsigned, $notnull, $sequence, $enum, $enumvalues, $default, $previous);
|
||||
|
||||
}
|
||||
/// Deprecated API ends here
|
||||
|
||||
/**
|
||||
* This function will add one new field to the table with all
|
||||
* its attributes defined
|
||||
@ -721,7 +732,7 @@ class xmldb_table extends xmldb_object {
|
||||
* @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 addFieldInfo($name, $type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $enum=null, $enumvalues=null, $default=null, $previous=null) {
|
||||
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);
|
||||
$field->setAttributes($type, $precision, $unsigned, $notnull, $sequence, $enum, $enumvalues, $default);
|
||||
$this->addField($field, $previous);
|
||||
@ -729,6 +740,18 @@ class xmldb_table extends xmldb_object {
|
||||
return $field;
|
||||
}
|
||||
|
||||
/// TODO: Delete for 2.1 (deprecated in 2.0).
|
||||
/// Deprecated API starts here
|
||||
|
||||
function addKeyInfo($name, $type, $fields, $reftable=null, $reffields=null) {
|
||||
|
||||
debugging('XMLDBTable->addKeyInfo() has been deprecated in Moodle 2.0. Will be out in Moodle 2.1. Please use xmldb_table->add_key() instead', DEBUG_DEVELOPER);
|
||||
|
||||
return $this->add_key($name, $type, $fields, $reftable, $reffields);
|
||||
|
||||
}
|
||||
/// Deprecated API ends here
|
||||
|
||||
/**
|
||||
* This function will add one new key to the table with all
|
||||
* its attributes defined
|
||||
@ -739,12 +762,23 @@ class xmldb_table extends xmldb_object {
|
||||
* @param string reftable name of the table the FK points to or null
|
||||
* @param array reffields an array of fieldnames in the FK table or null
|
||||
*/
|
||||
function addKeyInfo($name, $type, $fields, $reftable=null, $reffields=null) {
|
||||
function add_key($name, $type, $fields, $reftable=null, $reffields=null) {
|
||||
$key = new xmldb_key($name);
|
||||
$key->setAttributes($type, $fields, $reftable, $reffields);
|
||||
$this->addKey($key);
|
||||
}
|
||||
|
||||
/// TODO: Delete for 2.1 (deprecated in 2.0).
|
||||
/// Deprecated API starts here
|
||||
function addIndexInfo($name, $type, $fields) {
|
||||
|
||||
debugging('XMLDBTable->addIndexInfo() has been deprecated in Moodle 2.0. Will be out in Moodle 2.1. Please use xmldb_table->add_index() instead', DEBUG_DEVELOPER);
|
||||
|
||||
return $this->add_index($name, $type, $fields);
|
||||
|
||||
}
|
||||
/// Deprecated API ends here
|
||||
|
||||
/**
|
||||
* This function will add one new index to the table with all
|
||||
* its attributes defined
|
||||
@ -753,7 +787,7 @@ class xmldb_table extends xmldb_object {
|
||||
* @param string type XMLDB_INDEX_UNIQUE, XMLDB_INDEX_NOTUNIQUE
|
||||
* @param array fields an array of fieldnames to build the index over
|
||||
*/
|
||||
function addIndexInfo($name, $type, $fields) {
|
||||
function add_index($name, $type, $fields) {
|
||||
$index = new xmldb_index($name);
|
||||
$index->setAttributes($type, $fields);
|
||||
$this->addIndex($index);
|
||||
|
Loading…
x
Reference in New Issue
Block a user