XMLDB to create additional fields in other tables

XMLDB to create additional fields in other tables

par Utilisateur supprimé,
Nombre de réponses : 6
hey All,

I have a simple need..
I need to create a handfull of additional fields in moodle core tables Having created and used XMLDB with success for a setof my own tables, it seems like that Moodle's XMLDB fails to create additional fields on some other tables.

is this something that should work, or should I just create a README.TXT with some SQL statements a user needs to execute to make this work?

Moyenne des évaluations  -
En réponse à Utilisateur supprimé

Re: XMLDB to create additional fields in other tables

par Tim Hunt,
Avatar Core developers Avatar Documentation writers Avatar Particularly helpful Moodlers Avatar Peer reviewers Avatar Plugin developers
Adding a handful of fields to Moodle core tables is simple in the same way that lighting the fuse on a sticky of dynamite is simple - you don't want to hang around to look after it.

Why can't you use one of Moodle's numerous plugin types?
En réponse à Tim Hunt

Re: XMLDB to create additional fields in other tables

par Utilisateur supprimé,
Tim,

if you know how to handle dynamite, it's not such a big deal. And the various Moodle plugins don't do what I want to do...

For me, it sounds quite a common operation to add additional fields into a moodle core table, I have done that lot's of times with other projects.

In my case I am adding additional property to a section (course_sections) for a special course format, adding a start date and end date for specific sections. In this case we don't do 'things' on a weekly or monthly base, but rather starts specific tasks on any date, and can end at any other other date. Sometimes it can take 3 weeks, other times 30 days...

Setting up a separate 1:1 table and go through the whole operation of handling my own retrieval/save and delete functions doesn't make sense.

If XMLDB cannot add additional fields to a existing table, then this is fine with me and I will supply a readme or install.txt file for appropriate instructions.


En réponse à Utilisateur supprimé

Re: XMLDB to create additional fields in other tables

par Tim Hunt,
Avatar Core developers Avatar Documentation writers Avatar Particularly helpful Moodlers Avatar Peer reviewers Avatar Plugin developers
OK, as long as you know the risks.

What you have to remember is that the install.xml file only affects what happens when Moodle (or a new plugin) is first installed. After that, changes to the DB structure are done my the upgrade.php file.

Don't even think about adding stuff to the main lib/db/upgrade.php. Instead use local/db/upgrade.php, and local/version.php to make the changes.

Don't make changes to lib/db/install.xml either. local/db/upgrade.php is run for a clean install, and there is no local/db/install.xml.

Note also that the way the local folder works is being changed in Moodle 2.0.
En réponse à Tim Hunt

Re: XMLDB to create additional fields in other tables

par Utilisateur supprimé,
Tim,

yes I understand the risk, and I am also making sure Moodle can insert records because the fields have proper database defaults.

I was hoping that XMLDB was 'smart' enough to read the database and the XMLDB schema, compare them and make proper updates, unfortunately this is not the case.

I will look into upgrade.php to add the additional fields.

thanks for your answer!
En réponse à Utilisateur supprimé

Re: XMLDB to create additional fields in other tables

par Tim Hunt,
Avatar Core developers Avatar Documentation writers Avatar Particularly helpful Moodlers Avatar Peer reviewers Avatar Plugin developers
No. Migration from one schema to another one is a hard problem, especially when existing data has to be updated. There is not way to automate it.

However, the XMLDB editor has the option to generate the PHP code that needs to go into update.php.
En réponse à Tim Hunt

Re: XMLDB to create additional fields in other tables

par Phan Huu Tri,

I want to add new column to course table and i use XMLDB editor to do that but Moodle 2.0, I can not use Edit function to add new column, I also config folder lib/db with permisson 777. If anybody has the same problem as me, Please share it to me. Thanks