]> git.wh0rd.org - tt-rss.git/blame - update.php
mysql: disable utf8
[tt-rss.git] / update.php
CommitLineData
fecd57c8 1<?php
d65981e2
AD
2 error_reporting(E_ERROR | E_WARNING | E_PARSE);
3
1559e374 4 require_once "sessions.php";
81596c66
AD
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");
70dcff6b 16 } else {
c1879099
AD
17// db_query($link, "SET NAMES utf8");
18// db_query($link, "SET CHARACTER SET utf8");
81596c66 19 }
70dcff6b 20
81596c66
AD
21 login_sequence($link);
22
23 $owner_uid = $_SESSION["uid"];
24
441acab8 25 if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
a190ebfd
AD
26 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
27 render_login_form($link);
01a87dff 28 exit;
81596c66 29 }
87b9fb65 30
fecd57c8
AD
31
32?>
33
34<html>
35<head>
b4c27af7
AD
36<title>Database Updater</title>
37<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
ef59e6e8 38<link rel="stylesheet" type="text/css" href="utility.css">
fecd57c8
AD
39</head>
40
41<body>
42
b4c27af7
AD
43<script type='text/javascript'>
44function confirmOP() {
06719138 45 return confirm(__("Update the database?"));
b4c27af7
AD
46}
47</script>
48
ef59e6e8
AD
49<div class="floatingLogo"><img src="images/ttrss_logo.png"></div>
50
06719138 51<h1><?php echo __("Database Updater") ?></h1>
fecd57c8
AD
52
53<?php
81596c66
AD
54 function getline($fp, $delim) {
55 $result = "";
56 while(!feof($fp)) {
57 $tmp = fgetc($fp);
58
59 if($tmp == $delim) {
60 return $result;
61 }
62 $result .= $tmp;
fecd57c8 63 }
81596c66 64 return $result;
fecd57c8 65 }
81596c66
AD
66
67 $op = $_POST["op"];
68
69 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
70 $version = db_fetch_result($result, 0, "schema_version");
71
72 $update_files = glob("schema/versions/".DB_TYPE."/*sql");
73 $update_versions = array();
74
75 foreach ($update_files as $f) {
76 $m = array();
77 preg_match_all("/schema\/versions\/".DB_TYPE."\/(\d*)\.sql/", $f, $m,
78 PREG_PATTERN_ORDER);
79
80 if ($m[1][0]) {
81 $update_versions[$m[1][0]] = $f;
fecd57c8 82 }
81596c66
AD
83 }
84
85 ksort($update_versions, SORT_NUMERIC);
86
87 $latest_version = max(array_keys($update_versions));
9e21a571 88
81596c66 89 if ($version == $latest_version) {
9e21a571
AD
90
91 if ($version != SCHEMA_VERSION) {
92 print_error(__("Could not update database"));
93
94 print "<p>" .
95 __("Could not find necessary schema file, need version:") .
96 " " . SCHEMA_VERSION . __(", found: ") . $latest_version . "</p>";
97
98 } else {
99 print "<p>".__("Tiny Tiny RSS database is up to date.")."</p>";
100 print "<form method=\"GET\" action=\"tt-rss.php\">
101 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
102 </form>";
103 }
ef59e6e8 104
81596c66
AD
105 return;
106 }
107
108 if (!$op) {
87b9fb65 109 print_warning("Please backup your database before proceeding.");
81596c66 110
06719138 111 print "<p>" . T_sprintf("Your Tiny Tiny RSS database needs update to the latest version (<b>%d</b> to <b>%d</b>).", $version, $latest_version) . "</p>";
81596c66
AD
112
113 /* print "<p>Available incremental updates:";
114
115 foreach (array_keys($update_versions) as $v) {
116 if ($v > $version) {
117 print " <a href='$update_versions[$v]'>$v</a>";
118 }
119 } */
120
121 print "</p>";
122
123 print "<form method='POST'>
124 <input type='hidden' name='op' value='do'>
06719138 125 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
81596c66
AD
126 </form>";
127
128 } else if ($op == "do") {
129
06719138 130 print "<p>".__("Performing updates...")."</p>";
81596c66
AD
131
132 $num_updates = 0;
133
134 foreach (array_keys($update_versions) as $v) {
135 if ($v == $version + 1) {
06719138 136 print "<p>".T_sprintf("Updating to version %d...", $v)."</p>";
81596c66
AD
137 $fp = fopen($update_versions[$v], "r");
138 if ($fp) {
139 while (!feof($fp)) {
140 $query = trim(getline($fp, ";"));
141 if ($query != "") {
06719138 142 print "<p class='query'>$query</p>";
81596c66
AD
143 db_query($link, $query);
144 }
fecd57c8
AD
145 }
146 }
81596c66
AD
147 fclose($fp);
148
06719138 149 print "<p>".__("Checking version... ");
81596c66
AD
150
151 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
152 $version = db_fetch_result($result, 0, "schema_version");
153
154 if ($version == $v) {
06719138 155 print __("OK!");
81596c66 156 } else {
06719138 157 print "<b>".__("ERROR!")."</b>";
81596c66
AD
158 return;
159 }
160
161 $num_updates++;
b4c27af7 162 }
b4c27af7 163 }
81596c66 164
06719138
AD
165 print "<p>".T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema
166 version <b>%d</b>.", $num_updates, $version)."</p>";
81596c66 167
07a2b314 168 print "<form method=\"GET\" action=\"logout.php\">
06719138 169 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
ef59e6e8
AD
170 </form>";
171
fecd57c8 172 }
81596c66 173
fecd57c8
AD
174?>
175
fecd57c8
AD
176</body>
177</html>
178