summaryrefslogtreecommitdiff
path: root/db/update.d/11_Room_and_NeededAngelTypes.php
diff options
context:
space:
mode:
Diffstat (limited to 'db/update.d/11_Room_and_NeededAngelTypes.php')
-rw-r--r--db/update.d/11_Room_and_NeededAngelTypes.php33
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"));
+?>