diff options
author | Jan-Philipp Litza <janphilipp@litza.de> | 2011-12-27 13:22:43 +0100 |
---|---|---|
committer | Jan-Philipp Litza <janphilipp@litza.de> | 2011-12-27 13:22:43 +0100 |
commit | e90e6085dfd35ee101e43b0fa0f84a71a19f7208 (patch) | |
tree | 79dfce1522e0f38e73f44bd8e6f78fbd2141657f /db/update.d/11_Room_and_NeededAngelTypes.php | |
parent | 60810251e5d22e716107169b37f40072876a7f43 (diff) |
fixed various bug in DB update scripts
Diffstat (limited to 'db/update.d/11_Room_and_NeededAngelTypes.php')
-rw-r--r-- | db/update.d/11_Room_and_NeededAngelTypes.php | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/db/update.d/11_Room_and_NeededAngelTypes.php b/db/update.d/11_Room_and_NeededAngelTypes.php index f5b1c5b4..31cf7f06 100644 --- a/db/update.d/11_Room_and_NeededAngelTypes.php +++ b/db/update.d/11_Room_and_NeededAngelTypes.php @@ -29,5 +29,24 @@ if(sql_num_query("SHOW TABLES LIKE 'NeededAngelTypes'") === 0) { $applied = true; } + +if(sql_num_query("SELECT * FROM `ShiftEntry` WHERE `UID` = 0")) { + $data = sql_query(" + INSERT INTO `NeededAngelTypes` (`shift_id`, `angel_type_id`, `count`) + SELECT se.`SID`, se.`TID`, se.`count` FROM ( + SELECT `SID`, `TID`, COUNT(`TID`) AS `count` + FROM `ShiftEntry` + GROUP BY `SID`, `TID` + ) AS se + INNER JOIN `Shifts` AS s ON s.`SID` = se.`SID` + INNER JOIN `Room` AS r ON s.`RID` = r.`RID` + LEFT JOIN `NeededAngelTypes` AS nat ON (nat.`room_id` = r.`RID` AND nat.`angel_type_id` = se.`TID`) + WHERE nat.`count` IS NULL OR nat.`count` != se.`count` + "); + + sql_query("DELETE FROM `ShiftEntry` WHERE `UID` = 0 AND `Comment` IS NULL"); + + $applied = true; +} _add_index("Room", array("Name")); ?> |