// Write XML to the file.
fwrite($file, "<?xml version=\"1.0\"?>\n");
- fwrite($file, "<org>\n");
+ $org_part = "<org schema=\"".$this->getVersion()."\">\n";
+ fwrite($file, $org_part);
// Use ttGroupExportHelper to export all groups.
$groupExportHelper = new ttGroupExportHelper($user->group_id, $file, ' '); // 2 spaces indentation for home group.
fclose ($in_file);
return true;
}
+
+ private function getVersion() {
+ $mdb2 = getConnection();
+ $sql = "select param_value from tt_site_config where param_name = 'version_db'";
+ $res = $mdb2->query($sql);
+ if (!is_a($res, 'PEAR_Error')) {
+ $val = $res->fetchRow();
+ return $val['param_value'];
+ $result[] = $val;
+ }
+ return false;
+ }
}
// When done, it should handle import of complex groups consisting of other groups.
class ttOrgImportHelper {
var $errors = null; // Errors go here. Set in constructor by reference.
+ var $schema_version = null; // Database schema version from XML file we import from.
var $conflicting_entities = null; // A comma-separated list of entity names we cannot import.
var $canImport = true; // False if we cannot import data due to a conflict such as login collision.
var $firstPass = true; // True during first pass through the file.
// First pass. We only check user logins for potential collisions with existing.
if ($this->firstPass) {
+ if ($name == 'ORG' && $this->canImport) {
+ if ($attrs['SCHEMA'] == null) {
+ // We need (database) schema attribute to be available for import to work.
+ // Old Time Tracker export files don't have this.
+ // Current import code does not work with old format because we had to
+ // restructure data in export files for subgroup support.
+ $this->canImport = false;
+ $this->errors->add($i18n->get('error.format'));
+ return;
+ }
+ }
+
if ($name == 'USER' && $this->canImport) {
$login = $attrs['LOGIN'];
if ('' != $attrs['STATUS'] && ttUserHelper::getUserByLogin($login)) {
'error.future_date' => 'Date is in future.',
'error.xml' => 'Error in XML file at line %d: %s.',
'error.cannot_import' => 'Cannot import: %s.',
+'error.format' => 'Invalid file format.',
// Labels for buttons.
'button.login' => 'Login',