X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/d8d15e03655dcacf8365baf6d2b36d80dad84890..6b1d36d49ecb821678978322df9754ce23bb0359:/dbinstall.php
diff --git a/dbinstall.php b/dbinstall.php
index 1648a827..2719bca4 100644
--- a/dbinstall.php
+++ b/dbinstall.php
@@ -31,7 +31,7 @@ require_once('WEB-INF/lib/common.lib.php');
require_once('initialize.php');
import('ttUserHelper');
import('ttTaskHelper');
-import('ttUser');
+import('ttRoleHelper');
// setChange - executes an sql statement. TODO: rename this function to something better.
// Better yet, redo the entire thing and make an installer.
@@ -771,46 +771,51 @@ if ($_POST) {
$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";
+ $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());
- }
+ 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);
- // 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();
+ // 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.
- if ($deactivate) {
- // Deactivate temporarily activated user back.
- $sql = "update tt_users set status = 0 where id = $user_id";
- $mdb2->exec($sql);
- }
+ $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());
- 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["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();
@@ -854,7 +859,7 @@ if ($_POST) {
| Create database structure (v1.17.44) + | Create database structure (v1.17.51)
(applies only to new installations, do not execute when updating) |