diff options
author | Andrew Dolgov <[email protected]> | 2012-08-09 14:20:27 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-08-09 14:20:27 +0400 |
commit | 871f0a7ac658a0be2ed982ed1bcc6daccf14fd8a (patch) | |
tree | 00218ea91924114c84bec88c63ca0e7c5ba19e50 | |
parent | 8c5c4e494d92772533b2d56cbd426a01ccc24da1 (diff) |
add update.php -indexes to recreate tt-rss indexes from schema file
-rw-r--r-- | include/functions.php | 12 | ||||
-rwxr-xr-x | update.php | 56 |
2 files changed, 68 insertions, 0 deletions
diff --git a/include/functions.php b/include/functions.php index 3da777135..4ba60e844 100644 --- a/include/functions.php +++ b/include/functions.php @@ -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; + } ?> diff --git a/update.php b/update.php index fa322d3dc..4f8dcdbee 100755 --- a/update.php +++ b/update.php @@ -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) { |