]>
Commit | Line | Data |
---|---|---|
661135c7 | 1 | <?php |
107d0cf3 AD |
2 | set_include_path(get_include_path() . PATH_SEPARATOR . "include"); |
3 | ||
fb074239 | 4 | require_once "functions.php"; |
661135c7 | 5 | require_once "sessions.php"; |
661135c7 | 6 | require_once "sanity_check.php"; |
661135c7 AD |
7 | require_once "config.php"; |
8 | require_once "db.php"; | |
661135c7 | 9 | |
133ab8c7 AD |
10 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
11 | ||
5f0a3741 | 12 | if (!init_connection($link)) return; |
661135c7 | 13 | login_sequence($link); |
133ab8c7 | 14 | |
661135c7 | 15 | $owner_uid = $_SESSION["uid"]; |
133ab8c7 AD |
16 | |
17 | if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { | |
661135c7 AD |
18 | $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); |
19 | render_login_form($link); | |
20 | exit; | |
21 | } | |
22 | ||
23 | ||
24 | ?> | |
25 | ||
26 | <html> | |
27 | <head> | |
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"> | |
31 | </head> | |
32 | ||
33 | <body> | |
34 | ||
35 | <script type='text/javascript'> | |
36 | function confirmOP() { | |
37 | return confirm(__("Update the database?")); | |
38 | } | |
39 | </script> | |
40 | ||
0ae2bb2a | 41 | <div class="floatingLogo"><img src="images/logo_wide.png"></div> |
661135c7 AD |
42 | |
43 | <h1><?php echo __("Database Updater") ?></h1> | |
44 | ||
45 | <?php | |
46 | function getline($fp, $delim) { | |
47 | $result = ""; | |
48 | while(!feof($fp)) { | |
49 | $tmp = fgetc($fp); | |
133ab8c7 | 50 | |
661135c7 AD |
51 | if($tmp == $delim) { |
52 | return $result; | |
53 | } | |
54 | $result .= $tmp; | |
55 | } | |
56 | return $result; | |
57 | } | |
133ab8c7 | 58 | |
661135c7 | 59 | $op = $_POST["op"]; |
133ab8c7 | 60 | |
661135c7 AD |
61 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); |
62 | $version = db_fetch_result($result, 0, "schema_version"); | |
133ab8c7 | 63 | |
661135c7 AD |
64 | $update_files = glob("schema/versions/".DB_TYPE."/*sql"); |
65 | $update_versions = array(); | |
133ab8c7 | 66 | |
661135c7 AD |
67 | foreach ($update_files as $f) { |
68 | $m = array(); | |
69 | preg_match_all("/schema\/versions\/".DB_TYPE."\/(\d*)\.sql/", $f, $m, | |
70 | PREG_PATTERN_ORDER); | |
133ab8c7 | 71 | |
661135c7 AD |
72 | if ($m[1][0]) { |
73 | $update_versions[$m[1][0]] = $f; | |
74 | } | |
75 | } | |
133ab8c7 | 76 | |
661135c7 | 77 | ksort($update_versions, SORT_NUMERIC); |
133ab8c7 | 78 | |
661135c7 AD |
79 | $latest_version = max(array_keys($update_versions)); |
80 | ||
81 | if ($version == $latest_version) { | |
82 | ||
83 | if ($version != SCHEMA_VERSION) { | |
84 | print_error(__("Could not update database")); | |
85 | ||
133ab8c7 | 86 | print "<p>" . |
661135c7 AD |
87 | __("Could not find necessary schema file, need version:") . |
88 | " " . SCHEMA_VERSION . __(", found: ") . $latest_version . "</p>"; | |
89 | ||
90 | } else { | |
6ef0c9c3 | 91 | print_notice(__("Tiny Tiny RSS database is up to date.")); |
107d0cf3 | 92 | print "<form method=\"GET\" action=\"index.php\"> |
661135c7 AD |
93 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> |
94 | </form>"; | |
95 | } | |
96 | ||
0ae2bb2a | 97 | } else if ($version <= $latest_version && !$op) { |
133ab8c7 | 98 | |
661135c7 | 99 | print_warning(__("Please backup your database before proceeding.")); |
133ab8c7 | 100 | |
661135c7 | 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>"; |
133ab8c7 | 102 | |
661135c7 | 103 | /* print "<p>Available incremental updates:"; |
133ab8c7 | 104 | |
661135c7 AD |
105 | foreach (array_keys($update_versions) as $v) { |
106 | if ($v > $version) { | |
107 | print " <a href='$update_versions[$v]'>$v</a>"; | |
108 | } | |
109 | } */ | |
133ab8c7 | 110 | |
661135c7 | 111 | print "</p>"; |
133ab8c7 | 112 | |
661135c7 AD |
113 | print "<form method='POST'> |
114 | <input type='hidden' name='op' value='do'> | |
115 | <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'> | |
116 | </form>"; | |
133ab8c7 | 117 | |
661135c7 | 118 | } else if ($op == "do") { |
133ab8c7 | 119 | |
661135c7 | 120 | print "<p>".__("Performing updates...")."</p>"; |
133ab8c7 | 121 | |
661135c7 | 122 | $num_updates = 0; |
133ab8c7 | 123 | |
661135c7 AD |
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"); | |
128 | if ($fp) { | |
129 | while (!feof($fp)) { | |
130 | $query = trim(getline($fp, ";")); | |
131 | if ($query != "") { | |
132 | print "<p class='query'>$query</p>"; | |
133 | db_query($link, $query); | |
134 | } | |
135 | } | |
136 | } | |
137 | fclose($fp); | |
133ab8c7 | 138 | |
661135c7 | 139 | print "<p>".__("Checking version... "); |
133ab8c7 | 140 | |
661135c7 AD |
141 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); |
142 | $version = db_fetch_result($result, 0, "schema_version"); | |
133ab8c7 | 143 | |
661135c7 AD |
144 | if ($version == $v) { |
145 | print __("OK!"); | |
146 | } else { | |
147 | print "<b>".__("ERROR!")."</b>"; | |
148 | return; | |
149 | } | |
133ab8c7 | 150 | |
661135c7 AD |
151 | $num_updates++; |
152 | } | |
153 | } | |
133ab8c7 | 154 | |
661135c7 AD |
155 | print "<p>".T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema |
156 | version <b>%d</b>.", $num_updates, $version)."</p>"; | |
133ab8c7 | 157 | |
2376ad49 AD |
158 | print "<form method=\"GET\" action=\"backend.php\"> |
159 | <input type=\"hidden\" name=\"op\" value=\"logout\"> | |
661135c7 AD |
160 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> |
161 | </form>"; | |
162 | ||
0ae2bb2a AD |
163 | } else if ($version >= $latest_version) { |
164 | ||
165 | print_error(__("Your database schema is from a newer version of Tiny Tiny RSS.")); | |
166 | ||
167 | print "<p>" . T_sprintf("Found schema version: <b>%d</b>, required: <b>%d</b>.", $version, $latest_version) . "</p>"; | |
168 | ||
169 | print "<p>" . __("Schema upgrade impossible. Please update Tiny Tiny RSS files to the newer version and continue.") . "</p>"; | |
170 | ||
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")."\"> | |
174 | </form>"; | |
175 | ||
176 | ||
661135c7 | 177 | } |
133ab8c7 | 178 | |
661135c7 AD |
179 | ?> |
180 | ||
181 | </body> | |
182 | </html> | |
183 |