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