]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/setup/SetupClass.php
update osm2pgsql (disable install rule)
[nominatim.git] / lib / setup / SetupClass.php
index a865b8f0cb2edf4780a1b54ed8de6b5f45e450ac..2a49828733a2ff97c897b97dbe85deb724be3b5f 100755 (executable)
@@ -8,7 +8,6 @@ class SetupFunctions
 {
     protected $iCacheMemory;
     protected $iInstances;
 {
     protected $iCacheMemory;
     protected $iInstances;
-    protected $sModulePath;
     protected $aDSNInfo;
     protected $bQuiet;
     protected $bVerbose;
     protected $aDSNInfo;
     protected $bQuiet;
     protected $bVerbose;
@@ -42,12 +41,6 @@ class SetupFunctions
             $this->iCacheMemory = getCacheMemoryMB();
         }
 
             $this->iCacheMemory = getCacheMemoryMB();
         }
 
-        $this->sModulePath = getSetting('DATABASE_MODULE_PATH');
-        if (!$this->sModulePath) {
-            $this->sModulePath = CONST_Default_ModulePath;
-        }
-        info('module path: ' . $this->sModulePath);
-
         // parse database string
         $this->aDSNInfo = \Nominatim\DB::parseDSN(getSetting('DATABASE_DSN'));
         if (!isset($this->aDSNInfo['port'])) {
         // parse database string
         $this->aDSNInfo = \Nominatim\DB::parseDSN(getSetting('DATABASE_DSN'));
         if (!isset($this->aDSNInfo['port'])) {
@@ -149,6 +142,27 @@ class SetupFunctions
             exit(1);
         }
 
             exit(1);
         }
 
+        if (!getSetting('DATABASE_MODULE_PATH')) {
+            // If no custom module path is set then copy the module into the
+            // project directory, but only if it is not the same file already
+            // (aka we are running from the build dir).
+            $sDest = CONST_InstallDir.'/module';
+            if ($sDest != CONST_Default_ModulePath) {
+                if (!file_exists($sDest)) {
+                    mkdir($sDest);
+                }
+                if (!copy(CONST_Default_ModulePath.'/nominatim.so', $sDest.'/nominatim.so')) {
+                    echo "Failed to copy database module to $sDest.";
+                    exit(1);
+                }
+                chmod($sDest.'/nominatim.so', 0755);
+                info("Database module installed at $sDest.");
+            } else {
+                info('Running from build directory. Leaving database module as is.');
+            }
+        } else {
+            info('Using database module from DATABASE_MODULE_PATH ('.getSetting('DATABASE_MODULE_PATH').').');
+        }
         // Try accessing the C module, so we know early if something is wrong
         $this->checkModulePresence(); // raises exception on failure
 
         // Try accessing the C module, so we know early if something is wrong
         $this->checkModulePresence(); // raises exception on failure
 
@@ -159,22 +173,6 @@ class SetupFunctions
         }
         $this->pgsqlRunScriptFile(CONST_DataDir.'/data/country_name.sql');
         $this->pgsqlRunScriptFile(CONST_DataDir.'/data/country_osm_grid.sql.gz');
         }
         $this->pgsqlRunScriptFile(CONST_DataDir.'/data/country_name.sql');
         $this->pgsqlRunScriptFile(CONST_DataDir.'/data/country_osm_grid.sql.gz');
-        $this->pgsqlRunScriptFile(CONST_DataDir.'/data/gb_postcode_table.sql');
-        $this->pgsqlRunScriptFile(CONST_DataDir.'/data/us_postcode_table.sql');
-
-        $sPostcodeFilename = CONST_DataDir.'/data/gb_postcode_data.sql.gz';
-        if (file_exists($sPostcodeFilename)) {
-            $this->pgsqlRunScriptFile($sPostcodeFilename);
-        } else {
-            warn('optional external GB postcode table file ('.$sPostcodeFilename.') not found. Skipping.');
-        }
-
-        $sPostcodeFilename = CONST_DataDir.'/data/us_postcode_data.sql.gz';
-        if (file_exists($sPostcodeFilename)) {
-            $this->pgsqlRunScriptFile($sPostcodeFilename);
-        } else {
-            warn('optional external US postcode table file ('.$sPostcodeFilename.') not found. Skipping.');
-        }
 
         if ($this->bNoPartitions) {
             $this->pgsqlRunScript('update country_name set partition = 0');
 
         if ($this->bNoPartitions) {
             $this->pgsqlRunScript('update country_name set partition = 0');
@@ -295,7 +293,7 @@ class SetupFunctions
 
     public function importWikipediaArticles()
     {
 
     public function importWikipediaArticles()
     {
-        $sWikiArticlePath = getSetting('WIKIPEDIA_DATA_PATH', CONST_DataDir.'/data');
+        $sWikiArticlePath = getSetting('WIKIPEDIA_DATA_PATH', CONST_InstallDir);
         $sWikiArticlesFile = $sWikiArticlePath.'/wikimedia-importance.sql.gz';
         if (file_exists($sWikiArticlesFile)) {
             info('Importing wikipedia articles and redirects');
         $sWikiArticlesFile = $sWikiArticlePath.'/wikimedia-importance.sql.gz';
         if (file_exists($sWikiArticlesFile)) {
             info('Importing wikipedia articles and redirects');
@@ -507,6 +505,23 @@ class SetupFunctions
     public function calculatePostcodes($bCMDResultAll)
     {
         info('Calculate Postcodes');
     public function calculatePostcodes($bCMDResultAll)
     {
         info('Calculate Postcodes');
+        $this->pgsqlRunScriptFile(CONST_DataDir.'/sql/postcode_tables.sql');
+
+        $sPostcodeFilename = CONST_InstallDir.'/gb_postcode_data.sql.gz';
+        if (file_exists($sPostcodeFilename)) {
+            $this->pgsqlRunScriptFile($sPostcodeFilename);
+        } else {
+            warn('optional external GB postcode table file ('.$sPostcodeFilename.') not found. Skipping.');
+        }
+
+        $sPostcodeFilename = CONST_InstallDir.'/us_postcode_data.sql.gz';
+        if (file_exists($sPostcodeFilename)) {
+            $this->pgsqlRunScriptFile($sPostcodeFilename);
+        } else {
+            warn('optional external US postcode table file ('.$sPostcodeFilename.') not found. Skipping.');
+        }
+
+
         $this->db()->exec('TRUNCATE location_postcode');
 
         $sSQL  = 'INSERT INTO location_postcode';
         $this->db()->exec('TRUNCATE location_postcode');
 
         $sSQL  = 'INSERT INTO location_postcode';
@@ -739,8 +754,7 @@ class SetupFunctions
             fwriteConstDef($rFile, 'Use_US_Tiger_Data', getSettingBool('USE_US_TIGER_DATA'));
             fwriteConstDef($rFile, 'MapIcon_URL', getSetting('MAPICON_URL'));
 
             fwriteConstDef($rFile, 'Use_US_Tiger_Data', getSettingBool('USE_US_TIGER_DATA'));
             fwriteConstDef($rFile, 'MapIcon_URL', getSetting('MAPICON_URL'));
 
-            // XXX scripts should go into the library.
-            fwrite($rFile, 'require_once(\''.CONST_DataDir.'/website/'.$sScript."');\n");
+            fwrite($rFile, 'require_once(\''.CONST_LibDir.'/website/'.$sScript."');\n");
             fclose($rFile);
 
             chmod(CONST_InstallDir.'/website/'.$sScript, 0755);
             fclose($rFile);
 
             chmod(CONST_InstallDir.'/website/'.$sScript, 0755);
@@ -933,12 +947,13 @@ class SetupFunctions
      */
     private function checkModulePresence()
     {
      */
     private function checkModulePresence()
     {
+        $sModulePath = getSetting('DATABASE_MODULE_PATH', CONST_InstallDir.'/module');
         $sSQL = "CREATE FUNCTION nominatim_test_import_func(text) RETURNS text AS '";
         $sSQL = "CREATE FUNCTION nominatim_test_import_func(text) RETURNS text AS '";
-        $sSQL .= $this->sModulePath . "/nominatim.so', 'transliteration' LANGUAGE c IMMUTABLE STRICT";
+        $sSQL .= $sModulePath . "/nominatim.so', 'transliteration' LANGUAGE c IMMUTABLE STRICT";
         $sSQL .= ';DROP FUNCTION nominatim_test_import_func(text);';
 
         $oDB = new \Nominatim\DB();
         $oDB->connect();
         $sSQL .= ';DROP FUNCTION nominatim_test_import_func(text);';
 
         $oDB = new \Nominatim\DB();
         $oDB->connect();
-        $oDB->exec($sSQL, null, 'Database server failed to load '.$this->sModulePath.'/nominatim.so module');
+        $oDB->exec($sSQL, null, 'Database server failed to load '.$sModulePath.'/nominatim.so module');
     }
 }
     }
 }