how to generate new tables

how to generate new tables

by Ye Chen -
Number of replies: 3
Hello,
I am writing a moodle plugin on my own moodle server. When install the plugin, it just needs to put the whole folder under moodle directory.
The problem I have is how to auto generate new database tables in moodle when the user first time install. When I developed the plugin, I create tables through phpPgAdmin using sql statement. Although I can create an sql files for user to copy and paste to phpPgAdmin to generate the tables, it is not convinient for some of the users.

I know I can generate install.xml using moodle xmlEditor through administrator page. My problem is how I can do it. When I click xmlEditor, it lists all install.xml in different directories, most of them are unaccessed, some of them I can click load then edit. But how I can generate new install.xml under my plugin directory? What I need to do that I can access install.xml from XMLEditor?

Another question, once createing install.xml, when user installs the plugin, after they put the plugin folder under moodle directory, what they need to do for moodle to run install.xml to create those tables?

I appreciate any response
Thanks
Ye
Average of ratings: -
In reply to Ye Chen

Re: how to generate new tables

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Have you seen Development:Installing_and_upgrading_plugin_database_tables

To let XMLDB create and edit an install.xml file, you need to make sure the mod/mymod/db folder exists and is writable by the web server.

Moodle will check for plugins that need to be installed or updated when you go to the admin notifications page: .../admin/index.php.
In reply to Tim Hunt

Re: how to generate new tables

by Ye Chen -
Tim,

I did see the document about installing_and_upgrading_plugin_database_tables, but I think it is for the activity module or block, the plugin is supposed to be installed under mod/mymod or blocks/myblock. But the plugin I wrote is not activity module or block, I need to install it under moodle root like grade or questions which has their own folders not under mod or block.
I understand if my plugin is moodle module or block, put them under mod or blocks, moodle will check for plugins that need to be installed or updated.
But for the case I need to install the plugin under moodle root, how moodle will check and install the new plugin and all the tables? I have impression that moodle won't automatically do it if my plugin folder is under moodle root. I need to do something but i don't know what it is. Can you give me some clue?

Thanks in advance
Ye
In reply to Ye Chen

Re: how to generate new tables

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Moodle only looks for database install stuff for (some of) the predefinded types of plugin - and the way it processes database install actions is the same for all types of plugin.

If what you are trying to do fits into one of these standard types, then you are strongly recommended to make a standard plugin type. It will save you pain in the long run.

However, if all else fails, you can use Development:Local_customisation.