version = (int)$s['version']; /* fabricate a table to hold the schema info */ $table = new MTrackDBSchema_Table; $table->name = 'mtrack_schema'; $f = new stdclass; $f->name = 'version'; $f->type = 'integer'; $f->nullable = '0'; $table->fields[$f->name] = $f; $this->tables[$table->name] = $table; foreach ($s->table as $t) { $table = new MTrackDBSchema_Table; $table->name = (string)$t['name']; foreach ($t->field as $f) { $F = new stdclass; foreach ($f->attributes() as $k => $v) { $F->{(string)$k} = (string)$v; } if (isset($f->comment)) { $F->comment = (string)$f->comment; } $table->fields[$F->name] = $F; } foreach ($t->key as $k) { $K = new stdclass; $K->fields = array(); if (isset($k['type'])) { $K->type = (string)$k['type']; } else { $K->type = 'primary'; } foreach ($k->field as $f) { $K->fields[] = (string)$f; } if (isset($k['name'])) { $K->name = (string)$k['name']; } else { $K->name = sprintf("idx_%s_%s", $table->name, join('_', $K->fields)); } $table->keys[$K->name] = $K; } $this->tables[$table->name] = $table; } foreach ($s->post as $p) { $this->post[(string)$p['driver']] = (string)$p; } /* apply custom ticket fields */ if (isset($this->tables['tickets'])) { $table = $this->tables['tickets']; $custom = MTrackTicket_CustomFields::getInstance(); foreach ($custom->fields as $field) { $f = new stdclass; $f->name = $field->name; $f->type = 'text'; $table->fields[$f->name] = $f; } } } }