]>
git.wh0rd.org - tt-rss.git/blob - db-updater.php
2 set_include_path(get_include_path() . PATH_SEPARATOR
. "include");
4 require_once "functions.php";
5 require_once "sessions.php";
6 require_once "sanity_check.php";
7 require_once "config.php";
10 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
12 init_connection($link);
13 login_sequence($link);
15 $owner_uid = $_SESSION["uid"];
17 if (!SINGLE_USER_MODE
&& $_SESSION["access_level"] < 10) {
18 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
19 render_login_form($link);
28 <title
>Database Updater
</title
>
29 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
30 <link rel
="stylesheet" type
="text/css" href
="utility.css">
35 <script type
='text/javascript'>
36 function confirmOP() {
37 return confirm(__("Update the database?"));
41 <div
class="floatingLogo"><img src
="images/logo_wide.png"></div
>
43 <h1
><?php
echo __("Database Updater") ?
></h1
>
46 function getline($fp, $delim) {
61 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
62 $version = db_fetch_result($result, 0, "schema_version");
64 $update_files = glob("schema/versions/".DB_TYPE
."/*sql");
65 $update_versions = array();
67 foreach ($update_files as $f) {
69 preg_match_all("/schema\/versions\/".DB_TYPE
."\/(\d*)\.sql/", $f, $m,
73 $update_versions[$m[1][0]] = $f;
77 ksort($update_versions, SORT_NUMERIC
);
79 $latest_version = max(array_keys($update_versions));
81 if ($version == $latest_version) {
83 if ($version != SCHEMA_VERSION
) {
84 print_error(__("Could not update database"));
87 __("Could not find necessary schema file, need version:") .
88 " " . SCHEMA_VERSION
. __(", found: ") . $latest_version . "</p>";
91 print_notice(__("Tiny Tiny RSS database is up to date."));
92 print "<form method=\"GET\" action=\"index.php\">
93 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
97 } else if ($version <= $latest_version && !$op) {
99 print_warning(__("Please backup your database before proceeding."));
101 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>";
103 /* print "<p>Available incremental updates:";
105 foreach (array_keys($update_versions) as $v) {
107 print " <a href='$update_versions[$v]'>$v</a>";
113 print "<form method='POST'>
114 <input type='hidden' name='op' value='do'>
115 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
118 } else if ($op == "do") {
120 print "<p>".__("Performing updates...")."</p>";
124 foreach (array_keys($update_versions) as $v) {
125 if ($v == $version +
1) {
126 print "<p>".T_sprintf("Updating to version %d...", $v)."</p>";
127 $fp = fopen($update_versions[$v], "r");
130 $query = trim(getline($fp, ";"));
132 print "<p class='query'>$query</p>";
133 db_query($link, $query);
139 print "<p>".__("Checking version... ");
141 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
142 $version = db_fetch_result($result, 0, "schema_version");
144 if ($version == $v) {
147 print "<b>".__("ERROR!")."</b>";
155 print "<p>".T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema
156 version <b>%d</b>.", $num_updates, $version)."</p>";
158 print "<form method=\"GET\" action=\"backend.php\">
159 <input type=\"hidden\" name=\"op\" value=\"logout\">
160 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
163 } else if ($version >= $latest_version) {
165 print_error(__("Your database schema is from a newer version of Tiny Tiny RSS."));
167 print "<p>" . T_sprintf("Found schema version: <b>%d</b>, required: <b>%d</b>.", $version, $latest_version) . "</p>";
169 print "<p>" . __("Schema upgrade impossible. Please update Tiny Tiny RSS files to the newer version and continue.") . "</p>";
171 print "<form method=\"GET\" action=\"backend.php\">
172 <input type=\"hidden\" name=\"op\" value=\"logout\">
173 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">