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);
33 <title
>Database Updater
</title
>
34 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
35 <link rel
="stylesheet" type
="text/css" href
="utility.css">
40 <script type
='text/javascript'>
41 function confirmOP() {
42 return confirm(__("Update the database?"));
46 <div
class="floatingLogo"><img src
="images/ttrss_logo.png"></div
>
48 <h1
><?php
echo __("Database Updater") ?
></h1
>
51 function getline($fp, $delim) {
66 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
67 $version = db_fetch_result($result, 0, "schema_version");
69 $update_files = glob("schema/versions/".DB_TYPE
."/*sql");
70 $update_versions = array();
72 foreach ($update_files as $f) {
74 preg_match_all("/schema\/versions\/".DB_TYPE
."\/(\d*)\.sql/", $f, $m,
78 $update_versions[$m[1][0]] = $f;
82 ksort($update_versions, SORT_NUMERIC
);
84 $latest_version = max(array_keys($update_versions));
86 if ($version == $latest_version) {
88 if ($version != SCHEMA_VERSION
) {
89 print_error(__("Could not update database"));
92 __("Could not find necessary schema file, need version:") .
93 " " . SCHEMA_VERSION
. __(", found: ") . $latest_version . "</p>";
96 print "<p>".__("Tiny Tiny RSS database is up to date.")."</p>";
97 print "<form method=\"GET\" action=\"tt-rss.php\">
98 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
106 print_warning("Please backup your database before proceeding.");
108 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>";
110 /* print "<p>Available incremental updates:";
112 foreach (array_keys($update_versions) as $v) {
114 print " <a href='$update_versions[$v]'>$v</a>";
120 print "<form method='POST'>
121 <input type='hidden' name='op' value='do'>
122 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
125 } else if ($op == "do") {
127 print "<p>".__("Performing updates...")."</p>";
131 foreach (array_keys($update_versions) as $v) {
132 if ($v == $version +
1) {
133 print "<p>".T_sprintf("Updating to version %d...", $v)."</p>";
134 $fp = fopen($update_versions[$v], "r");
137 $query = trim(getline($fp, ";"));
139 print "<p class='query'>$query</p>";
140 db_query($link, $query);
146 print "<p>".__("Checking version... ");
148 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
149 $version = db_fetch_result($result, 0, "schema_version");
151 if ($version == $v) {
154 print "<b>".__("ERROR!")."</b>";
162 print "<p>".T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema
163 version <b>%d</b>.", $num_updates, $version)."</p>";
165 print "<form method=\"GET\" action=\"logout.php\">
166 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">