From: Nik Okuntseff Date: Wed, 14 Mar 2018 22:29:04 +0000 (+0000) Subject: Wrote a function to update role_id for all active and inactive users. X-Git-Tag: timetracker_1.19-1~1033 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=d8d15e03655dcacf8365baf6d2b36d80dad84890;p=timetracker.git Wrote a function to update role_id for all active and inactive users. --- diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 5e9768d1..d6f868a7 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- - +
 Anuko Time Tracker 1.17.44.4078 | Copyright © Anuko | +  Anuko Time Tracker 1.17.44.4079 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/dbinstall.php b/dbinstall.php index a800df2f..1648a827 100644 --- a/dbinstall.php +++ b/dbinstall.php @@ -31,6 +31,7 @@ require_once('WEB-INF/lib/common.lib.php'); require_once('initialize.php'); import('ttUserHelper'); import('ttTaskHelper'); +import('ttUser'); // setChange - executes an sql statement. TODO: rename this function to something better. // Better yet, redo the entire thing and make an installer. @@ -764,6 +765,52 @@ if ($_POST) { setChange("UPDATE `tt_site_config` SET `param_value` = '1.17.44' where param_name = 'version_db'"); } + // The update_role_id function assigns a role_id to users, who don't have it. + if ($_POST['update_role_id']) { + import('I18n'); + + $mdb2 = getConnection(); + + $sql = "select u.id, u.status from tt_users u inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.17.44') where u.role_id is NULL and u.status is NOT NULL"; + $res = $mdb2->query($sql); + if (is_a($res, 'PEAR_Error')) { + die($res->getMessage()); + } + + $users_updated = 0; + // Iterate through users. + while ($val = $res->fetchRow()) { + + $user_id = $val['id']; + + // Code only works on active users. Temporarily activate a user. + $deactivate = false; + if ($val['status'] == 0) { + $deactivate = true; // To deactivate later. + $sql = "update tt_users set status = 1 where id = $user_id"; + $mdb2->exec($sql); + } + + $user = new ttUser(null, $user_id); + $i18n = new I18n(); + $i18n->load($val['lang']); + if ($user->login) + $user->migrateLegacyRole(); + + if ($deactivate) { + // Deactivate temporarily activated user back. + $sql = "update tt_users set status = 0 where id = $user_id"; + $mdb2->exec($sql); + } + + unset($user); + unset($i18n); + $users_updated++; + // if ($users_updated >= 1000) break; // TODO: uncomment for large user sets to run multiple times. + } + print "Updated $users_updated users...
\n"; + } + if ($_POST["cleanup"]) { $mdb2 = getConnection(); @@ -844,7 +891,7 @@ if ($_POST) {
Update database structure (v1.14 to v1.17.44)

diff --git a/week.php b/week.php index 6bd2d492..29c15e47 100644 --- a/week.php +++ b/week.php @@ -198,7 +198,7 @@ class WeekViewCellRenderer extends DefaultCellRenderer { // Elements of weekTimeForm. $form = new Form('weekTimeForm'); -if ($user->canManageTeam()) { +if ($user->can('track_time')) { $user_list = ttTeamHelper::getActiveUsers(array('putSelfFirst'=>true)); if (count($user_list) > 1) { $form->addInput(array('type'=>'combobox', @@ -463,7 +463,7 @@ if ($request->isPost()) { } } elseif ($request->getParameter('onBehalfUser')) { - if($user->canManageTeam()) { + if($user->can('track_time')) { unset($_SESSION['behalf_id']); unset($_SESSION['behalf_name']);