From: Andrew Dolgov Date: Thu, 9 Aug 2012 10:20:27 +0000 (+0400) Subject: add update.php -indexes to recreate tt-rss indexes from schema file X-Git-Tag: 1.6.0~177 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=871f0a7ac658a0be2ed982ed1bcc6daccf14fd8a;p=tt-rss.git add update.php -indexes to recreate tt-rss indexes from schema file --- diff --git a/include/functions.php b/include/functions.php index 3da77713..4ba60e84 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 fa322d3d..4f8dcdbe 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) {