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