]>
git.wh0rd.org - tt-rss.git/blob - db-updater.php
2 set_include_path(dirname(__FILE__
) ."/include" . PATH_SEPARATOR
.
5 require_once "functions.php";
6 require_once "sessions.php";
7 require_once "sanity_check.php";
8 require_once "config.php";
11 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
13 if (!init_connection($link)) return;
14 login_sequence($link);
16 $owner_uid = $_SESSION["uid"];
18 if (!SINGLE_USER_MODE
&& $_SESSION["access_level"] < 10) {
19 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
20 render_login_form($link);
29 <title
>Database Updater
</title
>
30 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
31 <link rel
="stylesheet" type
="text/css" href
="utility.css">
36 <script type
='text/javascript'>
37 function confirmOP() {
38 return confirm(__("Update the database?"));
42 <div
class="floatingLogo"><img src
="images/logo_wide.png"></div
>
44 <h1
><?php
echo __("Database Updater") ?
></h1
>
47 function getline($fp, $delim) {
62 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
63 $version = db_fetch_result($result, 0, "schema_version");
65 $update_files = glob("schema/versions/".DB_TYPE
."/*sql");
66 $update_versions = array();
68 foreach ($update_files as $f) {
70 preg_match_all("/schema\/versions\/".DB_TYPE
."\/(\d*)\.sql/", $f, $m,
74 $update_versions[$m[1][0]] = $f;
78 ksort($update_versions, SORT_NUMERIC
);
80 $latest_version = max(array_keys($update_versions));
82 if ($version == $latest_version) {
84 if ($version != SCHEMA_VERSION
) {
85 print_error(__("Could not update database"));
88 __("Could not find necessary schema file, need version:") .
89 " " . SCHEMA_VERSION
. __(", found: ") . $latest_version . "</p>";
92 print_notice(__("Tiny Tiny RSS database is up to date."));
93 print "<form method=\"GET\" action=\"index.php\">
94 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
98 } else if ($version <= $latest_version && !$op) {
100 print_warning(__("Please backup your database before proceeding."));
102 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>";
104 /* print "<p>Available incremental updates:";
106 foreach (array_keys($update_versions) as $v) {
108 print " <a href='$update_versions[$v]'>$v</a>";
114 print "<form method='POST'>
115 <input type='hidden' name='op' value='do'>
116 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
119 } else if ($op == "do") {
121 print "<p>".__("Performing updates...")."</p>";
125 foreach (array_keys($update_versions) as $v) {
126 if ($v == $version +
1) {
127 print "<p>".T_sprintf("Updating to version %d...", $v)."</p>";
128 db_query($link, "BEGIN");
129 $fp = fopen($update_versions[$v], "r");
132 $query = trim(getline($fp, ";"));
134 print "<p class='query'>$query</p>";
135 db_query($link, $query);
140 db_query($link, "COMMIT");
142 print "<p>".__("Checking version... ");
144 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
145 $version = db_fetch_result($result, 0, "schema_version");
147 if ($version == $v) {
150 print "<b>".__("ERROR!")."</b>";
158 print "<p>".T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema
159 version <b>%d</b>.", $num_updates, $version)."</p>";
161 print "<form method=\"GET\" action=\"backend.php\">
162 <input type=\"hidden\" name=\"op\" value=\"logout\">
163 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
166 } else if ($version >= $latest_version) {
168 print_error(__("Your database schema is from a newer version of Tiny Tiny RSS."));
170 print "<p>" . T_sprintf("Found schema version: <b>%d</b>, required: <b>%d</b>.", $version, $latest_version) . "</p>";
172 print "<p>" . __("Schema upgrade impossible. Please update Tiny Tiny RSS files to the newer version and continue.") . "</p>";
174 print "<form method=\"GET\" action=\"backend.php\">
175 <input type=\"hidden\" name=\"op\" value=\"logout\">
176 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">