X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=dbinstall.php;h=1c95fc28cde205084f6dc35fcb919e4438617706;hb=8d68ecdd7b1c45cb2a5cf592b8d504d7e4614911;hp=a800df2fa19fa7b0793a65e5c36f3ef3005dd135;hpb=e96a91f4cdd1bd25ffab2afdc7d90102b30a37ba;p=timetracker.git diff --git a/dbinstall.php b/dbinstall.php index a800df2f..1c95fc28 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('ttRoleHelper'); // 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,46 @@ 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.team_id, u.role, u.status, t.lang from tt_users u inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.17.44') left join tt_teams t on (u.team_id = t.id) 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']; + $team_id = $val['team_id']; + $lang = $val['lang']; + $legacy_role = $val['role']; + + $sql = "select count(*) as count from tt_roles where team_id = $team_id"; + $result = $mdb2->query($sql); + if (is_a($result, 'PEAR_Error')) die($result->getMessage()); + $row = $result->fetchRow(); + if ($row['count'] == 0) + ttRoleHelper::createPredefinedRoles($team_id, $lang); + + // Obtain new role id based on legacy role. + $role_id = ttRoleHelper::getRoleByRank($legacy_role, $team_id); + if (!$role_id) continue; // Role not found, nothing to do. + + $sql = "update tt_users set role_id = $role_id where id = $user_id and team_id = $team_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) die($affected->getMessage()); + + $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 +885,7 @@ if ($_POST) { Update database structure (v1.14 to v1.17.44) -
+