]>
Commit | Line | Data |
---|---|---|
fecd57c8 | 1 | <?php |
b4c27af7 | 2 | require_once "sessions.php"; |
fecd57c8 | 3 | |
b4c27af7 AD |
4 | require_once "sanity_check.php"; |
5 | require_once "functions.php"; | |
6 | require_once "config.php"; | |
7 | require_once "db.php"; | |
fecd57c8 | 8 | |
b4c27af7 | 9 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
fecd57c8 | 10 | |
b4c27af7 AD |
11 | if (DB_TYPE == "pgsql") { |
12 | pg_query($link, "set client_encoding = 'utf-8'"); | |
13 | pg_set_client_encoding("UNICODE"); | |
14 | } | |
fecd57c8 | 15 | |
b4c27af7 | 16 | login_sequence($link); |
fecd57c8 | 17 | |
b4c27af7 | 18 | $owner_uid = $_SESSION["uid"]; |
fecd57c8 | 19 | |
b4c27af7 AD |
20 | if ($_SESSION["access_level"] < 10) { |
21 | header("Location: login.php"); die; | |
22 | } | |
fecd57c8 | 23 | |
b4c27af7 | 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 | |
b4c27af7 AD |
46 | function getline($fp, $delim) { |
47 | $result = ""; | |
48 | while(!feof($fp)) { | |
49 | $tmp = fgetc($fp); | |
fecd57c8 | 50 | |
b4c27af7 AD |
51 | if($tmp == $delim) { |
52 | return $result; | |
fecd57c8 | 53 | } |
b4c27af7 | 54 | $result .= $tmp; |
fecd57c8 | 55 | } |
b4c27af7 AD |
56 | return $result; |
57 | } | |
fecd57c8 | 58 | |
b4c27af7 | 59 | $op = $_POST["op"]; |
fecd57c8 | 60 | |
b4c27af7 AD |
61 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); |
62 | $version = db_fetch_result($result, 0, "schema_version"); | |
fecd57c8 | 63 | |
b4c27af7 AD |
64 | $update_files = glob("schema/versions/".DB_TYPE."/*sql"); |
65 | $update_versions = array(); | |
fecd57c8 | 66 | |
b4c27af7 AD |
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 | } |
b4c27af7 | 75 | } |
fecd57c8 | 76 | |
b4c27af7 | 77 | ksort($update_versions, SORT_NUMERIC); |
fecd57c8 | 78 | |
b4c27af7 | 79 | $latest_version = max(array_keys($update_versions)); |
fecd57c8 | 80 | |
b4c27af7 AD |
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 | } | |
fecd57c8 | 86 | |
b4c27af7 AD |
87 | if (!$op) { |
88 | print "<p class='warning'><b>Warning:</b> Please backup your database before proceeding.</p>"; | |
fecd57c8 | 89 | |
b4c27af7 AD |
90 | print "<p>Your Tiny Tiny RSS database needs update to the latest |
91 | version ($version —> $latest_version).</p>"; | |
fecd57c8 | 92 | |
b4c27af7 | 93 | /* print "<p>Available incremental updates:"; |
fecd57c8 | 94 | |
b4c27af7 AD |
95 | foreach (array_keys($update_versions) as $v) { |
96 | if ($v > $version) { | |
97 | print " <a href='$update_versions[$v]'>$v</a>"; | |
fecd57c8 | 98 | } |
b4c27af7 AD |
99 | } */ |
100 | ||
101 | print "</p>"; | |
fecd57c8 | 102 | |
b4c27af7 AD |
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>"; | |
fecd57c8 | 107 | |
b4c27af7 | 108 | } else if ($op == "do") { |
fecd57c8 | 109 | |
b4c27af7 | 110 | print "<p>Performing updates (from version $version)...</p>"; |
fecd57c8 | 111 | |
b4c27af7 | 112 | $num_updates = 0; |
fecd57c8 | 113 | |
b4c27af7 AD |
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); | |
fecd57c8 AD |
124 | } |
125 | } | |
b4c27af7 AD |
126 | } |
127 | fclose($fp); | |
fecd57c8 | 128 | |
b4c27af7 | 129 | print "<p>Checking version... "; |
fecd57c8 | 130 | |
b4c27af7 AD |
131 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); |
132 | $version = db_fetch_result($result, 0, "schema_version"); | |
fecd57c8 | 133 | |
b4c27af7 AD |
134 | if ($version == $v) { |
135 | print "OK! ($version)"; | |
136 | } else { | |
137 | print "<b>ERROR!</b>"; | |
138 | return; | |
fecd57c8 | 139 | } |
fecd57c8 | 140 | |
b4c27af7 AD |
141 | $num_updates++; |
142 | } | |
fecd57c8 | 143 | } |
b4c27af7 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 | ||
150 | } | |
151 | ||
fecd57c8 AD |
152 | ?> |
153 | ||
154 | ||
155 | </body> | |
156 | </html> | |
157 |