diff options
author | Jan Klemkow <j.klemkow@wemelug.de> | 2012-10-09 14:01:58 +0200 |
---|---|---|
committer | Jan Klemkow <j.klemkow@wemelug.de> | 2012-10-09 14:01:58 +0200 |
commit | 459313e56b0653e4709694a7e86afc11be514097 (patch) | |
tree | a81656d8694e7a10dae8415f0d6ce7c29aeae294 /sqlbox/db | |
parent | b5b11fc16c37bfa9445bf66e68b324636cc6c8f8 (diff) | |
download | sqltutor-plugin-459313e56b0653e4709694a7e86afc11be514097.tar.gz sqltutor-plugin-459313e56b0653e4709694a7e86afc11be514097.tar.bz2 sqltutor-plugin-459313e56b0653e4709694a7e86afc11be514097.zip |
add dummy module
Diffstat (limited to 'sqlbox/db')
-rw-r--r-- | sqlbox/db/access.php | 76 | ||||
-rw-r--r-- | sqlbox/db/install.php | 42 | ||||
-rw-r--r-- | sqlbox/db/install.xml | 25 | ||||
-rw-r--r-- | sqlbox/db/log.php | 40 | ||||
-rw-r--r-- | sqlbox/db/uninstall.php | 32 | ||||
-rw-r--r-- | sqlbox/db/upgrade.php | 165 |
6 files changed, 380 insertions, 0 deletions
diff --git a/sqlbox/db/access.php b/sqlbox/db/access.php new file mode 100644 index 0000000..71647d3 --- /dev/null +++ b/sqlbox/db/access.php @@ -0,0 +1,76 @@ +<?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/>. + +/** + * Capability definitions for the newmodule module + * + * The capabilities are loaded into the database table when the module is + * installed or updated. Whenever the capability definitions are updated, + * the module version number should be bumped up. + * + * The system has four possible values for a capability: + * CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT, and inherit (not set). + * + * It is important that capability names are unique. The naming convention + * for capabilities that are specific to modules and blocks is as follows: + * [mod/block]/<plugin_name>:<capabilityname> + * + * component_name should be the same as the directory name of the mod or block. + * + * Core moodle capabilities are defined thus: + * moodle/<capabilityclass>:<capabilityname> + * + * Examples: mod/forum:viewpost + * block/recent_activity:view + * moodle/site:deleteuser + * + * The variable name for the capability definitions array is $capabilities + * + * @package mod + * @subpackage newmodule + * @copyright 2011 Your Name + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$capabilities = array( + +/***************************** remove these comment marks and modify the code as needed + 'mod/newmodule:view' => array( + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'guest' => CAP_ALLOW, + 'student' => CAP_ALLOW, + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ), + + 'mod/newmodule:submit' => array( + 'riskbitmask' => RISK_SPAM, + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'student' => CAP_ALLOW + ) + ), +******************************/ +); + diff --git a/sqlbox/db/install.php b/sqlbox/db/install.php new file mode 100644 index 0000000..d81ba97 --- /dev/null +++ b/sqlbox/db/install.php @@ -0,0 +1,42 @@ +<?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/>. + +/** + * This file replaces the legacy STATEMENTS section in db/install.xml, + * lib.php/modulename_install() post installation hook and partially defaults.php + * + * @package mod + * @subpackage newmodule + * @copyright 2011 Your Name <your@email.adress> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Post installation procedure + * + * @see upgrade_plugins_modules() + */ +function xmldb_newmodule_install() { +} + +/** + * Post installation recovery procedure + * + * @see upgrade_plugins_modules() + */ +function xmldb_newmodule_install_recovery() { +} diff --git a/sqlbox/db/install.xml b/sqlbox/db/install.xml new file mode 100644 index 0000000..d5d861b --- /dev/null +++ b/sqlbox/db/install.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<XMLDB PATH="mod/newmodule/db" VERSION="20101203" COMMENT="XMLDB file for Moodle mod/newmodule" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd" +> + <TABLES> + <TABLE NAME="newmodule" COMMENT="Default comment for newmodule, please edit me"> + <FIELDS> + <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="course"/> + <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Course newmodule activity belongs to" PREVIOUS="id" NEXT="name"/> + <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="name field for moodle instances" PREVIOUS="course" NEXT="intro"/> + <FIELD NAME="intro" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="General introduction of the newmodule activity" PREVIOUS="name" NEXT="introformat"/> + <FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Format of the intro field (MOODLE, HTML, MARKDOWN...)" PREVIOUS="intro" NEXT="timecreated"/> + <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="introformat" NEXT="timemodified"/> + <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated"/> + </FIELDS> + <KEYS> + <KEY NAME="primary" TYPE="primary" FIELDS="id"/> + </KEYS> + <INDEXES> + <INDEX NAME="course" UNIQUE="false" FIELDS="course"/> + </INDEXES> + </TABLE> + </TABLES> +</XMLDB> diff --git a/sqlbox/db/log.php b/sqlbox/db/log.php new file mode 100644 index 0000000..73561d7 --- /dev/null +++ b/sqlbox/db/log.php @@ -0,0 +1,40 @@ +<?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/>. + +/** + * Definition of log events + * + * NOTE: this is an example how to insert log event during installation/update. + * It is not really essential to know about it, but these logs were created as example + * in the previous 1.9 NEWMODULE. + * + * @package mod + * @subpackage newmodule + * @copyright 2011 Your Name <your@email.adress> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +global $DB; + +$logs = array( + array('module'=>'newmodule', 'action'=>'add', 'mtable'=>'newmodule', 'field'=>'name'), + array('module'=>'newmodule', 'action'=>'update', 'mtable'=>'newmodule', 'field'=>'name'), + array('module'=>'newmodule', 'action'=>'view', 'mtable'=>'newmodule', 'field'=>'name'), + array('module'=>'newmodule', 'action'=>'view all', 'mtable'=>'newmodule', 'field'=>'name') +); diff --git a/sqlbox/db/uninstall.php b/sqlbox/db/uninstall.php new file mode 100644 index 0000000..22ad141 --- /dev/null +++ b/sqlbox/db/uninstall.php @@ -0,0 +1,32 @@ +<?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/>. + +/** + * @see uninstall_plugin() + * + * @package mod + * @subpackage newmodule + * @copyright 2011 Your Name <your@email.adress> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Custom uninstallation procedure + */ +function xmldb_newmodule_uninstall() { + return true; +} diff --git a/sqlbox/db/upgrade.php b/sqlbox/db/upgrade.php new file mode 100644 index 0000000..7f74831 --- /dev/null +++ b/sqlbox/db/upgrade.php @@ -0,0 +1,165 @@ +<?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/>. + +/** + * This file keeps track of upgrades to the newmodule module + * + * Sometimes, changes between versions involve alterations to database + * structures and other major things that may break installations. The upgrade + * function in this file will attempt to perform all the necessary actions to + * upgrade your older installation to the current version. If there's something + * it cannot do itself, it will tell you what you need to do. The commands in + * here will all be database-neutral, using the functions defined in DLL libraries. + * + * @package mod + * @subpackage newmodule + * @copyright 2011 Your Name + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Execute newmodule upgrade from the given old version + * + * @param int $oldversion + * @return bool + */ +function xmldb_newmodule_upgrade($oldversion) { + global $DB; + + $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes + + // And upgrade begins here. For each one, you'll need one + // block of code similar to the next one. Please, delete + // this comment lines once this file start handling proper + // upgrade code. + + // if ($oldversion < YYYYMMDD00) { //New version in version.php + // + // } + + // Lines below (this included) MUST BE DELETED once you get the first version + // of your module ready to be installed. They are here only + // for demonstrative purposes and to show how the newmodule + // iself has been upgraded. + + // For each upgrade block, the file newmodule/version.php + // needs to be updated . Such change allows Moodle to know + // that this file has to be processed. + + // To know more about how to write correct DB upgrade scripts it's + // highly recommended to read information available at: + // http://docs.moodle.org/en/Development:XMLDB_Documentation + // and to play with the XMLDB Editor (in the admin menu) and its + // PHP generation posibilities. + + // First example, some fields were added to install.xml on 2007/04/01 + if ($oldversion < 2007040100) { + + // Define field course to be added to newmodule + $table = new xmldb_table('newmodule'); + $field = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); + + // Add field course + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Define field intro to be added to newmodule + $table = new xmldb_table('newmodule'); + $field = new xmldb_field('intro', XMLDB_TYPE_TEXT, 'medium', null, null, null, null,'name'); + + // Add field intro + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Define field introformat to be added to newmodule + $table = new xmldb_table('newmodule'); + $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', + 'intro'); + + // Add field introformat + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Once we reach this point, we can store the new version and consider the module + // upgraded to the version 2007040100 so the next time this block is skipped + upgrade_mod_savepoint(true, 2007040100, 'newmodule'); + } + + // Second example, some hours later, the same day 2007/04/01 + // two more fields and one index were added to install.xml (note the micro increment + // "01" in the last two digits of the version + if ($oldversion < 2007040101) { + + // Define field timecreated to be added to newmodule + $table = new xmldb_table('newmodule'); + $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', + 'introformat'); + + // Add field timecreated + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Define field timemodified to be added to newmodule + $table = new xmldb_table('newmodule'); + $field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', + 'timecreated'); + + // Add field timemodified + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Define index course (not unique) to be added to newmodule + $table = new xmldb_table('newmodule'); + $index = new xmldb_index('courseindex', XMLDB_INDEX_NOTUNIQUE, array('course')); + + // Add index to course field + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + // Another save point reached + upgrade_mod_savepoint(true, 2007040101, 'newmodule'); + } + + // Third example, the next day, 2007/04/02 (with the trailing 00), some actions were performed to install.php, + // related with the module + if ($oldversion < 2007040200) { + + // insert here code to perform some actions (same as in install.php) + + upgrade_mod_savepoint(true, 2007040200, 'newmodule'); + } + + // And that's all. Please, examine and understand the 3 example blocks above. Also + // it's interesting to look how other modules are using this script. Remember that + // the basic idea is to have "blocks" of code (each one being executed only once, + // when the module version (version.php) is updated. + + // Lines above (this included) MUST BE DELETED once you get the first version of + // yout module working. Each time you need to modify something in the module (DB + // related, you'll raise the version and add one upgrade block here. + + // Final return of upgrade result (true, all went good) to Moodle. + return true; +} |