From cd0fdd6bdf0879f047732df3d0092a291b35ff6c Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Mon, 19 Nov 2018 23:11:58 +0000 Subject: [PATCH] Populating org_id in tt_custom_fields table. --- WEB-INF/lib/ttOrgImportHelper.class.php | 30 +++++++++++++++++++++++-- WEB-INF/templates/footer.tpl | 2 +- dbinstall.php | 1 + plugins/CustomFields.class.php | 5 ++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index dda7f75d..2758ac21 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -364,9 +364,9 @@ class ttOrgImportHelper { if ($name == 'CUSTOM_FIELD') { // We get here when processing tags for the current group. - $custom_field_id = ttCustomFieldHelper::insertField(array( + $custom_field_id = $this->insertCustomField(array( 'group_id' => $this->current_group_id, - // 'org_id' => $this->org_id, TODO: add this when org_id field is added to the table. + 'org_id' => $this->org_id, 'type' => $attrs['TYPE'], 'label' => $attrs['LABEL'], 'required' => $attrs['REQUIRED'], @@ -913,4 +913,30 @@ class ttOrgImportHelper { $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } + + // insertCustomField - a helper function to insert a custom field. + private function insertCustomField($fields) { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $type = (int) $fields['type']; + $label = $fields['label']; + $required = (int) $fields['required']; + $status = $fields['status']; + + $sql = "insert into tt_custom_fields". + " (group_id, org_id, type, label, required, status)". + " values($group_id, $org_id, $type, ".$mdb2->quote($label).", $required, ".$mdb2->quote($status).")"; + $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 9ace916c..00b5047c 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.23.4468 | Copyright © Anuko | +  Anuko Time Tracker 1.18.23.4469 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/dbinstall.php b/dbinstall.php index 90067399..a6c499bd 100644 --- a/dbinstall.php +++ b/dbinstall.php @@ -1032,6 +1032,7 @@ if ($_POST) { setChange("ALTER TABLE `tt_custom_field_log` ADD `group_id` int(11) default NULL AFTER `id`"); 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"); } if ($_POST["cleanup"]) { diff --git a/plugins/CustomFields.class.php b/plugins/CustomFields.class.php index 00582e3e..57f1d86c 100644 --- a/plugins/CustomFields.class.php +++ b/plugins/CustomFields.class.php @@ -274,7 +274,10 @@ class CustomFields { static function insertField($field_name, $field_type, $required) { global $user; $mdb2 = getConnection(); - $sql = "insert into tt_custom_fields (group_id, type, label, required, status) values($user->group_id, $field_type, ".$mdb2->quote($field_name).", $required, 1)"; + $group_id = $user->getActiveGroup(); + $org_id = $user->org_id; + $sql = "insert into tt_custom_fields (group_id, org_id, type, label, required, status)". + " values($group_id, $org_id, $field_type, ".$mdb2->quote($field_name).", $required, 1)"; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } -- 2.20.1