]> git.openstreetmap.org Git - nominatim.git/blobdiff - utils/setup.php
Do not swallow PEAR error.
[nominatim.git] / utils / setup.php
index b1c7e5a878dc168fb529fd7f8e0a60b9c508ef06..db15aa446b640c32f9e481c7d4396fd59aaf80b6 100755 (executable)
                $iInstances = getProcessorCount();
                echo "WARNING: resetting threads to $iInstances\n";
        }
+
+       // Assume we can steal all the cache memory in the box (unless told otherwise)
+       $iCacheMemory = (isset($aCMDResult['osm2pgsql-cache'])?$aCMDResult['osm2pgsql-cache']:getCacheMemoryMB());
+       if ($iCacheMemory > getTotalMemoryMB())
+       {
+               $iCacheMemory = getCacheMemoryMB();
+               echo "WARNING: resetting cache memory to $iCacheMemory\n";
+       }
+
        if (isset($aCMDResult['osm-file']) && !isset($aCMDResult['osmosis-init-date']))
        {
                $sBaseFile = basename($aCMDResult['osm-file']);
@@ -83,7 +92,7 @@
 
                $oDB =& getDB();
                passthru('createlang plpgsql '.$aDSNInfo['database']);
-        $pgver = (float) CONST_Postgresql_Version;
+               $pgver = (float) CONST_Postgresql_Version;
                if ($pgver < 9.1) {
                        pgsqlRunScriptFile(CONST_Path_Postgresql_Contrib.'/hstore.sql');
                } else {
                $osm2pgsql = CONST_Osm2pgsql_Binary;
                if (!file_exists($osm2pgsql)) fail("please download and build osm2pgsql");
                $osm2pgsql .= ' -lsc -O gazetteer --hstore';
-               if (isset($aCMDResult['osm2pgsql-cache']))
-               {
-                       $osm2pgsql .= ' -C '.$aCMDResult['osm2pgsql-cache'];
-               }
-               else
-               {
-                       $osm2pgsql .= ' -C 15000';
-               }
+               $osm2pgsql .= ' -C '.$iCacheMemory;
                $osm2pgsql .= ' -d '.$aDSNInfo['database'].' '.$aCMDResult['osm-file'];
                passthru($osm2pgsql);
 
                $oDB =& getDB();
                $x = $oDB->getRow('select * from place limit 1');
-               if (!$x || PEAR::isError($x)) fail('No Data');
+               if (PEAR::isError($x)) {
+                       fail($x->getMessage());
+               }
+               if (!$x) fail('No Data');
        }
 
        if ($aCMDResult['create-functions'] || $aCMDResult['all'])
        if (($aCMDResult['osmosis-init'] || $aCMDResult['all']) && isset($aCMDResult['osmosis-init-date']))
        {
                $bDidSomething = true;
+               $oDB =& getDB();
 
                if (!file_exists(CONST_Osmosis_Binary)) fail("please download osmosis");
                if (file_exists(CONST_BasePath.'/settings/configuration.txt')) echo "settings/configuration.txt already exists\n";
                else passthru(CONST_Osmosis_Binary.' --read-replication-interval-init '.CONST_BasePath.'/settings');
 
                $sDate = $aCMDResult['osmosis-init-date'];
-               $sURL = 'http://toolserver.org/~mazder/replicate-sequences/?'.$sDate;
+               $aDate = date_parse_from_format("Y-m-d\TH-i", $sDate);
+               $sURL = 'http://toolserver.org/~mazder/replicate-sequences/?';
+               $sURL .= 'Y='.$aDate['year'].'&m='.$aDate['month'].'&d='.$aDate['day'];
+               $sURL .= '&H='.$aDate['hour'].'&i='.$aDate['minute'].'&s=0';
+               $sURL .= '&stream=minute';
                echo "Getting state file: $sURL\n";
                $sStateFile = file_get_contents($sURL);
                if (!$sStateFile || strlen($sStateFile) > 1000) fail("unable to obtain state file");
                file_put_contents(CONST_BasePath.'/settings/state.txt', $sStateFile);
+               echo "Updating DB status\n";
+               pg_query($oDB->connection, 'TRUNCATE import_status');
+               $sSQL = "INSERT INTO import_status VALUES('".$sDate."')";
+               pg_query($oDB->connection, $sSQL);
+
        }
 
        if ($aCMDResult['index'] || $aCMDResult['all'])