]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16059 xmldb editor - now all the php auto-generated code include proper upgrade_x...
authorstronk7 <stronk7>
Sat, 30 May 2009 18:57:00 +0000 (18:57 +0000)
committerstronk7 <stronk7>
Sat, 30 May 2009 18:57:00 +0000 (18:57 +0000)
admin/xmldb/actions/XMLDBAction.class.php
admin/xmldb/actions/view_structure_php/view_structure_php.class.php
admin/xmldb/actions/view_table_php/view_table_php.class.php

index 201e67621f612f5e2c9d7361de1fdcd361271721..149858c08b40d3fb400a9a01610459c72f82e186 100644 (file)
@@ -1,32 +1,36 @@
-<?php // $Id$
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.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  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/// This is the main action class. It implements all the basic
-/// functionalities to be shared by each action.
-
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @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;
+    }
 }
 ?>
index 7abb8d607ed8c8c02d362f89242def4651cdfba7..e04e9ab64ed2d87d2070f2ee3e0a5842f9ea1a4c 100644 (file)
@@ -1,32 +1,34 @@
-<?php // $Id$
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.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  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/// This class will show the PHP needed to perform the desired action
-/// with the specified table.
-
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @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;
-    }
 }
 ?>
index 5f2cc294d42ed2f4f1ced1564469ddd39556c7f2..e519228805d2e3f28aba734e859eb4da6b881839 100644 (file)
@@ -1,32 +1,34 @@
-<?php // $Id$
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.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  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/// This class will show the PHP needed to perform the desired action
-/// with the specified fields/keys/indexes.
-
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @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;
-    }
-
 }
 ?>