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