]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/setup/SetupClass.php
Merge pull request #1667 from mtmail/setup-delete-invalid-indices
[nominatim.git] / lib / setup / SetupClass.php
index bf44e04b299068e47f4992f947dcd967f26fb098..100e384744d42f03f0342104c53017e7053c99cd 100755 (executable)
@@ -10,6 +10,7 @@ class SetupFunctions
     protected $iInstances;
     protected $sModulePath;
     protected $aDSNInfo;
+    protected $bQuiet;
     protected $bVerbose;
     protected $sIgnoreErrors;
     protected $bEnableDiffUpdates;
@@ -49,6 +50,7 @@ class SetupFunctions
         }
 
         // setting member variables based on command line options stored in $aCMDResult
+        $this->bQuiet = $aCMDResult['quiet'];
         $this->bVerbose = $aCMDResult['verbose'];
 
         //setting default values which are not set by the update.php array
@@ -518,10 +520,16 @@ class SetupFunctions
     public function index($bIndexNoanalyse)
     {
         $sOutputFile = '';
-        $sBaseCmd = CONST_InstallPath.'/nominatim/nominatim -i'
+        $sBaseCmd = CONST_BasePath.'/nominatim/nominatim.py'
             .' -d '.escapeshellarg($this->aDSNInfo['database'])
             .' -P '.escapeshellarg($this->aDSNInfo['port'])
             .' -t '.escapeshellarg($this->iInstances.$sOutputFile);
+        if (!$this->bQuiet) {
+            $sBaseCmd .= ' -v';
+        }
+        if ($this->bVerbose) {
+            $sBaseCmd .= ' -v';
+        }
         if (isset($this->aDSNInfo['hostspec'])) {
             $sBaseCmd .= ' -H '.escapeshellarg($this->aDSNInfo['hostspec']);
         }
@@ -558,6 +566,15 @@ class SetupFunctions
     {
         info('Create Search indices');
 
+        $sSQL = 'SELECT relname FROM pg_class, pg_index ';
+        $sSQL .= 'WHERE pg_index.indisvalid = false AND pg_index.indexrelid = pg_class.oid';
+        $aInvalidIndices = $this->oDB->getCol($sSQL);
+
+        foreach ($aInvalidIndices as $sIndexName) {
+            info("Cleaning up invalid index $sIndexName");
+            $this->oDB->exec("DROP INDEX $sIndexName;");
+        }
+
         $sTemplate = file_get_contents(CONST_BasePath.'/sql/indices.src.sql');
         if (!$this->dbReverseOnly()) {
             $sTemplate .= file_get_contents(CONST_BasePath.'/sql/indices_search.src.sql');