X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttOrgImportHelper.class.php;h=251cb3ea6a2a398ad160683dce94d7d5d80cba9d;hb=c14bc01ae221ece2c5b78c9c39b4902cb25154d6;hp=626408f2879c1de59cc42bebb7f79ab0486a10a7;hpb=6fc6c28b9eed8a9316a630185e327a53bb0d9e0c;p=timetracker.git diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 626408f2..251cb3ea 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -31,6 +31,7 @@ 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 $num_users = 0; // A number of active and inactive users we are importing. var $conflicting_logins = null; // A comma-separated list of logins 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. @@ -81,6 +82,7 @@ class ttOrgImportHelper { // In first pass we check user logins for potential collisions with existing. if ($name == 'USER' && $this->canImport) { $login = $attrs['LOGIN']; + if ('' != $attrs['STATUS']) $this->num_users++; if ('' != $attrs['STATUS'] && $this->loginExists($login)) { // We have a login collision. Append colliding login to a list of things we cannot import. $this->conflicting_logins .= ($this->conflicting_logins ? ", $login" : $login); @@ -247,6 +249,7 @@ class ttOrgImportHelper { 'login' => $attrs['LOGIN'], 'password' => $attrs['PASSWORD'], 'rate' => $attrs['RATE'], + 'quota_percent' => $attrs['QUOTA_PERCENT'], 'email' => $attrs['EMAIL'], 'status' => $attrs['STATUS']), false); if ($user_id) { @@ -493,12 +496,33 @@ class ttOrgImportHelper { } } - // importXml - uncompresses the file, reads and parses its content. During parsing, - // startElement, endElement, and dataElement functions are called as many times as necessary. - // Actual import occurs in the endElement handler. + // importXml - uncompresses the file, reads and parses its content. + // It goes through the file 2 times. + // + // During 1st pass, it determines whether we can import data. + // In 1st pass, startElement function is called as many times as necessary. + // + // Actual import occurs during 2nd pass. + // In 2nd pass, startElement and endElement are called many times. + // We only use endElement to finish current group processing. + // + // The above allows us to export/import complex orgs with nested groups, + // while by design all data are in attributes of the elements (no CDATA). + // + // There is currently at least one problem with keeping all data in attributes: + // a vertical tab character 0xB anywhere breaks parsing, making import impossible. + // See https://github.com/sparklemotion/nokogiri/issues/1581 - looks like + // an XML standard thing. Apparently, other invalid characters break parsing too. + // This problem needs to be addressed at some point but how exactly without + // complicating export-import too much with CDATA and dataElement processing? function importXml() { global $i18n; + if (!$_FILES['xmlfile']['name']) { + $this->errors->add($i18n->get('error.upload')); + return; // There is nothing to do if we don't have a file. + } + // Do we have a compressed file? $compressed = false; $file_ext = substr($_FILES['xmlfile']['name'], strrpos($_FILES['xmlfile']['name'], '.') + 1); @@ -547,6 +571,10 @@ class ttOrgImportHelper { $this->errors->add($i18n->get('error.user_exists')); $this->errors->add(sprintf($i18n->get('error.cannot_import'), $this->conflicting_logins)); } + if (!ttUserHelper::canAdd($this->num_users)) { + $this->canImport = false; + $this->errors->add($i18n->get('error.user_count')); + } $this->firstPass = false; // We are done with 1st pass. xml_parser_free($parser); @@ -754,7 +782,7 @@ class ttOrgImportHelper { $group_id = (int) $fields['group_id']; $org_id = (int) $fields['org_id']; - $columns = '(login, password, name, group_id, org_id, role_id, client_id, rate, email, created, created_ip, created_by, status)'; + $columns = '(login, password, name, group_id, org_id, role_id, client_id, rate, quota_percent, email, created, created_ip, created_by, status)'; $values = 'values ('; $values .= $mdb2->quote($fields['login']); @@ -765,6 +793,7 @@ class ttOrgImportHelper { $values .= ', '.(int)$fields['role_id']; $values .= ', '.$mdb2->quote($fields['client_id']); $values .= ', '.$mdb2->quote($fields['rate']); + $values .= ', '.$mdb2->quote($fields['quota_percent']); $values .= ', '.$mdb2->quote($fields['email']); $values .= ', now(), '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', '.$user->id; $values .= ', '.$mdb2->quote($fields['status']);