3 require_once 'MTrack/DBSchema/SQLite.php';
4 require_once 'MTrack/DBSchema/pgsql.php';
5 require_once 'MTrack/DBSchema/mysql.php';
7 require_once 'MTrack/DBSchema/Table.php';
14 function __construct($filename) {
15 $s = simplexml_load_file($filename);
17 $this->version = (int)$s['version'];
19 /* fabricate a table to hold the schema info */
20 $table = new MTrackDBSchema_Table;
21 $table->name = 'mtrack_schema';
26 $table->fields[$f->name] = $f;
27 $this->tables[$table->name] = $table;
29 foreach ($s->table as $t) {
30 $table = new MTrackDBSchema_Table;
31 $table->name = (string)$t['name'];
33 foreach ($t->field as $f) {
35 foreach ($f->attributes() as $k => $v) {
36 $F->{(string)$k} = (string)$v;
38 if (isset($f->comment)) {
39 $F->comment = (string)$f->comment;
41 $table->fields[$F->name] = $F;
43 foreach ($t->key as $k) {
46 if (isset($k['type'])) {
47 $K->type = (string)$k['type'];
51 foreach ($k->field as $f) {
52 $K->fields[] = (string)$f;
54 if (isset($k['name'])) {
55 $K->name = (string)$k['name'];
57 $K->name = sprintf("idx_%s_%s", $table->name, join('_', $K->fields));
59 $table->keys[$K->name] = $K;
62 $this->tables[$table->name] = $table;
64 foreach ($s->post as $p) {
65 $this->post[(string)$p['driver']] = (string)$p;
68 /* apply custom ticket fields */
69 if (isset($this->tables['tickets'])) {
70 $table = $this->tables['tickets'];
71 $custom = MTrackTicket_CustomFields::getInstance();
72 foreach ($custom->fields as $field) {
74 $f->name = $field->name;
76 $table->fields[$f->name] = $f;