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