Exemple #1
0
<?php

if (sql_num_query("SHOW COLUMNS FROM `Shifts` LIKE 'Date_'") == 2) {
    if (sql_num_query("DESCRIBE `Shifts` `Len`") != 0) {
        if (sql_num_query("SELECT * FROM `Shifts` WHERE DATE_SUB(`DateE`, INTERVAL (`Len`*60) MINUTE) != `DateS`") != 0) {
            die("Inconsistent data in Shifts table, won't do update " . __FILE__);
        } else {
            sql_query("ALTER TABLE `Shifts` DROP `Len`");
        }
    }
    _datetime_to_int("Shifts", "DateS");
    _datetime_to_int("Shifts", "DateE");
    sql_query("ALTER TABLE `Shifts` CHANGE `DateS` `start` INT NOT NULL, CHANGE `DateE` `end` INT NOT NULL");
    $applied = true;
}
if (sql_num_query("DESCRIBE `Shifts` `Man`") === 1 && sql_num_query("DESCRIBE `Shifts` `name`") === 0) {
    sql_query("ALTER TABLE `Shifts` CHANGE `Man` `name` VARCHAR(1024) NULL");
    $applied = true;
}
$res = sql_select("DESCRIBE `Shifts` `PSID`");
if ($res[0]['Type'] == 'text') {
    sql_query("ALTER TABLE `Shifts` CHANGE `PSID` `PSID` INT NULL");
    $applied = true;
}
_add_index("Shifts", array("PSID"), "UNIQUE");
_add_index("Shifts", array("RID"));
<?php

if (sql_num_query("SHOW TABLES LIKE 'NeededAngelTypes'") === 0) {
    sql_query("CREATE TABLE `NeededAngelTypes` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `room_id` int(11) DEFAULT NULL,\n                  `shift_id` int(11) DEFAULT NULL,\n                  `angel_type_id` int(11) NOT NULL,\n                  `count` int(11) NOT NULL,\n                  PRIMARY KEY (`id`),\n                  KEY `room_id` (`room_id`,`angel_type_id`),\n                  KEY `shift_id` (`shift_id`),\n                  KEY `angel_type_id` (`angel_type_id`)\n                )\n    ");
    $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;
}
if (sql_num_query("SELECT * FROM `ShiftEntry` WHERE `UID` = 0")) {
    $data = sql_query("\n        INSERT INTO `NeededAngelTypes` (`shift_id`, `angel_type_id`, `count`)\n            SELECT se.`SID`, se.`TID`, se.`count` FROM (\n                SELECT `SID`, `TID`, COUNT(`TID`) AS `count`\n                    FROM `ShiftEntry`\n                    GROUP BY `SID`, `TID`\n                ) AS se\n                INNER JOIN `Shifts` AS s ON s.`SID` = se.`SID`\n                INNER JOIN `Room` AS r ON s.`RID` = r.`RID`\n                LEFT JOIN `NeededAngelTypes` AS nat ON (nat.`room_id` = r.`RID` AND nat.`angel_type_id` = se.`TID`)\n                WHERE nat.`count` IS NULL OR nat.`count` != se.`count`\n    ");
    sql_query("DELETE FROM `ShiftEntry` WHERE `UID` = 0 AND `Comment` IS NULL");
    $applied = true;
}
_add_index("Room", array("Name"));
<?php

_add_index("ShiftFreeloader", array("UID"));
Exemple #4
0
function upgrade_1050()
{
    db_query_parsed(_add_index('log', 'domain_timestamp', 'domain,timestamp'));
}
Exemple #5
0
<?php

_datetime_to_int("Wecken", "Date");
_add_index("Wecken", array("UID"));
Exemple #6
0
<?php

if (sql_num_query("DESCRIBE `FAQ` `Sprache`") === 0 && sql_num_query("DESCRIBE `FAQ` `QID`") == 0) {
    sql_query("ALTER TABLE `FAQ`\n        ADD `Sprache` SET('de', 'en') NOT NULL,\n        ADD `QID` INT NOT NULL,\n        ADD INDEX(`Sprache`)");
    $res = sql_query("SELECT * FROM `FAQ` WHERE `Sprache` = ''");
    $i = 0;
    while ($row = mysql_fetch_assoc($res)) {
        $question = preg_split('#(?:<|&lt;)br(?:>|&gt;)#i', $row['Frage'], 2, PREG_SPLIT_NO_EMPTY);
        $answer = preg_split('#(?:<|&lt;)br(?:>|&gt;)#i', $row['Antwort'], 2, PREG_SPLIT_NO_EMPTY);
        if (count($question) == 2 && count($answer) == 2) {
            sql_query("INSERT INTO `FAQ` (`Frage`, `Antwort`, `Sprache`, `QID`) VALUES ('" . sql_escape(trim($question[1])) . "', '" . sql_escape(trim($answer[1])) . "', 'en', {$i})");
        }
        sql_query("UPDATE `FAQ` SET `Frage` = '" . sql_escape(trim($question[0])) . "', `Antwort` = '" . sql_escape(trim($answer[0])) . "', `Sprache` = 'de', `QID` = {$i} WHERE `FID` = " . $row['FID']);
        $i++;
    }
    _add_index('FAQ', array('QID', 'Sprache'), 'UNIQUE');
    $applied = true;
}
<?php

if (sql_num_query("DESCRIBE `Messages` `id`") === 0) {
    sql_query("ALTER TABLE `Messages`\n        DROP PRIMARY KEY,\n        ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST\n    ");
    $applied = true;
}
_add_index("Messages", array("SUID"));
_add_index("Messages", array("RUID"));
_datetime_to_int("Messages", "Datum");
_add_index("Messages", array("Datum"));
<?php

if (sql_num_query("DESCRIBE `ShiftEntry` `id`") === 0) {
    sql_query("ALTER TABLE `ShiftEntry` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
    $applied = true;
}
_add_index("ShiftEntry", array("SID"));
_add_index("ShiftEntry", array("TID"));
_add_index("ShiftEntry", array("UID"));
Exemple #9
0
<?php

_datetime_to_int("News", "Datum");
_add_index("News", array("UID"));
<?php

_add_index("news_comments", array("UID"));
<?php

_add_index("Questions", array("UID"));
_add_index("Questions", array("AID"));