]>
Commit | Line | Data |
---|---|---|
fecd57c8 | 1 | <?php |
d65981e2 AD |
2 | error_reporting(E_ERROR | E_WARNING | E_PARSE); |
3 | ||
1559e374 | 4 | require_once "sessions.php"; |
81596c66 AD |
5 | |
6 | require_once "sanity_check.php"; | |
7 | require_once "functions.php"; | |
8 | require_once "config.php"; | |
9 | require_once "db.php"; | |
10 | ||
11 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
12 | ||
13 | if (DB_TYPE == "pgsql") { | |
14 | pg_query($link, "set client_encoding = 'utf-8'"); | |
15 | pg_set_client_encoding("UNICODE"); | |
70dcff6b | 16 | } else { |
bddc9788 AD |
17 | if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { |
18 | db_query($link, "SET NAMES " . MYSQL_CHARSET); | |
75ca1986 | 19 | // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET); |
bddc9788 | 20 | } |
81596c66 | 21 | } |
70dcff6b | 22 | |
81596c66 AD |
23 | login_sequence($link); |
24 | ||
25 | $owner_uid = $_SESSION["uid"]; | |
26 | ||
441acab8 | 27 | if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { |
a190ebfd AD |
28 | $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); |
29 | render_login_form($link); | |
01a87dff | 30 | exit; |
81596c66 | 31 | } |
87b9fb65 | 32 | |
fecd57c8 AD |
33 | |
34 | ?> | |
35 | ||
36 | <html> | |
37 | <head> | |
b4c27af7 AD |
38 | <title>Database Updater</title> |
39 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
ef59e6e8 | 40 | <link rel="stylesheet" type="text/css" href="utility.css"> |
fecd57c8 AD |
41 | </head> |
42 | ||
43 | <body> | |
44 | ||
b4c27af7 AD |
45 | <script type='text/javascript'> |
46 | function confirmOP() { | |
06719138 | 47 | return confirm(__("Update the database?")); |
b4c27af7 AD |
48 | } |
49 | </script> | |
50 | ||
ef59e6e8 AD |
51 | <div class="floatingLogo"><img src="images/ttrss_logo.png"></div> |
52 | ||
06719138 | 53 | <h1><?php echo __("Database Updater") ?></h1> |
fecd57c8 AD |
54 | |
55 | <?php | |
81596c66 AD |
56 | function getline($fp, $delim) { |
57 | $result = ""; | |
58 | while(!feof($fp)) { | |
59 | $tmp = fgetc($fp); | |
60 | ||
61 | if($tmp == $delim) { | |
62 | return $result; | |
63 | } | |
64 | $result .= $tmp; | |
fecd57c8 | 65 | } |
81596c66 | 66 | return $result; |
fecd57c8 | 67 | } |
81596c66 AD |
68 | |
69 | $op = $_POST["op"]; | |
70 | ||
71 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
72 | $version = db_fetch_result($result, 0, "schema_version"); | |
73 | ||
74 | $update_files = glob("schema/versions/".DB_TYPE."/*sql"); | |
75 | $update_versions = array(); | |
76 | ||
77 | foreach ($update_files as $f) { | |
78 | $m = array(); | |
79 | preg_match_all("/schema\/versions\/".DB_TYPE."\/(\d*)\.sql/", $f, $m, | |
80 | PREG_PATTERN_ORDER); | |
81 | ||
82 | if ($m[1][0]) { | |
83 | $update_versions[$m[1][0]] = $f; | |
fecd57c8 | 84 | } |
81596c66 AD |
85 | } |
86 | ||
87 | ksort($update_versions, SORT_NUMERIC); | |
88 | ||
89 | $latest_version = max(array_keys($update_versions)); | |
9e21a571 | 90 | |
81596c66 | 91 | if ($version == $latest_version) { |
9e21a571 AD |
92 | |
93 | if ($version != SCHEMA_VERSION) { | |
94 | print_error(__("Could not update database")); | |
95 | ||
96 | print "<p>" . | |
97 | __("Could not find necessary schema file, need version:") . | |
98 | " " . SCHEMA_VERSION . __(", found: ") . $latest_version . "</p>"; | |
99 | ||
100 | } else { | |
101 | print "<p>".__("Tiny Tiny RSS database is up to date.")."</p>"; | |
102 | print "<form method=\"GET\" action=\"tt-rss.php\"> | |
103 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
104 | </form>"; | |
105 | } | |
ef59e6e8 | 106 | |
81596c66 AD |
107 | return; |
108 | } | |
109 | ||
110 | if (!$op) { | |
bddc9788 | 111 | print_warning(__("Please backup your database before proceeding.")); |
81596c66 | 112 | |
06719138 | 113 | 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>"; |
81596c66 AD |
114 | |
115 | /* print "<p>Available incremental updates:"; | |
116 | ||
117 | foreach (array_keys($update_versions) as $v) { | |
118 | if ($v > $version) { | |
119 | print " <a href='$update_versions[$v]'>$v</a>"; | |
120 | } | |
121 | } */ | |
122 | ||
123 | print "</p>"; | |
124 | ||
125 | print "<form method='POST'> | |
126 | <input type='hidden' name='op' value='do'> | |
06719138 | 127 | <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'> |
81596c66 AD |
128 | </form>"; |
129 | ||
130 | } else if ($op == "do") { | |
131 | ||
06719138 | 132 | print "<p>".__("Performing updates...")."</p>"; |
81596c66 AD |
133 | |
134 | $num_updates = 0; | |
135 | ||
136 | foreach (array_keys($update_versions) as $v) { | |
137 | if ($v == $version + 1) { | |
06719138 | 138 | print "<p>".T_sprintf("Updating to version %d...", $v)."</p>"; |
81596c66 AD |
139 | $fp = fopen($update_versions[$v], "r"); |
140 | if ($fp) { | |
141 | while (!feof($fp)) { | |
142 | $query = trim(getline($fp, ";")); | |
143 | if ($query != "") { | |
06719138 | 144 | print "<p class='query'>$query</p>"; |
81596c66 AD |
145 | db_query($link, $query); |
146 | } | |
fecd57c8 AD |
147 | } |
148 | } | |
81596c66 AD |
149 | fclose($fp); |
150 | ||
06719138 | 151 | print "<p>".__("Checking version... "); |
81596c66 AD |
152 | |
153 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
154 | $version = db_fetch_result($result, 0, "schema_version"); | |
155 | ||
156 | if ($version == $v) { | |
06719138 | 157 | print __("OK!"); |
81596c66 | 158 | } else { |
06719138 | 159 | print "<b>".__("ERROR!")."</b>"; |
81596c66 AD |
160 | return; |
161 | } | |
162 | ||
163 | $num_updates++; | |
b4c27af7 | 164 | } |
b4c27af7 | 165 | } |
81596c66 | 166 | |
06719138 AD |
167 | print "<p>".T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema |
168 | version <b>%d</b>.", $num_updates, $version)."</p>"; | |
81596c66 | 169 | |
07a2b314 | 170 | print "<form method=\"GET\" action=\"logout.php\"> |
06719138 | 171 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> |
ef59e6e8 AD |
172 | </form>"; |
173 | ||
fecd57c8 | 174 | } |
81596c66 | 175 | |
fecd57c8 AD |
176 | ?> |
177 | ||
fecd57c8 AD |
178 | </body> |
179 | </html> | |
180 |