]>
Commit | Line | Data |
---|---|---|
661135c7 | 1 | <?php |
87764a50 | 2 | set_include_path(get_include_path() . PATH_SEPARATOR . |
f03a795d | 3 | dirname(__FILE__) . "/include"); |
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 | ||
0ae2bb2a | 42 | <div class="floatingLogo"><img src="images/logo_wide.png"></div> |
661135c7 AD |
43 | |
44 | <h1><?php echo __("Database Updater") ?></h1> | |
45 | ||
46 | <?php | |
47 | function getline($fp, $delim) { | |
48 | $result = ""; | |
49 | while(!feof($fp)) { | |
50 | $tmp = fgetc($fp); | |
133ab8c7 | 51 | |
661135c7 AD |
52 | if($tmp == $delim) { |
53 | return $result; | |
54 | } | |
55 | $result .= $tmp; | |
56 | } | |
57 | return $result; | |
58 | } | |
133ab8c7 | 59 | |
661135c7 | 60 | $op = $_POST["op"]; |
133ab8c7 | 61 | |
661135c7 AD |
62 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); |
63 | $version = db_fetch_result($result, 0, "schema_version"); | |
133ab8c7 | 64 | |
661135c7 AD |
65 | $update_files = glob("schema/versions/".DB_TYPE."/*sql"); |
66 | $update_versions = array(); | |
133ab8c7 | 67 | |
661135c7 AD |
68 | foreach ($update_files as $f) { |
69 | $m = array(); | |
70 | preg_match_all("/schema\/versions\/".DB_TYPE."\/(\d*)\.sql/", $f, $m, | |
71 | PREG_PATTERN_ORDER); | |
133ab8c7 | 72 | |
661135c7 AD |
73 | if ($m[1][0]) { |
74 | $update_versions[$m[1][0]] = $f; | |
75 | } | |
76 | } | |
133ab8c7 | 77 | |
661135c7 | 78 | ksort($update_versions, SORT_NUMERIC); |
133ab8c7 | 79 | |
661135c7 AD |
80 | $latest_version = max(array_keys($update_versions)); |
81 | ||
82 | if ($version == $latest_version) { | |
83 | ||
84 | if ($version != SCHEMA_VERSION) { | |
85 | print_error(__("Could not update database")); | |
86 | ||
133ab8c7 | 87 | print "<p>" . |
661135c7 AD |
88 | __("Could not find necessary schema file, need version:") . |
89 | " " . SCHEMA_VERSION . __(", found: ") . $latest_version . "</p>"; | |
90 | ||
91 | } else { | |
6ef0c9c3 | 92 | print_notice(__("Tiny Tiny RSS database is up to date.")); |
107d0cf3 | 93 | print "<form method=\"GET\" action=\"index.php\"> |
661135c7 AD |
94 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> |
95 | </form>"; | |
96 | } | |
97 | ||
0ae2bb2a | 98 | } else if ($version <= $latest_version && !$op) { |
133ab8c7 | 99 | |
661135c7 | 100 | print_warning(__("Please backup your database before proceeding.")); |
133ab8c7 | 101 | |
661135c7 | 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>"; |
133ab8c7 | 103 | |
661135c7 | 104 | /* print "<p>Available incremental updates:"; |
133ab8c7 | 105 | |
661135c7 AD |
106 | foreach (array_keys($update_versions) as $v) { |
107 | if ($v > $version) { | |
108 | print " <a href='$update_versions[$v]'>$v</a>"; | |
109 | } | |
110 | } */ | |
133ab8c7 | 111 | |
661135c7 | 112 | print "</p>"; |
133ab8c7 | 113 | |
661135c7 AD |
114 | print "<form method='POST'> |
115 | <input type='hidden' name='op' value='do'> | |
116 | <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'> | |
117 | </form>"; | |
133ab8c7 | 118 | |
661135c7 | 119 | } else if ($op == "do") { |
133ab8c7 | 120 | |
661135c7 | 121 | print "<p>".__("Performing updates...")."</p>"; |
133ab8c7 | 122 | |
661135c7 | 123 | $num_updates = 0; |
133ab8c7 | 124 | |
661135c7 AD |
125 | foreach (array_keys($update_versions) as $v) { |
126 | if ($v == $version + 1) { | |
127 | print "<p>".T_sprintf("Updating to version %d...", $v)."</p>"; | |
87764a50 | 128 | db_query($link, "BEGIN"); |
661135c7 AD |
129 | $fp = fopen($update_versions[$v], "r"); |
130 | if ($fp) { | |
131 | while (!feof($fp)) { | |
132 | $query = trim(getline($fp, ";")); | |
133 | if ($query != "") { | |
134 | print "<p class='query'>$query</p>"; | |
135 | db_query($link, $query); | |
136 | } | |
137 | } | |
138 | } | |
139 | fclose($fp); | |
87764a50 | 140 | db_query($link, "COMMIT"); |
133ab8c7 | 141 | |
661135c7 | 142 | print "<p>".__("Checking version... "); |
133ab8c7 | 143 | |
661135c7 AD |
144 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); |
145 | $version = db_fetch_result($result, 0, "schema_version"); | |
133ab8c7 | 146 | |
661135c7 AD |
147 | if ($version == $v) { |
148 | print __("OK!"); | |
149 | } else { | |
150 | print "<b>".__("ERROR!")."</b>"; | |
151 | return; | |
152 | } | |
133ab8c7 | 153 | |
661135c7 AD |
154 | $num_updates++; |
155 | } | |
156 | } | |
133ab8c7 | 157 | |
661135c7 AD |
158 | print "<p>".T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema |
159 | version <b>%d</b>.", $num_updates, $version)."</p>"; | |
133ab8c7 | 160 | |
2376ad49 AD |
161 | print "<form method=\"GET\" action=\"backend.php\"> |
162 | <input type=\"hidden\" name=\"op\" value=\"logout\"> | |
661135c7 AD |
163 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> |
164 | </form>"; | |
165 | ||
0ae2bb2a AD |
166 | } else if ($version >= $latest_version) { |
167 | ||
168 | print_error(__("Your database schema is from a newer version of Tiny Tiny RSS.")); | |
169 | ||
170 | print "<p>" . T_sprintf("Found schema version: <b>%d</b>, required: <b>%d</b>.", $version, $latest_version) . "</p>"; | |
171 | ||
172 | print "<p>" . __("Schema upgrade impossible. Please update Tiny Tiny RSS files to the newer version and continue.") . "</p>"; | |
173 | ||
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")."\"> | |
177 | </form>"; | |
178 | ||
179 | ||
661135c7 | 180 | } |
133ab8c7 | 181 | |
661135c7 AD |
182 | ?> |
183 | ||
184 | </body> | |
185 | </html> | |
186 |