From 4255418fd8d5a23ff005e4136a0b173b9ad62bd0 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sun, 11 Nov 2018 16:56:06 +0000 Subject: [PATCH] Added database schema attribute to export files. --- WEB-INF/lib/ttOrgExportHelper.class.php | 15 ++++++++++++++- WEB-INF/lib/ttOrgImportHelper.class.php | 13 +++++++++++++ WEB-INF/resources/en.lang.php | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/WEB-INF/lib/ttOrgExportHelper.class.php b/WEB-INF/lib/ttOrgExportHelper.class.php index aa9c9051..719c486b 100644 --- a/WEB-INF/lib/ttOrgExportHelper.class.php +++ b/WEB-INF/lib/ttOrgExportHelper.class.php @@ -51,7 +51,8 @@ class ttOrgExportHelper { // Write XML to the file. fwrite($file, "\n"); - fwrite($file, "\n"); + $org_part = "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. @@ -98,4 +99,16 @@ class ttOrgExportHelper { 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; + } } diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 80dc8a19..ada23286 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -41,6 +41,7 @@ import('ttFavReportHelper'); // 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. @@ -73,6 +74,18 @@ class ttOrgImportHelper { // 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)) { diff --git a/WEB-INF/resources/en.lang.php b/WEB-INF/resources/en.lang.php index 82059051..31f0ebb8 100644 --- a/WEB-INF/resources/en.lang.php +++ b/WEB-INF/resources/en.lang.php @@ -102,6 +102,7 @@ $i18n_key_words = array( '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', -- 2.20.1