2 error_reporting(E_ERROR | E_WARNING | E_PARSE
);
4 require_once "sessions.php";
6 require_once "sanity_check.php";
7 require_once "functions.php";
8 require_once "config.php";
11 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
13 if (DB_TYPE
== "pgsql") {
14 pg_query($link, "set client_encoding = 'utf-8'");
15 pg_set_client_encoding("UNICODE");
18 login_sequence($link);
20 $owner_uid = $_SESSION["uid"];
22 if (!SINGLE_USER_MODE
&& $_SESSION["access_level"] < 10) {
23 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
24 render_login_form($link);
28 define('SCHEMA_VERSION', 15);
34 <title
>Database Updater
</title
>
35 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
36 <link rel
="stylesheet" type
="text/css" href
="utility.css">
41 <script type
='text/javascript'>
42 function confirmOP() {
43 return confirm(__("Update the database?"));
47 <div
class="floatingLogo"><img src
="images/ttrss_logo.png"></div
>
49 <h1
><?php
echo __("Database Updater") ?
></h1
>
52 function getline($fp, $delim) {
67 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
68 $version = db_fetch_result($result, 0, "schema_version");
70 $update_files = glob("schema/versions/".DB_TYPE
."/*sql");
71 $update_versions = array();
73 foreach ($update_files as $f) {
75 preg_match_all("/schema\/versions\/".DB_TYPE
."\/(\d*)\.sql/", $f, $m,
79 $update_versions[$m[1][0]] = $f;
83 ksort($update_versions, SORT_NUMERIC
);
85 $latest_version = max(array_keys($update_versions));
87 if ($version == $latest_version) {
88 print "<p>".__("Tiny Tiny RSS database is up to date.")."</p>";
89 print "<form method=\"GET\" action=\"tt-rss.php\">
90 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
97 print "<p class='warning'>".__("<b>Warning:</b> Please backup your database before proceeding.")."</p>";
99 print "<p>" . T_sprintf("Your Tiny Tiny RSS database needs update to the latest version (<b>%d</b> to <b>%d</b>).", $version, $latest_version) . "</p>";
101 /* print "<p>Available incremental updates:";
103 foreach (array_keys($update_versions) as $v) {
105 print " <a href='$update_versions[$v]'>$v</a>";
111 print "<form method='POST'>
112 <input type='hidden' name='op' value='do'>
113 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
116 } else if ($op == "do") {
118 print "<p>".__("Performing updates...")."</p>";
122 foreach (array_keys($update_versions) as $v) {
123 if ($v == $version +
1) {
124 print "<p>".T_sprintf("Updating to version %d...", $v)."</p>";
125 $fp = fopen($update_versions[$v], "r");
128 $query = trim(getline($fp, ";"));
130 print "<p class='query'>$query</p>";
131 db_query($link, $query);
137 print "<p>".__("Checking version... ");
139 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
140 $version = db_fetch_result($result, 0, "schema_version");
142 if ($version == $v) {
145 print "<b>".__("ERROR!")."</b>";
153 print "<p>".T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema
154 version <b>%d</b>.", $num_updates, $version)."</p>";
156 print "<form method=\"GET\" action=\"logout.php\">
157 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">