Fixed import-export for correct associations in custom field log.
authorNik Okuntseff <support@anuko.com>
Sat, 24 Nov 2018 15:29:14 +0000 (15:29 +0000)
committerNik Okuntseff <support@anuko.com>
Sat, 24 Nov 2018 15:29:14 +0000 (15:29 +0000)
WEB-INF/lib/ttGroupExportHelper.class.php
WEB-INF/lib/ttOrgImportHelper.class.php
WEB-INF/templates/footer.tpl

index 41f773d..4ce8eed 100644 (file)
@@ -335,6 +335,35 @@ class ttGroupExportHelper {
     }
 
     // Write time log entries and build logMap at the same time.
+    $records = $this->getRecordsFromTable('tt_log');
+    if (count($records) > 0) {
+      fwrite($this->file, $this->indentation."  <log>\n");
+      $key = 0;
+      foreach ($records as $record) {
+        $key++;
+        $this->logMap[$record['id']] = $key;
+        $log_part = $this->indentation.'    '."<log_item id=\"$key\"";
+        $log_part .= " user_id=\"".$this->userMap[$record['user_id']]."\"";
+        $log_part .= " date=\"".$record['date']."\"";
+        $log_part .= " start=\"".$record['start']."\"";
+        $log_part .= " duration=\"".$record['duration']."\"";
+        $log_part .= " client_id=\"".$this->clientMap[$record['client_id']]."\"";
+        $log_part .= " project_id=\"".$this->projectMap[$record['project_id']]."\"";
+        $log_part .= " task_id=\"".$this->taskMap[$record['task_id']]."\"";
+        $log_part .= " invoice_id=\"".$this->invoiceMap[$record['invoice_id']]."\"";
+        $log_part .= " comment=\"".htmlspecialchars($record['comment'])."\"";
+        $log_part .= " billable=\"".$record['billable']."\"";
+        $log_part .= " paid=\"".$record['paid']."\"";
+        $log_part .= " status=\"".$record['status']."\"";
+        $log_part .= "></log_item>\n";
+        fwrite($this->file, $log_part);
+      }
+      fwrite($this->file, $this->indentation."  </log>\n");
+      unset($records);
+      unset($log_part);
+    }
+
+    /*
     fwrite($this->file, $this->indentation."  <log>\n");
     $key = 0;
     foreach ($this->userMap as $key => $value) {
@@ -364,6 +393,7 @@ class ttGroupExportHelper {
     fwrite($this->file, $this->indentation."  </log>\n");
     unset($records);
     unset($log_part);
+    */
 
     // Write custom fields.
     if (count($custom_fields) > 0) {
index 30b9a09..1bfa07c 100644 (file)
@@ -331,7 +331,7 @@ class ttOrgImportHelper {
 
       if ($name == 'LOG_ITEM') {
         // We get here when processing <log_item> tags for the current group.
-        $log_item_id = ttTimeHelper::insert(array(
+        $log_item_id = $this->insertLogEntry(array(
           'user_id' => $this->currentGroupUserMap[$attrs['USER_ID']],
           'group_id' => $this->current_group_id,
           'org_id' => $this->org_id,
@@ -339,11 +339,11 @@ class ttOrgImportHelper {
           'start' => $attrs['START'],
           'finish' => $attrs['FINISH'],
           'duration' => $attrs['DURATION'],
-          'client' => $this->currentGroupClientMap[$attrs['CLIENT_ID']],
-          'project' => $this->currentGroupProjectMap[$attrs['PROJECT_ID']],
-          'task' => $this->currentGroupTaskMap[$attrs['TASK_ID']],
-          'invoice' => $this->currentGroupInvoiceMap[$attrs['INVOICE_ID']],
-          'note' => (isset($attrs['COMMENT']) ? $attrs['COMMENT'] : ''),
+          'client_id' => $this->currentGroupClientMap[$attrs['CLIENT_ID']],
+          'project_id' => $this->currentGroupProjectMap[$attrs['PROJECT_ID']],
+          'task_id' => $this->currentGroupTaskMap[$attrs['TASK_ID']],
+          'invoice_id' => $this->currentGroupInvoiceMap[$attrs['INVOICE_ID']],
+          'comment' => (isset($attrs['COMMENT']) ? $attrs['COMMENT'] : ''),
           'billable' => $attrs['BILLABLE'],
           'paid' => $attrs['PAID'],
           'status' => $attrs['STATUS']));
@@ -980,6 +980,51 @@ class ttOrgImportHelper {
     return $last_id;
   }
 
+  // insertLogEntry - a helper function to insert a time log entry.
+  private function insertLogEntry($fields) {
+    global $user;
+    $mdb2 = getConnection();
+
+    $group_id = (int) $fields['group_id'];
+    $org_id = (int) $fields['org_id'];
+    $user_id = (int) $fields['user_id'];
+    $date = $fields['date'];
+    $start = $fields['start'];
+    $duration = $fields['duration'];
+    $client_id = $fields['client_id'];
+    $project_id = $fields['project_id'];
+    $task_id = $fields['task_id'];
+    $invoice_id = $fields['invoice_id'];
+    $comment = $fields['comment'];
+    $billable = (int) $fields['billable'];
+    $paid = (int) $fields['paid'];
+    $status = $fields['status'];
+
+    $sql = "insert into tt_log".
+      " (user_id, group_id, org_id, date, start, duration, client_id, project_id, task_id, invoice_id, comment".
+      ", billable, paid, created, created_ip, created_by, status)".
+      " values ($user_id, $group_id, $org_id".
+      ", ".$mdb2->quote($date).
+      ", ".$mdb2->quote($start).
+      ", ".$mdb2->quote($duration).
+      ", ".$mdb2->quote($client_id).
+      ", ".$mdb2->quote($project_id).
+      ", ".$mdb2->quote($task_id).
+      ", ".$mdb2->quote($invoice_id).
+      ", ".$mdb2->quote($comment).
+      ", $billable, $paid".
+      ", now(), ".$mdb2->quote($_SERVER['REMOTE_ADDR']).", ".$mdb2->quote($user->id).
+      ", ". $mdb2->quote($status).")";
+    $affected = $mdb2->exec($sql);
+    if (is_a($affected, 'PEAR_Error')) {
+      $this->errors->add($i18n->get('error.db')); // TODO: review whether or not to add error here in all insert calls.
+      return false;
+    }
+
+    $log_id = $mdb2->lastInsertID('tt_log', 'id');
+    return $log_id;
+  }
+
   // insertCustomFieldLogEntry - a helper function to insert a custom field log entry.
   private function insertCustomFieldLogEntry($fields) {
     $mdb2 = getConnection();
index a154b7d..9757471 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.27.4507 | 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.28.4508 | 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>