Ravindu
Ravindu

Reputation: 2550

Add new tables to moodle database

I just want to know is it ok to add new tables to the moodle database or should I create a new database for that? I need a table to save a unique id and a token in one table and client's ip address, client's MAC address and computer name in another table.(and what are the best data types to store those?) And I just want to know does moodle save these things in there tables? Then it will be easy for me. Thank You

Upvotes: 5

Views: 3521

Answers (3)

ahwelp
ahwelp

Reputation: 87

Yes, you can add a table to moodle's database, but i and the moodle developers recomend you to follow some very rigid rules.

Don't edit existent moodle code. Moodle is based on a core, that should not be edited, because your code can conflict with new versions of the system. So if you follow the rules, your code will work on the further moodle versions.

To develop your stuff in moodle is recomended creating a plugin with the extra things you want. I recomend you create it in /local/yourplugin .

Inside this you will need to create some files listed in the documentation. I will say about the file local/yourplugin/db/install.xml.

More data about moodle plugin https://docs.moodle.org/dev/Blocks https://docs.moodle.org/dev/Plugin_files

Inside this file you will define what a part of your database will be. So with this, you can say that will exist a new table with the fields.

About XMLDB (the way moodle define database structure) https://docs.moodle.org/dev/XMLDB_Documentation

With all the files in place, moodle will install your plugin and generate your tables.

If you don't want to follow the rules B-). You can locate a module and edit the db/upgrade.php, and define a new structure.

Upvotes: 0

Phil Lello
Phil Lello

Reputation: 8639

Standard practise for plugin tables is to use a table name based on the plugin path. So if the plugin is in local/clientlogger, a safe name would be {local_clientlogger}. Tables should be created by /db/install.xml and /db/upgrade.php

Upvotes: 0

gnuwings
gnuwings

Reputation: 950

The question is not clear and you haven't mentioned how you are going to fill those extra tables.. I'm not sure how to get the MAC address from an HTTP request/response.

Moodle has an in-built logging mechanism which keeps track of the IP Addresses of visited users. It also has a unique id(primary key) and the user id.

If you want to add new tables, you can add it via the plugins(block, module or local plugin). Moodle also has a robust Event API allows you to trigger some actions without actually modifying the core code.

Hope this helps.

Upvotes: 2

Related Questions