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 if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
18 db_query($link, "SET NAMES " . MYSQL_CHARSET);
19 // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
23 login_sequence($link);
25 $owner_uid = $_SESSION["uid"];
27 if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
28 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
29 render_login_form($link);
38 <title>Database Updater</title>
39 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
40 <link rel="stylesheet" type="text/css" href="utility.css">
45 <script type='text/javascript'>
46 function confirmOP() {
47 return confirm(__("Update the database?"));
51 <div class="floatingLogo"><img src="images/ttrss_logo.png"></div>
53 <h1><?php echo __("Database Updater") ?></h1>
56 function getline($fp, $delim) {
71 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
72 $version = db_fetch_result($result, 0, "schema_version");
74 $update_files = glob("schema/versions/".DB_TYPE."/*sql");
75 $update_versions = array();
77 foreach ($update_files as $f) {
79 preg_match_all("/schema\/versions\/".DB_TYPE."\/(\d*)\.sql/", $f, $m,
83 $update_versions[$m[1][0]] = $f;
87 ksort($update_versions, SORT_NUMERIC);
89 $latest_version = max(array_keys($update_versions));
91 if ($version == $latest_version) {
93 if ($version != SCHEMA_VERSION) {
94 print_error(__("Could not update database"));
97 __("Could not find necessary schema file, need version:") .
98 " " . SCHEMA_VERSION . __(", found: ") . $latest_version . "</p>";
101 print "<p>".__("Tiny Tiny RSS database is up to date.")."</p>";
102 print "<form method=\"GET\" action=\"tt-rss.php\">
103 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
111 print_warning(__("Please backup your database before proceeding."));
113 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>";
115 /* print "<p>Available incremental updates:";
117 foreach (array_keys($update_versions) as $v) {
119 print " <a href='$update_versions[$v]'>$v</a>";
125 print "<form method='POST'>
126 <input type='hidden' name='op' value='do'>
127 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
130 } else if ($op == "do") {
132 print "<p>".__("Performing updates...")."</p>";
136 foreach (array_keys($update_versions) as $v) {
137 if ($v == $version + 1) {
138 print "<p>".T_sprintf("Updating to version %d...", $v)."</p>";
139 $fp = fopen($update_versions[$v], "r");
142 $query = trim(getline($fp, ";"));
144 print "<p class='query'>$query</p>";
145 db_query($link, $query);
151 print "<p>".__("Checking version... ");
153 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
154 $version = db_fetch_result($result, 0, "schema_version");
156 if ($version == $v) {
159 print "<b>".__("ERROR!")."</b>";
167 print "<p>".T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema
168 version <b>%d</b>.", $num_updates, $version)."</p>";
170 print "<form method=\"GET\" action=\"logout.php\">
171 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">