コード例 #1
0
<?php

// Most complex update yet. Let's go...
_rename_table("UserGroups", "Groups");
if (sql_num_query("SHOW TABLES LIKE 'UserCVS'") === 1 && sql_num_query("SHOW TABLES LIKE 'UserGroups'") === 0) {
    // First of all, create a separate table for group assignments of users
    sql_query("CREATE TABLE `UserGroups` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `uid` int(11) NOT NULL,\n                  `group_id` int(11) NOT NULL,\n                  PRIMARY KEY (`id`),\n                  KEY `uid` (`uid`,`group_id`),\n                  KEY `group_id` (`group_id`)\n                )");
    // ...and fill it with the old data
    sql_query("INSERT INTO UserGroups (`uid`, `group_id`) SELECT `UID`, `GroupID` FROM `UserCVS` WHERE `UID` > 0");
    if (sql_num_query("SHOW TABLES LIKE 'Privileges'") == 0) {
        // Then create a separate table that stores the available privileges...
        sql_query("CREATE TABLE IF NOT EXISTS `Privileges` (\n                      `id` int(11) NOT NULL AUTO_INCREMENT,\n                      `name` varchar(128) NOT NULL,\n                      `desc` varchar(1024) NOT NULL,\n                      PRIMARY KEY (`id`),\n                      UNIQUE KEY `name` (`name`)\n                    )");
        // ...and fill it with genuine data. We cannot determine these from the old data!
        sql_query("INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES\n                    (1, 'start', 'Startseite für Gäste/Nicht eingeloggte User'),\n                    (2, 'login', 'Logindialog'),\n                    (3, 'news', 'Anzeigen der News-Seite'),\n                    (4, 'logout', 'User darf sich ausloggen'),\n                    (5, 'register', 'Einen neuen Engel registerieren'),\n                    (6, 'admin_rooms', 'Orte administrieren'),\n                    (7, 'admin_angel_types', 'Engel Typen administrieren'),\n                    (8, 'user_settings', 'User profile settings'),\n                    (9, 'user_messages', 'Writing and reading messages from user to user'),\n                    (10, 'admin_groups', 'Manage usergroups and their rights'),\n                    (11, 'user_questions', 'Let users ask questions'),\n                    (12, 'admin_questions', 'Answer user''s questions'),\n                    (13, 'admin_faq', 'Edit FAQs'),\n                    (14, 'admin_news', 'Administrate the news section'),\n                    (15, 'news_comments', 'User can comment news'),\n                    (16, 'admin_user', 'Administrate the angels'),\n                    (17, 'user_meetings', 'Lists meetings (news)'),\n                    (18, 'admin_language', 'Translate the system'),\n                    (19, 'admin_log', 'Display recent changes'),\n                    (20, 'user_wakeup', 'User wakeup-service organization'),\n                    (21, 'admin_import', 'Import locations and shifts from pentabarf'),\n                    (22, 'credits', 'View credits'),\n                    (23, 'faq', 'View FAQ'),\n                    (24, 'user_shifts', 'Signup for shifts'),\n                    (25, 'user_shifts_admin', 'Signup other angels for shifts.'),\n                    (26, 'user_myshifts', 'Allow angels to view their own shifts and cancel them.'),\n                    (27, 'admin_arrive', 'Mark angels when they are available.'),\n                    (28, 'admin_shifts', 'Create shifts'),\n                    (30, 'ical', 'iCal shift export'),\n                    (31, 'admin_active', 'Mark angels as active and if they got a t-shirt.'),\n                    (32, 'admin_free', 'Show a list of free/unemployed angels.'),\n                    (39, 'faq2', 'View FAQ'),\n                    (40, 'imprint', 'View imprint'),\n                    (41, 'privacy', 'View privacy statement')\n        ");
    }
    if (sql_num_query("SHOW TABLES LIKE 'GroupPrivileges'") == 0) {
        // Last, we create the table for the privileges a group can have
        sql_query("CREATE TABLE `GroupPrivileges` (\n                      `id` int(11) NOT NULL AUTO_INCREMENT,\n                      `group_id` int(11) NOT NULL,\n                      `privilege_id` int(11) NOT NULL,\n                      PRIMARY KEY (`id`),\n                      KEY `group_id` (`group_id`,`privilege_id`)\n                    )");
        // ...and fill it with data.
        /// XXX: We could determine this from the old UserCVS table, at lease partially!
        sqL_query("INSERT INTO `GroupPrivileges` (`id`, `group_id`, `privilege_id`) VALUES\n                    (107, -2, 24),\n                    (24, -1, 5),\n                    (106, -2, 8),\n                    (105, -2, 11),\n                    (23, -1, 2),\n                    (142, -5, 16),\n                    (141, -5, 28),\n                    (104, -2, 26),\n                    (103, -2, 9),\n                    (86, -6, 21),\n                    (140, -5, 6),\n                    (139, -5, 12),\n                    (102, -2, 17),\n                    (138, -5, 14),\n                    (137, -5, 13),\n                    (136, -5, 7),\n                    (101, -2, 15),\n                    (87, -6, 18),\n                    (100, -2, 3),\n                    (85, -6, 10),\n                    (99, -2, 4),\n                    (88, -1, 1),\n                    (133, -3, 32),\n                    (108, -2, 20),\n                    (109, -4, 27),\n                    (135, -5, 31),\n                    (134, -3, 25),\n                    (143, -5, 5),\n                    (260, -1, 39),\n                    (261, -1, 40),\n                    (262, -1, 41);");
    }
    /* Hardest things last: We need to transform the old column-based system
     * with filename-based permissions to the new privileges system.
     *
     * For that to work, we need a manual mapping filename -> privilege, so we
     * can use the old data. So here we go:
     */
    #$files_to_privileges = array(
    #    "index.php" => "start",
    #    "logout.php" => "logout",
コード例 #2
0
<?php

if (_rename_table("EngelType", "AngelTypes")) {
    sql_query("ALTER TABLE `AngelTypes`\n                CHANGE `TID` `id` INT NOT NULL AUTO_INCREMENT,\n                CHANGE `Name` `name` VARCHAR(25) NOT NULL DEFAULT '',\n                DROP `Man`,\n                ADD `restricted` INT(1) NOT NULL\n    ");
}