]>
git.wh0rd.org - tt-rss.git/blob - update.php
eb5cf94f5383509ae0ecaf7d610a779a055e3635
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
="update.css">
38 <script type
='text/javascript'>
39 function confirmOP() {
40 return confirm("Update the database?");
44 <h1
>Database Updater
</h1
>
47 function getline($fp, $delim) {
62 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
63 $version = db_fetch_result($result, 0, "schema_version");
65 $update_files = glob("schema/versions/".DB_TYPE
."/*sql");
66 $update_versions = array();
68 foreach ($update_files as $f) {
70 preg_match_all("/schema\/versions\/".DB_TYPE
."\/(\d*)\.sql/", $f, $m,
74 $update_versions[$m[1][0]] = $f;
78 ksort($update_versions, SORT_NUMERIC
);
80 $latest_version = max(array_keys($update_versions));
82 if ($version == $latest_version) {
83 print "<p>Tiny Tiny RSS database is up to date (version $version).</p>";
84 print "<p><a href='tt-rss.php'>Return to Tiny Tiny RSS</a></p>";
89 print "<p class='warning'><b>Warning:</b> Please backup your database before proceeding.</p>";
91 print "<p>Your Tiny Tiny RSS database needs update to the latest
92 version ($version —> $latest_version).</p>";
94 /* print "<p>Available incremental updates:";
96 foreach (array_keys($update_versions) as $v) {
98 print " <a href='$update_versions[$v]'>$v</a>";
104 print "<form method='POST'>
105 <input type='hidden' name='op' value='do'>
106 <input type='submit' onclick='return confirmOP()' value='Perform updates'>
109 } else if ($op == "do") {
111 print "<p>Performing updates (from version $version)...</p>";
115 foreach (array_keys($update_versions) as $v) {
116 if ($v == $version +
1) {
117 print "<p>Updating to version $v...</p>";
118 $fp = fopen($update_versions[$v], "r");
121 $query = trim(getline($fp, ";"));
123 print "<p class='query'><b>QUERY:</b> $query</p>";
124 db_query($link, $query);
130 print "<p>Checking version... ";
132 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
133 $version = db_fetch_result($result, 0, "schema_version");
135 if ($version == $v) {
136 print "OK! ($version)";
138 print "<b>ERROR!</b>";
146 print "<p>Finished. Performed $num_updates updates up to schema
147 version $version.</p>";
149 print "<p><a href='tt-rss.php'>Return to Tiny Tiny RSS</a></p>";