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