Added users to new import.
authorNik Okuntseff <support@anuko.com>
Sat, 10 Nov 2018 15:57:09 +0000 (15:57 +0000)
committerNik Okuntseff <support@anuko.com>
Sat, 10 Nov 2018 15:57:09 +0000 (15:57 +0000)
WEB-INF/lib/ttOrgImportHelper.class.php
WEB-INF/templates/footer.tpl

index 7c00f25..6519ffa 100644 (file)
@@ -44,19 +44,19 @@ class ttOrgImportHelper {
   var $current_group_id        = null; // Current group id during parsing.
   var $current_parent_group_id = null; // Current parent group id during parsing.
                                        // Set when we create a new group.
-  // Entities for current group. -- Looks like they are not needed as we insert right away...
-  // var $currentGroupRoles = array(); // Array of arrays of role properties.
-  // var $currentGroupUsers = array(); // Array of arrays of user properties.
+  var $top_role_id    = 0;       // Top role id.
 
   // Entity maps for current group. They map XML ids with database ids.
   var $currentGroupRoleMap    = array();
   var $currentGroupTaskMap    = array();
   var $currentGroupProjectMap = array();
   var $currentGroupClientMap  = array();
+  var $currentGroupUserMap    = array();
 
   // Constructor.
   function __construct(&$errors) {
     $this->errors = &$errors;
+    $this->top_role_id = ttRoleHelper::getRoleByRank(512, 0);
   }
 
   // startElement - callback handler for opening tag of an XML element in the file.
@@ -199,6 +199,36 @@ class ttOrgImportHelper {
           $this->currentGroupClientMap[$attrs['ID']] = $client_id;
         } else $this->errors->add($i18n->get('error.db'));
       }
+
+      if ($name == 'USERS') {
+        // If we get here, we have to recycle $currentGroupUserMap.
+        unset($this->currentGroupUserMap);
+        $this->currentGroupUserMap = array();
+        // User map is reconstructed after processing <user> elements in XML. See below.
+      }
+
+      if ($name == 'USER') {
+        // We get here when processing <user> tags for the current group.
+
+        $role_id = $attrs['ROLE_ID'] === '0' ? $this->top_role_id :  $this->currentGroupRoleMap[$attrs['ROLE_ID']]; // 0 (not null) means top manager role.
+
+        $user_id = ttUserHelper::insert(array(
+          'group_id' => $this->current_group_id,
+          'org_id' => $this->org_id,
+          'role_id' => $role_id,
+          'client_id' => $this->currentGroupClientMap[$attrs['CLIENT_ID']],
+          'name' => $attrs['NAME'], // TODO: check if we need to decode all such things from htmlentities back. Refactor from the beginning if necessary.
+          'login' => $attrs['LOGIN'],
+          'password' => $attrs['PASSWORD'],
+          'rate' => $attrs['RATE'],
+          'email' => $attrs['EMAIL'],
+          'status' => $attrs['STATUS']), false);
+        // TODO: what about created_by and other audit info?
+        if ($user_id) {
+          // Add a mapping.
+          $this->currentGroupUserMap[$attrs['ID']] = $user_id;
+        } else $this->errors->add($i18n->get('error.db'));
+      }
     }
   }
 
index d4275c1..f9a3350 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.18.12.4406 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.18.12.4407 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>