3 require_once(CONST_BasePath.'/lib/init-cmd.php');
 
  11 $print_success = function ($message = 'OK') use ($term_colors) {
 
  12     echo $term_colors['green'].$message.$term_colors['normal']."\n";
 
  15 $print_fail = function ($message = 'Failed') use ($term_colors) {
 
  16     echo $term_colors['red'].$message.$term_colors['normal']."\n";
 
  20 $oDB = new Nominatim\DB;
 
  23 function isReverseOnlyInstallation()
 
  26     return !$oDB->tableExists('search_name');
 
  30 echo 'Checking database got created ... ';
 
  31 if ($oDB->databaseExists()) {
 
  37     * Is the database server started?
 
  38     * Check the CONST_Database_DSN variable in build/settings/local.php
 
  39     * Try connecting to the database with the same settings
 
  46 echo 'Checking nominatim.so module installed ... ';
 
  47 $sStandardWord = $oDB->getOne("SELECT make_standard_name('a')");
 
  48 if ($sStandardWord === 'a') {
 
  53     The Postgresql extension nominatim.so was not found in the database.
 
  55     * Check the output of the CMmake/make installation step
 
  56     * Does nominatim.so exist?
 
  57     * Does nominatim.so exist on the database server?
 
  58     * Can nominatim.so be accessed by the database user?
 
  64 echo 'Checking place table ... ';
 
  65 if ($oDB->tableExists('place')) {
 
  70     * The import didn't finish.
 
  72     * Check the output of the utils/setup.php you ran.
 
  73     Usually the osm2pgsql step failed. Check for errors related to
 
  74     * the file you imported not containing any places
 
  77     * osm2pgsql killed by other scripts, for consuming to much memory
 
  85 echo 'Checking indexing status ... ';
 
  86 $iUnindexed = $oDB->getOne('SELECT count(*) FROM placex WHERE indexed_status > 0');
 
  87 if ($iUnindexed == 0) {
 
  92     The indexing didn't finish. There is still $iUnindexed places. See the
 
  93     question 'Can a stopped/killed import process be resumed?' in the
 
  94     troubleshooting guide.
 
 100 echo "Search index creation\n";
 
 101 $aExpectedIndices = array(
 
 102     // sql/indices.src.sql
 
 104     'idx_place_addressline_address_place_id',
 
 105     'idx_placex_rank_search',
 
 106     'idx_placex_rank_address',
 
 107     'idx_placex_pendingsector',
 
 108     'idx_placex_parent_place_id',
 
 109     'idx_placex_geometry_reverse_lookuppoint',
 
 110     'idx_placex_geometry_reverse_lookuppolygon',
 
 111     'idx_placex_geometry_reverse_placenode',
 
 112     'idx_location_area_country_place_id',
 
 113     'idx_osmline_parent_place_id',
 
 114     'idx_osmline_parent_osm_id',
 
 115     'idx_place_osm_unique',
 
 117     'idx_postcode_postcode'
 
 119 if (!isReverseOnlyInstallation()) {
 
 120     $aExpectedIndices = array_merge($aExpectedIndices, array(
 
 121         // sql/indices_search.src.sql
 
 122         'idx_search_name_nameaddress_vector',
 
 123         'idx_search_name_name_vector',
 
 124         'idx_search_name_centroid'
 
 128 foreach ($aExpectedIndices as $sExpectedIndex) {
 
 129     echo "Checking index $sExpectedIndex ... ";
 
 130     if ($oDB->indexExists($sExpectedIndex)) {
 
 136         * Rerun the setup.php --create-search-indices step
 
 143 echo 'Checking search indices are valid ... ';
 
 146     FROM pg_class, pg_index
 
 147     WHERE pg_index.indisvalid = false
 
 148       AND pg_index.indexrelid = pg_class.oid;
 
 150 $aInvalid = $oDB->getCol($sSQL);
 
 151 if (empty($aInvalid)) {
 
 156     At least one index is invalid. That can happen, e.g. when index creation was
 
 157     disrupted and later restarted. You should delete the affected indices and
 
 158     run the index stage of setup again.
 
 159     See the question 'Can a stopped/killed import process be resumed?' in the
 
 160     troubleshooting guide.
 
 163     echo join(', ', $aInvalid) . "\n";
 
 169 if (CONST_Use_US_Tiger_Data) {
 
 170     echo 'Checking TIGER table exists ... ';
 
 171     if ($oDB->tableExists('location_property_tiger')) {
 
 176         Table 'location_property_tiger' does not exist. Run the TIGER data