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");
17 db_query($link, "SET NAMES utf8");
18 db_query($link, "SET CHARACTER SET utf8");
21 login_sequence($link);
23 $owner_uid = $_SESSION["uid"];
25 if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
26 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
27 render_login_form($link);
36 <title>Database Updater</title>
37 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
38 <link rel="stylesheet" type="text/css" href="utility.css">
43 <script type='text/javascript'>
44 function confirmOP() {
45 return confirm(__("Update the database?"));
49 <div class="floatingLogo"><img src="images/ttrss_logo.png"></div>
51 <h1><?php echo __("Database Updater") ?></h1>
54 function getline($fp, $delim) {
69 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
70 $version = db_fetch_result($result, 0, "schema_version");
72 $update_files = glob("schema/versions/".DB_TYPE."/*sql");
73 $update_versions = array();
75 foreach ($update_files as $f) {
77 preg_match_all("/schema\/versions\/".DB_TYPE."\/(\d*)\.sql/", $f, $m,
81 $update_versions[$m[1][0]] = $f;
85 ksort($update_versions, SORT_NUMERIC);
87 $latest_version = max(array_keys($update_versions));
89 if ($version == $latest_version) {
91 if ($version != SCHEMA_VERSION) {
92 print_error(__("Could not update database"));
95 __("Could not find necessary schema file, need version:") .
96 " " . SCHEMA_VERSION . __(", found: ") . $latest_version . "</p>";
99 print "<p>".__("Tiny Tiny RSS database is up to date.")."</p>";
100 print "<form method=\"GET\" action=\"tt-rss.php\">
101 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
109 print_warning("Please backup your database before proceeding.");
111 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>";
113 /* print "<p>Available incremental updates:";
115 foreach (array_keys($update_versions) as $v) {
117 print " <a href='$update_versions[$v]'>$v</a>";
123 print "<form method='POST'>
124 <input type='hidden' name='op' value='do'>
125 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
128 } else if ($op == "do") {
130 print "<p>".__("Performing updates...")."</p>";
134 foreach (array_keys($update_versions) as $v) {
135 if ($v == $version + 1) {
136 print "<p>".T_sprintf("Updating to version %d...", $v)."</p>";
137 $fp = fopen($update_versions[$v], "r");
140 $query = trim(getline($fp, ";"));
142 print "<p class='query'>$query</p>";
143 db_query($link, $query);
149 print "<p>".__("Checking version... ");
151 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
152 $version = db_fetch_result($result, 0, "schema_version");
154 if ($version == $v) {
157 print "<b>".__("ERROR!")."</b>";
165 print "<p>".T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema
166 version <b>%d</b>.", $num_updates, $version)."</p>";
168 print "<form method=\"GET\" action=\"logout.php\">
169 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">