]>
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 header("Location: login.php"); die;
24 define('SCHEMA_VERSION', 13);
30 <title
>Database Updater
</title
>
31 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
32 <link rel
="stylesheet" type
="text/css" href
="update.css">
37 <script type
='text/javascript'>
38 function confirmOP() {
39 return confirm("Update the database?");
43 <h1
>Database Updater
</h1
>
46 function getline($fp, $delim) {
61 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
62 $version = db_fetch_result($result, 0, "schema_version");
64 $update_files = glob("schema/versions/".DB_TYPE
."/*sql");
65 $update_versions = array();
67 foreach ($update_files as $f) {
69 preg_match_all("/schema\/versions\/".DB_TYPE
."\/(\d*)\.sql/", $f, $m,
73 $update_versions[$m[1][0]] = $f;
77 ksort($update_versions, SORT_NUMERIC
);
79 $latest_version = max(array_keys($update_versions));
81 if ($version == $latest_version) {
82 print "<p>Tiny Tiny RSS database is up to date (version $version).</p>";
83 print "<p><a href='tt-rss.php'>Return to Tiny Tiny RSS</a></p>";
88 print "<p class='warning'><b>Warning:</b> Please backup your database before proceeding.</p>";
90 print "<p>Your Tiny Tiny RSS database needs update to the latest
91 version ($version —> $latest_version).</p>";
93 /* print "<p>Available incremental updates:";
95 foreach (array_keys($update_versions) as $v) {
97 print " <a href='$update_versions[$v]'>$v</a>";
103 print "<form method='POST'>
104 <input type='hidden' name='op' value='do'>
105 <input type='submit' onclick='return confirmOP()' value='Perform updates'>
108 } else if ($op == "do") {
110 print "<p>Performing updates (from version $version)...</p>";
114 foreach (array_keys($update_versions) as $v) {
115 if ($v == $version +
1) {
116 print "<p>Updating to version $v...</p>";
117 $fp = fopen($update_versions[$v], "r");
120 $query = trim(getline($fp, ";"));
122 print "<p class='query'><b>QUERY:</b> $query</p>";
123 db_query($link, $query);
129 print "<p>Checking version... ";
131 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
132 $version = db_fetch_result($result, 0, "schema_version");
134 if ($version == $v) {
135 print "OK! ($version)";
137 print "<b>ERROR!</b>";
145 print "<p>Finished. Performed $num_updates updates up to schema
146 version $version.</p>";
148 print "<p><a href='tt-rss.php'>Return to Tiny Tiny RSS</a></p>";