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