add update.php -indexes to recreate tt-rss indexes from schema file

This commit is contained in:
Andrew Dolgov 2012-08-09 14:20:27 +04:00
parent 8c5c4e494d
commit 871f0a7ac6
2 changed files with 68 additions and 0 deletions

View file

@ -5469,4 +5469,16 @@
return $output;
}
}
function read_stdin() {
$fp = fopen("php://stdin", "r");
if ($fp) {
$line = trim(fgets($fp));
fclose($fp);
return $line;
}
return null;
}
?>

View file

@ -29,6 +29,7 @@
print " -get-feeds - receive popular feeds from linked instances\n";
print " -import USER FILE - import articles from XML\n";
print " -quiet - don't show messages\n";
print " -indexes - recreate missing schema indexes\n";
print " -help - show this help\n";
return;
}
@ -149,6 +150,61 @@
}
if (in_array("-indexes", $op)) {
_debug("PLEASE BACKUP YOUR DATABASE BEFORE PROCEEDING!");
_debug("Type 'yes' to continue.");
if (read_stdin() != 'yes')
exit;
_debug("clearing existing indexes...");
if (DB_TYPE == "pgsql") {
$result = db_query($link, "SELECT relname FROM
pg_catalog.pg_class WHERE relname LIKE 'ttrss_%'
AND relname NOT LIKE '%_pkey'
AND relkind = 'i'");
} else {
$result = db_query($link, "SELECT index_name,table_name FROM
information_schema.statistics WHERE index_name LIKE 'ttrss_%'");
}
while ($line = db_fetch_assoc($result)) {
if (DB_TYPE == "pgsql") {
$statement = "DROP INDEX " . $line["relname"];
_debug($statement);
} else {
$statement = "ALTER TABLE ".
$line['table_name']." DROP INDEX ".$line['index_name'];
_debug($statement);
}
db_query($link, $statement, false);
}
_debug("reading indexes from schema for: " . DB_TYPE);
$fp = fopen("schema/ttrss_schema_" . DB_TYPE . ".sql", "r");
if ($fp) {
while ($line = fgets($fp)) {
$matches = array();
if (preg_match("/^create index ([^ ]+) on ([^ ]+)$/i", $line, $matches)) {
$index = $matches[1];
$table = $matches[2];
$statement = "CREATE INDEX $index ON $table";
_debug($statement);
db_query($link, $statement);
}
}
fclose($fp);
} else {
_debug("unable to open schema file.");
}
_debug("all done.");
}
db_close($link);
if ($lock_handle != false) {