]>
Commit | Line | Data |
---|---|---|
75ca1986 AD |
1 | <?php |
2 | error_reporting(E_ERROR | E_WARNING | E_PARSE); | |
3 | ||
4 | require_once "sessions.php"; | |
5 | ||
6 | require_once "sanity_check.php"; | |
7 | require_once "functions.php"; | |
8 | require_once "config.php"; | |
9 | require_once "db.php"; | |
10 | ||
11 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
12 | ||
13 | if (DB_TYPE == "pgsql") { | |
14 | pg_query($link, "set client_encoding = 'utf-8'"); | |
15 | pg_set_client_encoding("UNICODE"); | |
16 | } else { | |
17 | if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { | |
18 | db_query($link, "SET NAMES " . MYSQL_CHARSET); | |
19 | // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET); | |
20 | } | |
21 | } | |
22 | ||
23 | login_sequence($link); | |
24 | ||
25 | $owner_uid = $_SESSION["uid"]; | |
26 | ||
27 | if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { | |
28 | $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); | |
29 | render_login_form($link); | |
30 | exit; | |
31 | } | |
32 | ||
33 | ||
34 | ?> | |
35 | ||
36 | <html> | |
37 | <head> | |
38 | <title>MySQL Charset Converter</title> | |
39 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
40 | <link rel="stylesheet" type="text/css" href="utility.css"> | |
41 | <script type="text/javascript" src="localized_js.php"></script> | |
42 | </head> | |
43 | ||
44 | <body> | |
45 | ||
46 | <script type='text/javascript'> | |
47 | function confirmOP() { | |
48 | return confirm(__("Update the database?")); | |
49 | } | |
50 | </script> | |
51 | ||
52 | <div class="floatingLogo"><img src="images/ttrss_logo.png"></div> | |
53 | ||
54 | <h1><?php echo __("MySQL Charset Updater") ?></h1> | |
55 | ||
56 | <?php | |
57 | ||
58 | $op = $_POST["op"]; | |
59 | ||
60 | if (DB_TYPE != "mysql") { | |
61 | print_warning(__("This script is for Tiny Tiny RSS installations with MySQL backend only.")); | |
62 | ||
63 | print "<form method=\"GET\" action=\"logout.php\"> | |
64 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
65 | </form>"; | |
66 | ||
67 | } else if (!$op) { | |
68 | ||
69 | print_warning(__("Please backup your database before proceeding.")); | |
70 | ||
71 | print "<p>" . __("This script will convert your Tiny Tiny RSS database to UTF-8. | |
72 | Depending on current database charset you may experience data corruption (lost accent characters, etc.). | |
73 | After update, you'll have to set <b>MYSQL_CHARSET</b> option in config.php to 'utf8'.") . "</p>"; | |
74 | ||
75 | print "<form method='POST'> | |
76 | <input type='hidden' name='op' value='do'> | |
77 | <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'> | |
78 | </form>"; | |
79 | ||
80 | } else if ($op == "do") { | |
81 | ||
82 | print "<p>".__("Converting database...")."</p>"; | |
83 | ||
1a25307a | 84 | db_query($link, "BEGIN"); |
75ca1986 AD |
85 | db_query($link, "SET FOREIGN_KEY_CHECKS=0"); |
86 | ||
87 | $result = db_query($link, "SHOW TABLES LIKE 'ttrss%'"); | |
88 | ||
89 | while ($line = db_fetch_assoc($result)) { | |
90 | $vals = array_values($line); | |
91 | $table = $vals[0]; | |
92 | ||
93 | $query = "ALTER TABLE $table CONVERT TO | |
94 | CHARACTER SET 'utf8'"; | |
95 | ||
96 | print "<p class='query'>$query</p>"; | |
97 | ||
98 | db_query($link, $query); | |
99 | } | |
100 | ||
101 | db_query($link, "SET FOREIGN_KEY_CHECKS=1"); | |
1a25307a | 102 | db_query($link, "COMMIT"); |
75ca1986 AD |
103 | |
104 | print "<form method=\"GET\" action=\"logout.php\"> | |
105 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
106 | </form>"; | |
107 | ||
108 | } | |
109 | ||
110 | ?> | |
111 | ||
112 | </body> | |
113 | </html> | |
114 |