X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=dbinstall.php;h=2719bca4a9ecd48281051d2cd23d8b419fb3d899;hb=074e8daef75c2b729e75f350b52935a6b7ecfba8;hp=a800df2fa19fa7b0793a65e5c36f3ef3005dd135;hpb=e96a91f4cdd1bd25ffab2afdc7d90102b30a37ba;p=timetracker.git diff --git a/dbinstall.php b/dbinstall.php index a800df2f..2719bca4 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,57 @@ 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, 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["convert11744to11751"]) { + setChange("update `tt_roles` inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.17.44') set rights = replace(rights, 'override_punch_mode,override_date_lock', 'override_punch_mode,override_own_punch_mode,override_date_lock')"); + setChange("UPDATE `tt_site_config` SET param_value = '1.17.48' where param_name = 'version_db' and param_value = '1.17.44'"); + setChange("update `tt_users` inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.17.48') set role_id = (select id from tt_roles where team_id = 0 and rank = 512) where role = 324"); + setChange("UPDATE `tt_site_config` SET param_value = '1.17.49' where param_name = 'version_db' and param_value = '1.17.48'"); + setChange("ALTER TABLE `tt_users` drop role"); + setChange("UPDATE `tt_site_config` SET param_value = '1.17.50' where param_name = 'version_db' and param_value = '1.17.49'"); + setChange("update `tt_roles` inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.17.50') set rights = replace(rights, 'override_date_lock,swap_roles', 'override_date_lock,override_own_date_lock,swap_roles')"); + setChange("UPDATE `tt_site_config` SET param_value = '1.17.51' where param_name = 'version_db' and param_value = '1.17.50'"); + } + if ($_POST["cleanup"]) { $mdb2 = getConnection(); @@ -807,7 +859,7 @@ if ($_POST) {

DB Install

-
Create database structure (v1.17.44) + Create database structure (v1.17.51)
(applies only to new installations, do not execute when updating)
@@ -844,7 +896,11 @@ if ($_POST) { Update database structure (v1.14 to v1.17.44) -
+
+ + + Update database structure (v1.17.44 to v1.17.51) +