From 11e167a9d06317f7e6f4e3762017ccf3fed3f932 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sat, 30 May 2009 18:57:00 +0000 Subject: [PATCH] MDL-16059 xmldb editor - now all the php auto-generated code include proper upgrade_xxx_savepoint() calls --- admin/xmldb/actions/XMLDBAction.class.php | 117 +++++++++++++----- .../view_structure_php.class.php | 91 +++++--------- .../view_table_php/view_table_php.class.php | 92 +++++--------- 3 files changed, 150 insertions(+), 150 deletions(-) diff --git a/admin/xmldb/actions/XMLDBAction.class.php b/admin/xmldb/actions/XMLDBAction.class.php index 201e67621f..149858c08b 100644 --- a/admin/xmldb/actions/XMLDBAction.class.php +++ b/admin/xmldb/actions/XMLDBAction.class.php @@ -1,32 +1,36 @@ -. + +/** + * @package xmldb-editor + * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Main xmldb action clasee + * + * Main xmldb action class. It implements all the basic + * functionalities to be shared by each action. + * + * @package xmldb-editor + * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class XMLDBAction { var $does_generate; //Type of value returned by the invoke method @@ -187,5 +191,60 @@ class XMLDBAction { } 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. It's used by + * the view_structure_php and view_table_php actions + * + * @param xmldb_structure 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(); + + /// Trim "db" from path + $path = dirname($path); + + /// Get all the available plugin types + $plugintypes = get_plugin_types(); + + /// Get pluginname, plugindir and plugintype + $pluginname = basename($path); + if ($path == 'lib') { /// exception for lib (not proper plugin) + $plugindir = 'lib'; + $plugintype = 'lib'; + } else { /// rest of plugins + $plugindir = dirname($path); + $plugintype = array_search($plugindir, $plugintypes); + } + + $result = ''; + + switch ($plugintype ) { + case 'lib': /// has own savepoint function + $result = XMLDB_LINEFEED . + ' /// Main savepoint reached' . XMLDB_LINEFEED . + ' upgrade_main_savepoint($result, XXXXXXXXXX);' . XMLDB_LINEFEED; + break; + case 'mod': /// has own savepoint function + $result = XMLDB_LINEFEED . + ' /// ' . $pluginname . ' savepoint reached' . XMLDB_LINEFEED . + ' upgrade_mod_savepoint($result, XXXXXXXXXX, ' . "'$pluginname'" . ');' . XMLDB_LINEFEED; + break; + case 'block': /// has own savepoint function + $result = XMLDB_LINEFEED . + ' /// ' . $pluginname . ' savepoint reached' . XMLDB_LINEFEED . + ' upgrade_block_savepoint($result, XXXXXXXXXX, ' . "'$pluginname'" . ');' . XMLDB_LINEFEED; + break; + default: /// rest of plugins + $result = XMLDB_LINEFEED . + ' /// ' . $pluginname . ' savepoint reached' . XMLDB_LINEFEED . + ' upgrade_plugin_savepoint($result, XXXXXXXXXX, ' . "'$plugintype'" . ', ' . "'$pluginname'" . ');' . XMLDB_LINEFEED; + } + return $result; + } } ?> 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 7abb8d607e..e04e9ab64e 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 @@ -1,32 +1,34 @@ -. + +/** + * @package xmldb-editor + * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * This class will show the PHP needed (upgrade block) to perform + * the desired DDL action with the specified table + * + * @package xmldb-editor + * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class view_structure_php extends XMLDBAction { /** @@ -309,36 +311,5 @@ class view_structure_php extends XMLDBAction { 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 xmldb_structure 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 = ''; - - /// Split path into components - $patharr = explode('/', $path); - - switch ($patharr[0]) { - case 'lib': - $result = XMLDB_LINEFEED . - ' /// Main savepoint reached' . XMLDB_LINEFEED . - ' upgrade_main_savepoint($result, XXXXXXXXXX);' . XMLDB_LINEFEED; - break; - case 'mod': - $result = XMLDB_LINEFEED . - ' /// ' . $patharr[1] . ' savepoint reached' . XMLDB_LINEFEED . - ' upgrade_mod_savepoint($result, XXXXXXXXXX, ' . "'$patharr[1]'" . ');' . 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 5f2cc294d4..e519228805 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 @@ -1,32 +1,34 @@ -. + +/** + * @package xmldb-editor + * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * This class will show the PHP needed (upgrade block) to perform + * the desired DDL action with the specified field/key/index + * + * @package xmldb-editor + * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class view_table_php extends XMLDBAction { /** @@ -1031,37 +1033,5 @@ class view_table_php extends XMLDBAction { 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 xmldb_structure 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 = ''; - - /// Split path into components - $patharr = explode('/', $path); - - switch ($patharr[0]) { - case 'lib': - $result = XMLDB_LINEFEED . - ' /// Main savepoint reached' . XMLDB_LINEFEED . - ' upgrade_main_savepoint($result, XXXXXXXXXX);' . XMLDB_LINEFEED; - break; - case 'mod': - $result = XMLDB_LINEFEED . - ' /// ' . $patharr[1] . ' savepoint reached' . XMLDB_LINEFEED . - ' upgrade_mod_savepoint($result, XXXXXXXXXX, ' . "'$patharr[1]'" . ');' . XMLDB_LINEFEED; - break; - } - return $result; - } - } ?> -- 2.39.5