]>
git.wh0rd.org - tt-rss.git/blob - update.php
964626d7fa9dd2f02076cb9b733b68d9922336de
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 <h1
>Database Updater
</h1
>
40 function getline($fp, $delim) {
53 $op = $_REQUEST["op"];
55 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
56 $version = db_fetch_result($result, 0, "schema_version");
58 $update_files = glob("schema/versions/".DB_TYPE
."/*sql");
59 $update_versions = array();
61 foreach ($update_files as $f) {
63 preg_match_all("/schema\/versions\/".DB_TYPE
."\/(\d*)\.sql/", $f, $m,
67 $update_versions[$m[1][0]] = $f;
71 ksort($update_versions, SORT_NUMERIC
);
73 $latest_version = max(array_keys($update_versions));
75 if ($version == $latest_version) {
76 print "Database schema is up to date (version $version).";
81 print "<p class='warning'><b>Warning:</b> Please backup your database before proceeding.</p>";
83 print "<p>Your database schema version is $version. Latest version is ".
84 "$latest_version.</p>";
86 print "<p>Available incremental updates:";
88 foreach (array_keys($update_versions) as $v) {
90 print " <a href='$update_versions[$v]'>$v</a>";
95 print "<a href='update.php?op=do'>Click here to perform updates.</a>";
97 } else if ($op == "do") {
99 print "<p>Performing updates (version: $version)...</p>";
103 foreach (array_keys($update_versions) as $v) {
104 if ($v == $version +
1) {
105 print "<p>Updating to version $v...</p>";
106 $fp = fopen($update_versions[$v], "r");
109 $query = trim(getline($fp, ";"));
111 print "<p class='query'><b>QUERY:</b> $query</p>";
112 db_query($link, $query);
118 print "<p>Checking version... ";
120 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
121 $version = db_fetch_result($result, 0, "schema_version");
123 if ($version == $v) {
126 print "<b>ERROR!</b>";
134 print "<p>Finished. Performed $num_updates updates up to schema
135 version $version.</p>";