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