summaryrefslogtreecommitdiff
path: root/db/update.d
diff options
context:
space:
mode:
authorJan-Philipp Litza <janphilipp@litza.de>2012-04-26 19:18:17 +0200
committerJan-Philipp Litza <janphilipp@litza.de>2012-04-26 19:18:17 +0200
commit34582524ba39e895e072129b1c83e48d94864cff (patch)
tree15858aef085c7edda685ead3086b6350e6d1fcc7 /db/update.d
parent0ce217e3ebe2a304d7bcb465622d7165ff90c235 (diff)
adapted admin section for FAQ to new database scheme
Diffstat (limited to 'db/update.d')
-rw-r--r--db/update.d/01_faq.php14
1 files changed, 9 insertions, 5 deletions
diff --git a/db/update.d/01_faq.php b/db/update.d/01_faq.php
index 1e32f1ad..759cc109 100644
--- a/db/update.d/01_faq.php
+++ b/db/update.d/01_faq.php
@@ -1,16 +1,20 @@
<?php
-if(sql_num_query("DESCRIBE `FAQ` `Sprache`") === 0) {
+if(sql_num_query("DESCRIBE `FAQ` `Sprache`") === 0 && sql_num_query("DESCRIBE `FAQ` `QID`") == 0) {
sql_query("ALTER TABLE `FAQ`
ADD `Sprache` SET('de', 'en') NOT NULL,
+ ADD `QID` INT NOT NULL,
ADD INDEX(`Sprache`)");
$res = sql_query("SELECT * FROM `FAQ` WHERE `Sprache` = ''");
+ $i = 0;
while($row = mysql_fetch_assoc($res)) {
- $question = explode('<br>', $row['Frage'], 2);
- $answer = explode('<br>', $row['Antwort'], 2);
+ $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`) VALUES ('" . sql_escape(trim($question[1])) . "', '" . sql_escape(trim($answer[1])) . "', 'en')");
- sql_query("UPDATE `FAQ` SET `Frage` = '" . sql_escape(trim($question[0])) . "', `Antwort` = '" . sql_escape(trim($answer[0])) . "', `Sprache` = 'de' WHERE `FID` = " . $row['FID']);
+ 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;
}