From eb437bd3517e996fb62cd000bd5bd73c28569068 Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 4 Oct 2006 09:44:38 +0000 Subject: [PATCH] Some changes to ddllib.php to make some functions a bit easier to call. May not be final ... see MDL-6817 for details. --- lib/ddllib.php | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/lib/ddllib.php b/lib/ddllib.php index b541993b59..a70d9dc653 100644 --- a/lib/ddllib.php +++ b/lib/ddllib.php @@ -251,6 +251,11 @@ function table_exists($table) { $exists = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + /// Do this function silenty (to avoid output in install/upgrade process) $olddbdebug = $db->debug; $db->debug = false; @@ -290,6 +295,16 @@ function field_exists($table, $field) { $exists = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + +/// Retrieve the field object in case just a name was supplied + if (is_string($field)) { + $field = new XMLDBField($field); + } + /// Do this function silenty (to avoid output in install/upgrade process) $olddbdebug = $db->debug; $db->debug = false; @@ -337,6 +352,16 @@ function index_exists($table, $index) { $exists = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + +/// Retrieve the index object in case just a name was supplied + if (is_string($index)) { + $index = new XMLDBIndex($index); + } + /// Do this function silenty (to avoid output in install/upgrade process) $olddbdebug = $db->debug; $db->debug = false; @@ -555,6 +580,11 @@ function drop_table($table, $continue=true, $feedback=true) { $status = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } @@ -589,6 +619,11 @@ function rename_table($table, $newname, $continue=true, $feedback=true) { $status = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } @@ -628,6 +663,11 @@ function add_field($table, $field, $continue=true, $feedback=true) { $status = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } @@ -664,6 +704,11 @@ function drop_field($table, $field, $continue=true, $feedback=true) { $status = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } @@ -700,6 +745,12 @@ function change_field_type($table, $field, $continue=true, $feedback=true) { $status = true; +/// Retrieve the table object in case just a name was supplied + + if (is_string($table)) { + $table = new XMLDBTable($table); + } + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } @@ -778,6 +829,11 @@ function change_field_enum($table, $field, $continue=true, $feedback=true) { $status = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } @@ -808,6 +864,11 @@ function change_field_default($table, $field, $continue=true, $feedback=true) { $status = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } @@ -838,6 +899,17 @@ function rename_field($table, $field, $newname, $continue=true, $feedback=true) global $CFG, $db; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + +/// Retrieve the field object in case just a name was supplied + if (is_string($field)) { + $field = new XMLDBField($field); + } + + $status = true; if (strtolower(get_class($table)) != 'xmldbtable') { @@ -888,6 +960,11 @@ function add_key($table, $key, $continue=true, $feedback=true) { $status = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } @@ -922,6 +999,11 @@ function drop_key($table, $key, $continue=true, $feedback=true) { $status = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } @@ -960,6 +1042,11 @@ function rename_key($table, $key, $newname, $continue=true, $feedback=true) { $status = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } @@ -998,6 +1085,11 @@ function add_index($table, $index, $continue=true, $feedback=true) { $status = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } @@ -1035,6 +1127,17 @@ function drop_index($table, $index, $continue=true, $feedback=true) { $status = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } + +/// Retrieve the index object in case just a name was supplied + if (is_string($index)) { + $index = new XMLDBIndex($index); + } + + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } @@ -1076,6 +1179,16 @@ function rename_index($table, $index, $newname, $continue=true, $feedback=true) $status = true; +/// Retrieve the table object in case just a name was supplied + if (is_string($table)) { + $table = new XMLDBTable($table); + } +/// Retrieve the index object in case just a name was supplied + if (is_string($index)) { + $index = new XMLDBIndex($index); + } + + if (strtolower(get_class($table)) != 'xmldbtable') { return false; } -- 2.39.5