summaryrefslogtreecommitdiff
path: root/update.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2012-08-09 14:20:27 +0400
committerAndrew Dolgov <[email protected]>2012-08-09 14:20:27 +0400
commit871f0a7ac658a0be2ed982ed1bcc6daccf14fd8a (patch)
tree00218ea91924114c84bec88c63ca0e7c5ba19e50 /update.php
parent8c5c4e494d92772533b2d56cbd426a01ccc24da1 (diff)
add update.php -indexes to recreate tt-rss indexes from schema file
Diffstat (limited to 'update.php')
-rwxr-xr-xupdate.php56
1 files changed, 56 insertions, 0 deletions
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) {