2010-11-09 13:33:08 +00:00
|
|
|
<?php
|
2012-12-09 09:41:22 +00:00
|
|
|
set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
|
|
|
|
get_include_path());
|
2011-12-11 19:59:25 +00:00
|
|
|
|
2010-11-10 10:14:44 +00:00
|
|
|
require_once "functions.php";
|
2010-11-09 13:33:08 +00:00
|
|
|
require_once "sessions.php";
|
|
|
|
require_once "sanity_check.php";
|
|
|
|
require_once "config.php";
|
|
|
|
require_once "db.php";
|
|
|
|
|
2011-04-14 13:48:26 +00:00
|
|
|
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
|
|
|
|
2011-12-13 10:49:11 +00:00
|
|
|
if (!init_connection($link)) return;
|
2010-11-09 13:33:08 +00:00
|
|
|
login_sequence($link);
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
$owner_uid = $_SESSION["uid"];
|
2011-04-14 13:48:26 +00:00
|
|
|
|
|
|
|
if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
|
2010-11-09 13:33:08 +00:00
|
|
|
$_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
|
|
|
|
render_login_form($link);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Database Updater</title>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
|
|
<link rel="stylesheet" type="text/css" href="utility.css">
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<script type='text/javascript'>
|
|
|
|
function confirmOP() {
|
|
|
|
return confirm(__("Update the database?"));
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2011-04-20 07:52:17 +00:00
|
|
|
<div class="floatingLogo"><img src="images/logo_wide.png"></div>
|
2010-11-09 13:33:08 +00:00
|
|
|
|
|
|
|
<h1><?php echo __("Database Updater") ?></h1>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
function getline($fp, $delim) {
|
|
|
|
$result = "";
|
|
|
|
while(!feof($fp)) {
|
|
|
|
$tmp = fgetc($fp);
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
if($tmp == $delim) {
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
$result .= $tmp;
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
$op = $_POST["op"];
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
$result = db_query($link, "SELECT schema_version FROM ttrss_version");
|
|
|
|
$version = db_fetch_result($result, 0, "schema_version");
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
$update_files = glob("schema/versions/".DB_TYPE."/*sql");
|
|
|
|
$update_versions = array();
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
foreach ($update_files as $f) {
|
|
|
|
$m = array();
|
|
|
|
preg_match_all("/schema\/versions\/".DB_TYPE."\/(\d*)\.sql/", $f, $m,
|
|
|
|
PREG_PATTERN_ORDER);
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
if ($m[1][0]) {
|
|
|
|
$update_versions[$m[1][0]] = $f;
|
|
|
|
}
|
|
|
|
}
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
ksort($update_versions, SORT_NUMERIC);
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
$latest_version = max(array_keys($update_versions));
|
|
|
|
|
|
|
|
if ($version == $latest_version) {
|
|
|
|
|
|
|
|
if ($version != SCHEMA_VERSION) {
|
|
|
|
print_error(__("Could not update database"));
|
|
|
|
|
2011-04-14 13:48:26 +00:00
|
|
|
print "<p>" .
|
2010-11-09 13:33:08 +00:00
|
|
|
__("Could not find necessary schema file, need version:") .
|
|
|
|
" " . SCHEMA_VERSION . __(", found: ") . $latest_version . "</p>";
|
|
|
|
|
|
|
|
} else {
|
2010-11-22 16:25:15 +00:00
|
|
|
print_notice(__("Tiny Tiny RSS database is up to date."));
|
2011-12-11 19:59:25 +00:00
|
|
|
print "<form method=\"GET\" action=\"index.php\">
|
2010-11-09 13:33:08 +00:00
|
|
|
<input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
|
|
|
|
</form>";
|
|
|
|
}
|
|
|
|
|
2011-04-20 07:52:17 +00:00
|
|
|
} else if ($version <= $latest_version && !$op) {
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
print_warning(__("Please backup your database before proceeding."));
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
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>";
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
/* print "<p>Available incremental updates:";
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
foreach (array_keys($update_versions) as $v) {
|
|
|
|
if ($v > $version) {
|
|
|
|
print " <a href='$update_versions[$v]'>$v</a>";
|
|
|
|
}
|
|
|
|
} */
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
print "</p>";
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
print "<form method='POST'>
|
|
|
|
<input type='hidden' name='op' value='do'>
|
|
|
|
<input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
|
|
|
|
</form>";
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
} else if ($op == "do") {
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
print "<p>".__("Performing updates...")."</p>";
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
$num_updates = 0;
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
foreach (array_keys($update_versions) as $v) {
|
|
|
|
if ($v == $version + 1) {
|
|
|
|
print "<p>".T_sprintf("Updating to version %d...", $v)."</p>";
|
2012-11-23 09:22:34 +00:00
|
|
|
db_query($link, "BEGIN");
|
2010-11-09 13:33:08 +00:00
|
|
|
$fp = fopen($update_versions[$v], "r");
|
|
|
|
if ($fp) {
|
|
|
|
while (!feof($fp)) {
|
|
|
|
$query = trim(getline($fp, ";"));
|
|
|
|
if ($query != "") {
|
|
|
|
print "<p class='query'>$query</p>";
|
|
|
|
db_query($link, $query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($fp);
|
2012-11-23 09:22:34 +00:00
|
|
|
db_query($link, "COMMIT");
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
print "<p>".__("Checking version... ");
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
$result = db_query($link, "SELECT schema_version FROM ttrss_version");
|
|
|
|
$version = db_fetch_result($result, 0, "schema_version");
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
if ($version == $v) {
|
|
|
|
print __("OK!");
|
|
|
|
} else {
|
|
|
|
print "<b>".__("ERROR!")."</b>";
|
|
|
|
return;
|
|
|
|
}
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
$num_updates++;
|
|
|
|
}
|
|
|
|
}
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
print "<p>".T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema
|
|
|
|
version <b>%d</b>.", $num_updates, $version)."</p>";
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2011-04-20 07:46:16 +00:00
|
|
|
print "<form method=\"GET\" action=\"backend.php\">
|
|
|
|
<input type=\"hidden\" name=\"op\" value=\"logout\">
|
2010-11-09 13:33:08 +00:00
|
|
|
<input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
|
|
|
|
</form>";
|
|
|
|
|
2011-04-20 07:52:17 +00:00
|
|
|
} else if ($version >= $latest_version) {
|
|
|
|
|
|
|
|
print_error(__("Your database schema is from a newer version of Tiny Tiny RSS."));
|
|
|
|
|
|
|
|
print "<p>" . T_sprintf("Found schema version: <b>%d</b>, required: <b>%d</b>.", $version, $latest_version) . "</p>";
|
|
|
|
|
|
|
|
print "<p>" . __("Schema upgrade impossible. Please update Tiny Tiny RSS files to the newer version and continue.") . "</p>";
|
|
|
|
|
|
|
|
print "<form method=\"GET\" action=\"backend.php\">
|
|
|
|
<input type=\"hidden\" name=\"op\" value=\"logout\">
|
|
|
|
<input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
|
|
|
|
</form>";
|
|
|
|
|
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
}
|
2011-04-14 13:48:26 +00:00
|
|
|
|
2010-11-09 13:33:08 +00:00
|
|
|
?>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|