From f05a2db179417c20c7d841f0363bca4988c8a2ca Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sat, 24 Nov 2018 15:29:14 +0000 Subject: [PATCH] Fixed import-export for correct associations in custom field log. --- WEB-INF/lib/ttGroupExportHelper.class.php | 30 ++++++++++++ WEB-INF/lib/ttOrgImportHelper.class.php | 57 ++++++++++++++++++++--- WEB-INF/templates/footer.tpl | 2 +- 3 files changed, 82 insertions(+), 7 deletions(-) diff --git a/WEB-INF/lib/ttGroupExportHelper.class.php b/WEB-INF/lib/ttGroupExportHelper.class.php index 41f773d7..4ce8eed6 100644 --- a/WEB-INF/lib/ttGroupExportHelper.class.php +++ b/WEB-INF/lib/ttGroupExportHelper.class.php @@ -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." \n"); + $key = 0; + foreach ($records as $record) { + $key++; + $this->logMap[$record['id']] = $key; + $log_part = $this->indentation.' '."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 .= ">\n"; + fwrite($this->file, $log_part); + } + fwrite($this->file, $this->indentation." \n"); + unset($records); + unset($log_part); + } + + /* fwrite($this->file, $this->indentation." \n"); $key = 0; foreach ($this->userMap as $key => $value) { @@ -364,6 +393,7 @@ class ttGroupExportHelper { fwrite($this->file, $this->indentation." \n"); unset($records); unset($log_part); + */ // Write custom fields. if (count($custom_fields) > 0) { diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 30b9a09d..1bfa07c7 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -331,7 +331,7 @@ class ttOrgImportHelper { if ($name == 'LOG_ITEM') { // We get here when processing 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(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index a154b7de..9757471d 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.27.4507 | Copyright © Anuko | +  Anuko Time Tracker 1.18.28.4508 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1