+ // Second pass processing. We import data here, one tag at a time.
+ if (!$this->firstPass && $this->canImport && $this->errors->no()) {
+ $mdb2 = getConnection();
+
+ // We are in second pass and can import data.
+ if ($name == 'GROUP') {
+ // Create a new group.
+ $this->current_group_id = $this->createGroup(array(
+ 'parent_id' => $this->current_parent_group_id,
+ 'org_id' => $this->org_id,
+ 'name' => $attrs['NAME'],
+ 'currency' => $attrs['CURRENCY'],
+ 'lang' => $attrs['LANG']));
+ // We only have 3 properties at the moment, while work is ongoing...
+
+ // Special handling for top group.
+ if (!$this->org_id && $this->current_group_id) {
+ $this->org_id = $this->current_group_id;
+ $sql = "update tt_groups set org_id = $this->current_group_id where org_id is NULL and id = $this->current_group_id";
+ $affected = $mdb2->exec($sql);
+ }
+ // Set parent group to create subgroups with this group as parent at next entry here.
+ $this->current_parent_group_id = $this->current_group_id;
+ }
+
+ if ($name == 'ROLES') {
+ // If we get here, we have to recycle $currentGroupRoleMap.
+ unset($this->currentGroupRoleMap);
+ $this->currentGroupRoleMap = array();
+ // Role map is reconstructed after processing <role> elements in XML. See below.
+ }
+
+ if ($name == 'ROLE') {
+ // We get here when processing <role> tags for the current group.
+ $role_id = ttRoleHelper::insert(array(
+ 'group_id' => $this->current_group_id,
+ 'org_id' => $this->org_id,
+ 'name' => $attrs['NAME'],
+ 'description' => $attrs['DESCRIPTION'],
+ 'rank' => $attrs['RANK'],
+ 'rights' => $attrs['RIGHTS'],
+ 'status' => $attrs['STATUS']));
+ if ($role_id) {
+ // Add a mapping.
+ $this->currentGroupRoleMap[$attrs['ID']] = $role_id;
+ } else $this->errors->add($i18n->get('error.db'));
+ }
+
+ if ($name == 'TASKS') {
+ // If we get here, we have to recycle $currentGroupTaskMap.
+ unset($this->currentGroupTaskMap);
+ $this->currentGroupTaskMap = array();
+ // Task map is reconstructed after processing <task> elements in XML. See below.
+ }
+
+ if ($name == 'TASK') {
+ // We get here when processing <task> tags for the current group.
+ $task_id = ttTaskHelper::insert(array(
+ 'group_id' => $this->current_group_id,
+ 'org_id' => $this->org_id,
+ 'name' => $attrs['NAME'],
+ 'description' => $attrs['DESCRIPTION'],
+ 'status' => $attrs['STATUS']));
+ if ($task_id) {
+ // Add a mapping.
+ $this->currentGroupTaskMap[$attrs['ID']] = $task_id;
+ } else $this->errors->add($i18n->get('error.db'));
+ }
+
+ if ($name == 'PROJECTS') {
+ // If we get here, we have to recycle $currentGroupProjectMap.
+ unset($this->currentGroupProjectMap);
+ $this->currentGroupProjectMap = array();
+ // Project map is reconstructed after processing <project> elements in XML. See below.
+ }
+
+ if ($name == 'PROJECT') {
+ // We get here when processing <project> tags for the current group.
+
+ // Prepare a list of task ids.
+ $tasks = explode(',', $attrs['TASKS']);
+ foreach ($tasks as $id)
+ $mapped_tasks[] = $this->currentGroupTaskMap[$id];