From d23d7bcb0be0840de0aa847c75e1673dba9302a8 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sat, 28 Jul 2018 20:58:10 +0000 Subject: [PATCH] Wrote code to update group_id in 2 tables. --- WEB-INF/templates/footer.tpl | 2 +- dbinstall.php | 49 +++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index df6d91d3..a261f3e7 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- - +
 Anuko Time Tracker 1.17.96.4298 | Copyright © Anuko | +  Anuko Time Tracker 1.17.96.4299 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/dbinstall.php b/dbinstall.php index 51b01ede..09c8d02e 100644 --- a/dbinstall.php +++ b/dbinstall.php @@ -906,6 +906,53 @@ if ($_POST) { setChange("UPDATE `tt_site_config` SET param_value = '1.17.96', modified = now() where param_name = 'version_db' and param_value = '1.17.92'"); } + // The update_group_id function updates group_id field in tt_log and tt_expense_items tables. + if ($_POST["update_group_id"]) { + $mdb2 = getConnection(); + + $sql = "(select distinct user_id from tt_log where group_id is null) union distinct (select distinct user_id from tt_expense_items where group_id is null)"; + $res = $mdb2->query($sql); + if (is_a($res, 'PEAR_Error')) { + die($res->getMessage()); + } + $users_updated = 0; + $tt_log_records_updated = 0; + $tt_expense_items_updated = 0; + + // Iterate through result set. + while ($val = $res->fetchRow()) { + $user_id = $val['user_id']; + $sql = "select group_id from tt_users where id = $user_id"; + $result = $mdb2->query($sql); + if (is_a($result, 'PEAR_Error')) { + die($res->getMessage()); + } + $value = $result->fetchRow(); + $group_id = $value['group_id']; + + if ($group_id) { + $sql = "update tt_log set group_id = $group_id where user_id = $user_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) { + die($affected->getMessage()); + } + $tt_log_records_updated += $affected; + + $sql = "update tt_expense_items set group_id = $group_id where user_id = $user_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) { + die($affected->getMessage()); + } + $tt_expense_items_updated += $affected; + $users_updated++; + } else { + print "Error: Could not find group for user $user_id...
\n"; + } + } + print "Updated $tt_log_records_updated tt_log records...
\n"; + print "Updated $tt_expense_items_updated tt_expense_items records...
\n"; + } + if ($_POST["cleanup"]) { $mdb2 = getConnection(); @@ -990,7 +1037,7 @@ if ($_POST) {
Update database structure (v1.17.44 to v1.17.96)
-- 2.20.1