]>
Commit | Line | Data |
---|---|---|
fecd57c8 | 1 | <?php |
81596c66 AD |
2 | require_once "sessions.php"; |
3 | ||
4 | require_once "sanity_check.php"; | |
5 | require_once "functions.php"; | |
6 | require_once "config.php"; | |
7 | require_once "db.php"; | |
8 | ||
9 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
10 | ||
11 | if (DB_TYPE == "pgsql") { | |
12 | pg_query($link, "set client_encoding = 'utf-8'"); | |
13 | pg_set_client_encoding("UNICODE"); | |
14 | } | |
15 | ||
16 | login_sequence($link); | |
17 | ||
18 | $owner_uid = $_SESSION["uid"]; | |
19 | ||
20 | if ($_SESSION["access_level"] < 10) { | |
21 | header("Location: login.php"); die; | |
22 | } | |
23 | ||
24 | define('SCHEMA_VERSION', 13); | |
fecd57c8 AD |
25 | |
26 | ?> | |
27 | ||
28 | <html> | |
29 | <head> | |
b4c27af7 AD |
30 | <title>Database Updater</title> |
31 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
32 | <link rel="stylesheet" type="text/css" href="update.css"> | |
fecd57c8 AD |
33 | </head> |
34 | ||
35 | <body> | |
36 | ||
b4c27af7 AD |
37 | <script type='text/javascript'> |
38 | function confirmOP() { | |
39 | return confirm("Update the database?"); | |
40 | } | |
41 | </script> | |
42 | ||
fecd57c8 AD |
43 | <h1>Database Updater</h1> |
44 | ||
45 | <?php | |
81596c66 AD |
46 | function getline($fp, $delim) { |
47 | $result = ""; | |
48 | while(!feof($fp)) { | |
49 | $tmp = fgetc($fp); | |
50 | ||
51 | if($tmp == $delim) { | |
52 | return $result; | |
53 | } | |
54 | $result .= $tmp; | |
fecd57c8 | 55 | } |
81596c66 | 56 | return $result; |
fecd57c8 | 57 | } |
81596c66 AD |
58 | |
59 | $op = $_POST["op"]; | |
60 | ||
61 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
62 | $version = db_fetch_result($result, 0, "schema_version"); | |
63 | ||
64 | $update_files = glob("schema/versions/".DB_TYPE."/*sql"); | |
65 | $update_versions = array(); | |
66 | ||
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); | |
71 | ||
72 | if ($m[1][0]) { | |
73 | $update_versions[$m[1][0]] = $f; | |
fecd57c8 | 74 | } |
81596c66 AD |
75 | } |
76 | ||
77 | ksort($update_versions, SORT_NUMERIC); | |
78 | ||
79 | $latest_version = max(array_keys($update_versions)); | |
80 | ||
81 | if ($version == $latest_version) { | |
82 | print "<p>Tiny Tiny RSS database is up to date (version $version).</p>"; | |
83 | print "<p><a href='tt-rss.php'>Return to Tiny Tiny RSS</a></p>"; | |
84 | return; | |
85 | } | |
86 | ||
87 | if (!$op) { | |
88 | print "<p class='warning'><b>Warning:</b> Please backup your database before proceeding.</p>"; | |
89 | ||
90 | print "<p>Your Tiny Tiny RSS database needs update to the latest | |
91 | version ($version —> $latest_version).</p>"; | |
92 | ||
93 | /* print "<p>Available incremental updates:"; | |
94 | ||
95 | foreach (array_keys($update_versions) as $v) { | |
96 | if ($v > $version) { | |
97 | print " <a href='$update_versions[$v]'>$v</a>"; | |
98 | } | |
99 | } */ | |
100 | ||
101 | print "</p>"; | |
102 | ||
103 | print "<form method='POST'> | |
104 | <input type='hidden' name='op' value='do'> | |
105 | <input type='submit' onclick='return confirmOP()' value='Perform updates'> | |
106 | </form>"; | |
107 | ||
108 | } else if ($op == "do") { | |
109 | ||
110 | print "<p>Performing updates (from version $version)...</p>"; | |
111 | ||
112 | $num_updates = 0; | |
113 | ||
114 | foreach (array_keys($update_versions) as $v) { | |
115 | if ($v == $version + 1) { | |
116 | print "<p>Updating to version $v...</p>"; | |
117 | $fp = fopen($update_versions[$v], "r"); | |
118 | if ($fp) { | |
119 | while (!feof($fp)) { | |
120 | $query = trim(getline($fp, ";")); | |
121 | if ($query != "") { | |
122 | print "<p class='query'><b>QUERY:</b> $query</p>"; | |
123 | db_query($link, $query); | |
124 | } | |
fecd57c8 AD |
125 | } |
126 | } | |
81596c66 AD |
127 | fclose($fp); |
128 | ||
129 | print "<p>Checking version... "; | |
130 | ||
131 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
132 | $version = db_fetch_result($result, 0, "schema_version"); | |
133 | ||
134 | if ($version == $v) { | |
135 | print "OK! ($version)"; | |
136 | } else { | |
137 | print "<b>ERROR!</b>"; | |
138 | return; | |
139 | } | |
140 | ||
141 | $num_updates++; | |
b4c27af7 | 142 | } |
b4c27af7 | 143 | } |
81596c66 AD |
144 | |
145 | print "<p>Finished. Performed $num_updates updates up to schema | |
146 | version $version.</p>"; | |
147 | ||
148 | print "<p><a href='tt-rss.php'>Return to Tiny Tiny RSS</a></p>"; | |
149 | ||
fecd57c8 | 150 | } |
81596c66 | 151 | |
fecd57c8 AD |
152 | ?> |
153 | ||
fecd57c8 AD |
154 | </body> |
155 | </html> | |
156 |