From: Nik Okuntseff Date: Tue, 20 Nov 2018 08:33:15 +0000 (+0000) Subject: Populating group_id and org_id in tt_custom_field_log. X-Git-Tag: timetracker_1.19-1~601 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=6ebd9b5c4aa66017858979cf00ac1db700f9d643;p=timetracker.git Populating group_id and org_id in tt_custom_field_log. --- diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 7ff3b5b6..a14d9714 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -32,7 +32,6 @@ import('ttTaskHelper'); import('ttClientHelper'); import('ttInvoiceHelper'); import('ttTimeHelper'); -import('ttCustomFieldHelper'); import('ttExpenseHelper'); import('ttFavReportHelper'); @@ -402,9 +401,9 @@ class ttOrgImportHelper { if ($name == 'CUSTOM_FIELD_LOG_ENTRY') { // We get here when processing tags for the current group. - if (!ttCustomFieldHelper::insertLogEntry(array( - // 'group_id' => $this->current_group_id, TODO: add this when group_id field is added to the table. - // 'org_id' => $this->org_id, TODO: add this when org_id field is added to the table. + if (!$this->insertCustomFieldLogEntry(array( + 'group_id' => $this->current_group_id, + 'org_id' => $this->org_id, 'log_id' => $this->currentGroupLogMap[$attrs['LOG_ID']], 'field_id' => $this->currentGroupCustomFieldMap[$attrs['FIELD_ID']], 'option_id' => $this->currentGroupCustomFieldOptionMap[$attrs['OPTION_ID']], @@ -962,4 +961,22 @@ class ttOrgImportHelper { $last_id = $val['last_insert_id']; return $last_id; } + + // insertCustomFieldLogEntry - a helper function to insert a custom field log entry. + private function insertCustomFieldLogEntry($fields) { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $log_id = (int) $fields['log_id']; + $field_id = (int) $fields['field_id']; + $option_id = $fields['option_id']; + $value = $fields['value']; + $status = $fields['status']; + + $sql = "insert into tt_custom_field_log (group_id, org_id, log_id, field_id, option_id, value, status)". + " values ($group_id, $org_id, $log_id, $field_id, ".$mdb2->quote($option_id).", ".$mdb2->quote($value).", ".$mdb2->quote($status).")"; + $affected = $mdb2->exec($sql); + return (!is_a($affected, 'PEAR_Error')); + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 305fc79c..405a939b 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.23.4470 | Copyright © Anuko | +  Anuko Time Tracker 1.18.23.4471 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/dbinstall.php b/dbinstall.php index f7254ad6..d0ccbe33 100644 --- a/dbinstall.php +++ b/dbinstall.php @@ -1034,6 +1034,7 @@ if ($_POST) { setChange("UPDATE `tt_site_config` SET param_value = '1.18.23', modified = now() where param_name = 'version_db' and param_value = '1.18.22'"); setChange("UPDATE `tt_custom_fields` inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.18.23') set org_id = group_id where org_id is null"); setChange("update `tt_custom_field_options` cfo inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.18.23') inner join `tt_custom_fields` cf on cf.id = cfo.field_id set cfo.group_id = cf.group_id, cfo.org_id = cf.org_id where cfo.org_id is null"); + setChange("update `tt_custom_field_log` cfl inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.18.23') inner join `tt_custom_fields` cf on cf.id = cfl.field_id set cfl.group_id = cf.group_id, cfl.org_id = cf.org_id where cfl.org_id is null"); } if ($_POST["cleanup"]) { diff --git a/plugins/CustomFields.class.php b/plugins/CustomFields.class.php index 306b5993..0e450b14 100644 --- a/plugins/CustomFields.class.php +++ b/plugins/CustomFields.class.php @@ -63,9 +63,14 @@ class CustomFields { } function insert($log_id, $field_id, $option_id, $value) { - + global $user; $mdb2 = getConnection(); - $sql = "insert into tt_custom_field_log (log_id, field_id, option_id, value) values($log_id, $field_id, ".$mdb2->quote($option_id).", ".$mdb2->quote($value).")"; + + $group_id = $user->getActiveGroup(); + $org_id = $user->org_id; + + $sql = "insert into tt_custom_field_log (group_id, org_id, log_id, field_id, option_id, value)". + " values($group_id, $org_id, $log_id, $field_id, ".$mdb2->quote($option_id).", ".$mdb2->quote($value).")"; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); }