From: stronk7 Date: Thu, 1 Nov 2007 23:24:36 +0000 (+0000) Subject: Now PHP code generated by the XMLDB editor automatically X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=dcbef1994eadf3fb5b6a718e1f31197f3700ac09;p=moodle.git Now PHP code generated by the XMLDB editor automatically adds calls to upgrade_main_savepoint(). MDL-11698 Merged from MOODLE_19_STABLE --- diff --git a/admin/xmldb/actions/view_structure_php/view_structure_php.class.php b/admin/xmldb/actions/view_structure_php/view_structure_php.class.php index 14490b7fbd..13d757b9be 100644 --- a/admin/xmldb/actions/view_structure_php/view_structure_php.class.php +++ b/admin/xmldb/actions/view_structure_php/view_structure_php.class.php @@ -7,7 +7,7 @@ // Moodle - Modular Object-Oriented Dynamic Learning Environment // // http://moodle.com // // // -// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com // +// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com // // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com // // // // This program is free software; you can redistribute it and/or modify // @@ -214,6 +214,9 @@ class view_structure_php extends XMLDBAction { $result .= ' /// Launch create table for ' . $table->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && create_table($table);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -252,6 +255,9 @@ class view_structure_php extends XMLDBAction { $result .= ' /// Launch drop table for ' . $table->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && drop_table($table);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -290,10 +296,37 @@ class view_structure_php extends XMLDBAction { $result .= ' /// Launch rename table for ' . $table->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && rename_table($table, ' . "'NEWNAMEGOESHERE'" . ');' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; } + + /** + * This function will generate the PHP code needed to + * implement the upgrade_xxxx_savepoint() php calls in + * upgrade code generated from the editor + * + * @param XMLDBStructure structure object containing all the info + * @return string PHP code to be used to stabilish a savepoint + */ + function upgrade_savepoint_php ($structure) { + + $path = $structure->getPath(); + + $result = ''; + + switch ($path) { + case 'lib/db': + $result = XMLDB_LINEFEED . + ' /// Main savepoint reached' . XMLDB_LINEFEED . + ' upgrade_main_savepoint($result, XXXXXXXXXX);' . XMLDB_LINEFEED; + break; + } + return $result; + } } ?> diff --git a/admin/xmldb/actions/view_table_php/view_table_php.class.php b/admin/xmldb/actions/view_table_php/view_table_php.class.php index 41d29c43f9..7d1b46bbd0 100644 --- a/admin/xmldb/actions/view_table_php/view_table_php.class.php +++ b/admin/xmldb/actions/view_table_php/view_table_php.class.php @@ -7,7 +7,7 @@ // Moodle - Modular Object-Oriented Dynamic Learning Environment // // http://moodle.com // // // -// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com // +// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com // // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com // // // // This program is free software; you can redistribute it and/or modify // @@ -339,6 +339,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch add field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && add_field($table, $field);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -382,6 +385,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch drop field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && drop_field($table, $field);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -426,6 +432,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch rename field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && rename_field($table, $field, ' . "'" . 'NEWNAMEGOESHERE' . "'" . ');' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -479,6 +488,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch change of type for field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && change_field_type($table, $field);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -529,6 +541,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch change of precision for field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && change_field_precision($table, $field);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -575,6 +590,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch change of sign for field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && change_field_unsigned($table, $field);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -621,6 +639,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch change of nullability for field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && change_field_notnull($table, $field);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -668,6 +689,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch change of list of values for field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && change_field_enum($table, $field);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -714,6 +738,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch change of default for field ' . $field->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && change_field_default($table, $field);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -758,6 +785,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch add key ' . $key->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && add_key($table, $key);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -802,6 +832,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch drop key ' . $key->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && drop_key($table, $key);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -849,6 +882,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch rename key ' . $key->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && rename_key($table, $key, ' . "'" . 'NEWNAMEGOESHERE' . "'" . ');' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -893,6 +929,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch add index ' . $index->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && add_index($table, $index);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -937,6 +976,9 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch drop index ' . $index->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && drop_index($table, $index);' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; @@ -984,11 +1026,38 @@ class view_table_php extends XMLDBAction { $result .= ' /// Launch rename index ' . $index->getName() . XMLDB_LINEFEED; $result .= ' $result = $result && rename_index($table, $index, ' . "'" . 'NEWNAMEGOESHERE' . "'" . ');' . XMLDB_LINEFEED; + /// Add the proper upgrade_xxxx_savepoint call + $result .= $this->upgrade_savepoint_php ($structure); + /// Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; } + /** + * This function will generate the PHP code needed to + * implement the upgrade_xxxx_savepoint() php calls in + * upgrade code generated from the editor + * + * @param XMLDBStructure structure object containing all the info + * @return string PHP code to be used to stabilish a savepoint + */ + function upgrade_savepoint_php ($structure) { + + $path = $structure->getPath(); + + $result = ''; + + switch ($path) { + case 'lib/db': + $result = XMLDB_LINEFEED . + ' /// Main savepoint reached' . XMLDB_LINEFEED . + ' upgrade_main_savepoint($result, XXXXXXXXXX);' . XMLDB_LINEFEED; + break; + } + return $result; + } + } ?>