]> git.openstreetmap.org Git - nominatim.git/blob - lib/setup_functions.php
move checkModilePresence to class, delete own debug echo
[nominatim.git] / lib / setup_functions.php
1 <?php
2
3 function checkInFile($sOSMFile)
4 {
5     if (!isset($sOSMFile)) {
6         fail('missing --osm-file for data import');
7     }
8
9     if (!file_exists($sOSMFile)) {
10         fail('the path supplied to --osm-file does not exist');
11     }
12
13     if (!is_readable($sOSMFile)) {
14         fail('osm-file "' . $aCMDResult['osm-file'] . '" not readable');
15     }
16 }
17
18 function checkModulePresence()
19 {
20     // Try accessing the C module, so we know early if something is wrong
21     // and can simply error out.
22     $sModulePath = CONST_Database_Module_Path;
23     $sSQL = "CREATE FUNCTION nominatim_test_import_func(text) RETURNS text AS '";
24     $sSQL .= $sModulePath . "/nominatim.so', 'transliteration' LANGUAGE c IMMUTABLE STRICT";
25     $sSQL .= ';DROP FUNCTION nominatim_test_import_func(text);';
26
27     $oDB = &getDB();
28     $oResult = $oDB->query($sSQL);
29
30     $bResult = true;
31
32     if (PEAR::isError($oResult)) {
33         echo "\nERROR: Failed to load nominatim module. Reason:\n";
34         echo $oResult->userinfo . "\n\n";
35         $bResult = false;
36     }
37
38     return $bResult;
39 }
40
41 // (long-opt, short-opt, min-occurs, max-occurs, num-arguments, num-arguments, type, help)
42 // create and array
43 function createSetupArgvArray()
44 {
45     $aCMDOptions
46     = array(
47         'Create and setup nominatim search system',
48         array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
49         array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
50         array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
51
52         array('osm-file', '', 0, 1, 1, 1, 'realpath', 'File to import'),
53         array('threads', '', 0, 1, 1, 1, 'int', 'Number of threads (where possible)'),
54
55         array('all', '', 0, 1, 0, 0, 'bool', 'Do the complete process'),
56
57         array('create-db', '', 0, 1, 0, 0, 'bool', 'Create nominatim db'),
58         array('setup-db', '', 0, 1, 0, 0, 'bool', 'Build a blank nominatim db'),
59         array('import-data', '', 0, 1, 0, 0, 'bool', 'Import a osm file'),
60         array('osm2pgsql-cache', '', 0, 1, 1, 1, 'int', 'Cache size used by osm2pgsql'),
61         array('create-functions', '', 0, 1, 0, 0, 'bool', 'Create functions'),
62         array('enable-diff-updates', '', 0, 1, 0, 0, 'bool', 'Turn on the code required to make diff updates work'),
63         array('enable-debug-statements', '', 0, 1, 0, 0, 'bool', 'Include debug warning statements in pgsql commands'),
64         array('ignore-errors', '', 0, 1, 0, 0, 'bool', 'Continue import even when errors in SQL are present (EXPERT)'),
65         array('create-tables', '', 0, 1, 0, 0, 'bool', 'Create main tables'),
66         array('create-partition-tables', '', 0, 1, 0, 0, 'bool', 'Create required partition tables'),
67         array('create-partition-functions', '', 0, 1, 0, 0, 'bool', 'Create required partition triggers'),
68         array('no-partitions', '', 0, 1, 0, 0, 'bool', 'Do not partition search indices (speeds up import of single country extracts)'),
69         array('import-wikipedia-articles', '', 0, 1, 0, 0, 'bool', 'Import wikipedia article dump'),
70         array('load-data', '', 0, 1, 0, 0, 'bool', 'Copy data to live tables from import table'),
71         array('disable-token-precalc', '', 0, 1, 0, 0, 'bool', 'Disable name precalculation (EXPERT)'),
72         array('import-tiger-data', '', 0, 1, 0, 0, 'bool', 'Import tiger data (not included in \'all\')'),
73         array('calculate-postcodes', '', 0, 1, 0, 0, 'bool', 'Calculate postcode centroids'),
74         array('osmosis-init', '', 0, 1, 0, 0, 'bool', 'Generate default osmosis configuration'),
75         array('index', '', 0, 1, 0, 0, 'bool', 'Index the data'),
76         array('index-noanalyse', '', 0, 1, 0, 0, 'bool', 'Do not perform analyse operations during index (EXPERT)'),
77         array('create-search-indices', '', 0, 1, 0, 0, 'bool', 'Create additional indices required for search and update'),
78         array('create-country-names', '', 0, 1, 0, 0, 'bool', 'Create default list of searchable country names'),
79         array('drop', '', 0, 1, 0, 0, 'bool', 'Drop tables needed for updates, making the database readonly (EXPERIMENTAL)'),
80     );
81     return $aCMDOptions;
82 }
83
84 function createUpdateArgvArray()
85 {
86     $aCMDOptions
87     = array(
88         'Import / update / index osm data',
89         array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
90         array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
91         array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
92
93         array('init-updates', '', 0, 1, 0, 0, 'bool', 'Set up database for updating'),
94         array('check-for-updates', '', 0, 1, 0, 0, 'bool', 'Check if new updates are available'),
95         array('no-update-functions', '', 0, 1, 0, 0, 'bool', 'Do not update trigger functions to support differential updates (assuming the diff update logic is already present)'),
96         array('import-osmosis', '', 0, 1, 0, 0, 'bool', 'Import updates once'),
97         array('import-osmosis-all', '', 0, 1, 0, 0, 'bool', 'Import updates forever'),
98         array('no-index', '', 0, 1, 0, 0, 'bool', 'Do not index the new data'),
99
100         array('calculate-postcodes', '', 0, 1, 0, 0, 'bool', 'Update postcode centroid table'),
101
102         array('import-file', '', 0, 1, 1, 1, 'realpath', 'Re-import data from an OSM file'),
103         array('import-diff', '', 0, 1, 1, 1, 'realpath', 'Import a diff (osc) file from local file system'),
104         array('osm2pgsql-cache', '', 0, 1, 1, 1, 'int', 'Cache size used by osm2pgsql'),
105
106         array('import-node', '', 0, 1, 1, 1, 'int', 'Re-import node'),
107         array('import-way', '', 0, 1, 1, 1, 'int', 'Re-import way'),
108         array('import-relation', '', 0, 1, 1, 1, 'int', 'Re-import relation'),
109         array('import-from-main-api', '', 0, 1, 0, 0, 'bool', 'Use OSM API instead of Overpass to download objects'),
110
111         array('index', '', 0, 1, 0, 0, 'bool', 'Index'),
112         array('index-rank', '', 0, 1, 1, 1, 'int', 'Rank to start indexing from'),
113         array('index-instances', '', 0, 1, 1, 1, 'int', 'Number of indexing instances (threads)'),
114
115         array('deduplicate', '', 0, 1, 0, 0, 'bool', 'Deduplicate tokens'),
116         array('recompute-word-counts', '', 0, 1, 0, 0, 'bool', 'Compute frequency of full-word search terms'),
117         array('no-npi', '', 0, 1, 0, 0, 'bool', '(obsolete)'),
118
119         array('create-functions', '', 0, 1, 1, 1, 'bool', 'Create functions'),
120         array('enable-diff-updates', '', 0, 1, 1, 1, 'bool', 'Turn on the code required to make diff updates work'),
121     );
122     return $aCMDOptions;
123 }