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