where is the function to build a database table from an XMLDB file?

where is the function to build a database table from an XMLDB file?

by Matt Gibson -
Number of replies: 2
I've been looking , but can't find it. Is there one, or do I need to write an upgrade script that makes that table and fields one at a time along these lines:

if ($result && $oldversion < 2007122300) {

  $table = new XMLDBTable('data_table');
  $field = new XMLDBField('field1');
  $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'content');
 
   
  $result = $result && add_field($table, $field);
 
  }


Average of ratings: -
In reply to Matt Gibson

Re: where is the function to build a database table from an XMLDB file?

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
That's probably the best way in general (the XMLDB editor in Moodle can generate these statements for you). [Note the syntax has changed a little in Moodle 2.0 as part of the whole recent DML and DDL refactoring]

If you really just want to load an install.xml file in one shot without any checking for previous tables etc you can do it like this:


install_from_xmldb_file('/your/full/file/path/install.xml');

Average of ratings: Useful (1)
In reply to Martin Dougiamas

Re: where is the function to build a database table from an XMLDB file?

by Matt Gibson -
Perfect. Cheers Martin!