diff options
author | Philip Häusler <msquare@notrademark.de> | 2011-12-26 16:09:15 +0100 |
---|---|---|
committer | Philip Häusler <msquare@notrademark.de> | 2011-12-26 16:09:15 +0100 |
commit | d0bb9fbbebf2112b7330476a471c18e06222634b (patch) | |
tree | abc17d687448e1844c0cff3ca953bbf54f17d7be /db/update.d/11_Room_and_NeededAngelTypes.php | |
parent | 1852a2a1ae190391d47d5ce15398bc0c02c7071b (diff) | |
parent | 7154097581f231753005aaabdc12d00173b7ce27 (diff) |
Merge branch 'master' of https://vcs.wybt.net/engelsystem/git
Diffstat (limited to 'db/update.d/11_Room_and_NeededAngelTypes.php')
-rw-r--r-- | db/update.d/11_Room_and_NeededAngelTypes.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/db/update.d/11_Room_and_NeededAngelTypes.php b/db/update.d/11_Room_and_NeededAngelTypes.php new file mode 100644 index 00000000..f5b1c5b4 --- /dev/null +++ b/db/update.d/11_Room_and_NeededAngelTypes.php @@ -0,0 +1,33 @@ +<?php +if(sql_num_query("SHOW TABLES LIKE 'NeededAngelTypes'") === 0) { + sql_query("CREATE TABLE `NeededAngelTypes` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `room_id` int(11) DEFAULT NULL, + `shift_id` int(11) DEFAULT NULL, + `angel_type_id` int(11) NOT NULL, + `count` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `room_id` (`room_id`,`angel_type_id`), + KEY `shift_id` (`shift_id`), + KEY `angel_type_id` (`angel_type_id`) + ) + "); + $data = sql_select("SELECT * FROM `Room`"); + $res = sql_query("SHOW COLUMNS FROM `Room` LIKE 'DEFAULT_EID_%'"); + while($col = mysql_fetch_assoc($res)) { + $tid = explode('_', $col['Field']); + $tid = intval(array_pop($tid)); + if($col['Default'] != '0') + sql_query("INSERT INTO `NeededAngelTypes` (`angel_type_id`, `count`) VALUES (" . $tid . ", " . intval($col['Default']) . ")"); + + foreach($data as $row) { + if($row[$col['Field']] > 0) + sql_query("INSERT INTO `NeededAngelTypes` (`angel_type_id`, `room_id`, `count`) VALUES (" . $tid . ", " . $row['RID'] . ", " . $row[$col['Field']] . ")"); + } + sql_query("ALTER TABLE `Room` DROP `" . $col['Field'] . "`"); + } + + $applied = true; +} +_add_index("Room", array("Name")); +?> |