]>
git.wh0rd.org - tt-rss.git/blob - update.php
2 require_once "sessions.php";
4 require_once "sanity_check.php";
5 require_once "functions.php";
6 require_once "config.php";
9 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
11 if (DB_TYPE
== "pgsql") {
12 pg_query($link, "set client_encoding = 'utf-8'");
13 pg_set_client_encoding("UNICODE");
16 login_sequence($link);
18 $owner_uid = $_SESSION["uid"];
20 if ($_SESSION["access_level"] < 10) {
21 print "<p>Error: your access level is insufficient to run this script.</p>";
25 define('SCHEMA_VERSION', 13);
31 <title
>Database Updater
</title
>
32 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
33 <link rel
="stylesheet" type
="text/css" href
="utility.css">
38 <script type
='text/javascript'>
39 function confirmOP() {
40 return confirm("Update the database?");
44 <div
class="floatingLogo"><img src
="images/ttrss_logo.png"></div
>
46 <h1
>Database Updater
</h1
>
49 function getline($fp, $delim) {
64 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
65 $version = db_fetch_result($result, 0, "schema_version");
67 $update_files = glob("schema/versions/".DB_TYPE
."/*sql");
68 $update_versions = array();
70 foreach ($update_files as $f) {
72 preg_match_all("/schema\/versions\/".DB_TYPE
."\/(\d*)\.sql/", $f, $m,
76 $update_versions[$m[1][0]] = $f;
80 ksort($update_versions, SORT_NUMERIC
);
82 $latest_version = max(array_keys($update_versions));
84 if ($version == $latest_version) {
85 print "<p>Tiny Tiny RSS database is up to date (version $version).</p>";
86 print "<form method=\"GET\" action=\"tt-rss.php\">
87 <input type=\"submit\" value=\"Return to Tiny Tiny RSS\">
94 print "<p class='warning'><b>Warning:</b> Please backup your database before proceeding.</p>";
96 print "<p>Your Tiny Tiny RSS database needs update to the latest
97 version ($version —> $latest_version).</p>";
99 /* print "<p>Available incremental updates:";
101 foreach (array_keys($update_versions) as $v) {
103 print " <a href='$update_versions[$v]'>$v</a>";
109 print "<form method='POST'>
110 <input type='hidden' name='op' value='do'>
111 <input type='submit' onclick='return confirmOP()' value='Perform updates'>
114 } else if ($op == "do") {
116 print "<p>Performing updates (from version $version)...</p>";
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");
126 $query = trim(getline($fp, ";"));
128 print "<p class='query'><b>QUERY:</b> $query</p>";
129 db_query($link, $query);
135 print "<p>Checking version... ";
137 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
138 $version = db_fetch_result($result, 0, "schema_version");
140 if ($version == $v) {
141 print "OK! ($version)";
143 print "<b>ERROR!</b>";
151 print "<p>Finished. Performed $num_updates updates up to schema
152 version $version.</p>";
154 print "<form method=\"GET\" action=\"tt-rss.php\">
155 <input type=\"submit\" value=\"Return to Tiny Tiny RSS\">