From a4c1ced936fb1a1b71d4d34479a9c999aef4b338 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Tue, 20 Nov 2018 08:02:25 +0000 Subject: [PATCH] Populating group_id and org_id in tt_custom_field_options table. --- WEB-INF/lib/ttOrgImportHelper.class.php | 29 ++++++++++++++++++++++--- WEB-INF/templates/footer.tpl | 2 +- dbinstall.php | 1 + plugins/CustomFields.class.php | 8 +++++-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 2758ac21..7ff3b5b6 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -388,9 +388,9 @@ class ttOrgImportHelper { if ($name == 'CUSTOM_FIELD_OPTION') { // We get here when processing tags for the current group. - $custom_field_option_id = ttCustomFieldHelper::insertOption(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. + $custom_field_option_id = $this->insertCustomFieldOption(array( + 'group_id' => $this->current_group_id, + 'org_id' => $this->org_id, 'field_id' => $this->currentGroupCustomFieldMap[$attrs['FIELD_ID']], 'value' => $attrs['VALUE'])); if ($custom_field_option_id) { @@ -939,4 +939,27 @@ class ttOrgImportHelper { $last_id = $val['last_insert_id']; return $last_id; } + + // insertCustomFieldOption - a helper function to insert a custom field option. + private function insertCustomFieldOption($fields) { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $field_id = (int) $fields['field_id']; + $value = $fields['value']; + + $sql = "insert into tt_custom_field_options (group_id, org_id, field_id, value)". + " values ($group_id, $org_id, $field_id, ".$mdb2->quote($value).")"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + $last_id = 0; + $sql = "select last_insert_id() as last_insert_id"; + $res = $mdb2->query($sql); + $val = $res->fetchRow(); + $last_id = $val['last_insert_id']; + return $last_id; + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 00b5047c..305fc79c 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.23.4469 | Copyright © Anuko | +  Anuko Time Tracker 1.18.23.4470 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/dbinstall.php b/dbinstall.php index a6c499bd..f7254ad6 100644 --- a/dbinstall.php +++ b/dbinstall.php @@ -1033,6 +1033,7 @@ if ($_POST) { setChange("ALTER TABLE `tt_custom_field_log` ADD `org_id` int(11) default NULL AFTER `group_id`"); 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"); } if ($_POST["cleanup"]) { diff --git a/plugins/CustomFields.class.php b/plugins/CustomFields.class.php index 57f1d86c..306b5993 100644 --- a/plugins/CustomFields.class.php +++ b/plugins/CustomFields.class.php @@ -110,9 +110,12 @@ class CustomFields { // insertOption adds a new option to a custom field. static function insertOption($field_id, $option_name) { - + global $user; $mdb2 = getConnection(); + $group_id = $user->getActiveGroup(); + $org_id = $user->org_id; + // Check if the option exists. $id = 0; $sql = "select id from tt_custom_field_options where field_id = $field_id and value = ".$mdb2->quote($option_name); @@ -123,7 +126,8 @@ class CustomFields { // Insert option. if (!$id) { - $sql = "insert into tt_custom_field_options (field_id, value) values($field_id, ".$mdb2->quote($option_name).")"; + $sql = "insert into tt_custom_field_options (group_id, org_id, field_id, value)". + " values($group_id, $org_id, $field_id, ".$mdb2->quote($option_name).")"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; -- 2.20.1