4 require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
5 require_once(CONST_BasePath.'/lib/init-cmd.php');
6 include_once(CONST_InstallPath.'/utils/setup_functions.php');
7 ini_set('memory_limit', '800M');
9 # (long-opt, short-opt, min-occurs, max-occurs, num-arguments, num-arguments, type, help)
13 'Create and setup nominatim search system',
14 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
15 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
16 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
18 array('osm-file', '', 0, 1, 1, 1, 'realpath', 'File to import'),
19 array('threads', '', 0, 1, 1, 1, 'int', 'Number of threads (where possible)'),
21 array('all', '', 0, 1, 0, 0, 'bool', 'Do the complete process'),
23 array('create-db', '', 0, 1, 0, 0, 'bool', 'Create nominatim db'),
24 array('setup-db', '', 0, 1, 0, 0, 'bool', 'Build a blank nominatim db'),
25 array('import-data', '', 0, 1, 0, 0, 'bool', 'Import a osm file'),
26 array('osm2pgsql-cache', '', 0, 1, 1, 1, 'int', 'Cache size used by osm2pgsql'),
27 array('create-functions', '', 0, 1, 0, 0, 'bool', 'Create functions'),
28 array('enable-diff-updates', '', 0, 1, 0, 0, 'bool', 'Turn on the code required to make diff updates work'),
29 array('enable-debug-statements', '', 0, 1, 0, 0, 'bool', 'Include debug warning statements in pgsql commands'),
30 array('ignore-errors', '', 0, 1, 0, 0, 'bool', 'Continue import even when errors in SQL are present (EXPERT)'),
31 array('create-tables', '', 0, 1, 0, 0, 'bool', 'Create main tables'),
32 array('create-partition-tables', '', 0, 1, 0, 0, 'bool', 'Create required partition tables'),
33 array('create-partition-functions', '', 0, 1, 0, 0, 'bool', 'Create required partition triggers'),
34 array('no-partitions', '', 0, 1, 0, 0, 'bool', 'Do not partition search indices (speeds up import of single country extracts)'),
35 array('import-wikipedia-articles', '', 0, 1, 0, 0, 'bool', 'Import wikipedia article dump'),
36 array('load-data', '', 0, 1, 0, 0, 'bool', 'Copy data to live tables from import table'),
37 array('disable-token-precalc', '', 0, 1, 0, 0, 'bool', 'Disable name precalculation (EXPERT)'),
38 array('import-tiger-data', '', 0, 1, 0, 0, 'bool', 'Import tiger data (not included in \'all\')'),
39 array('calculate-postcodes', '', 0, 1, 0, 0, 'bool', 'Calculate postcode centroids'),
40 array('osmosis-init', '', 0, 1, 0, 0, 'bool', 'Generate default osmosis configuration'),
41 array('index', '', 0, 1, 0, 0, 'bool', 'Index the data'),
42 array('index-noanalyse', '', 0, 1, 0, 0, 'bool', 'Do not perform analyse operations during index (EXPERT)'),
43 array('create-search-indices', '', 0, 1, 0, 0, 'bool', 'Create additional indices required for search and update'),
44 array('create-country-names', '', 0, 1, 0, 0, 'bool', 'Create default list of searchable country names'),
45 array('drop', '', 0, 1, 0, 0, 'bool', 'Drop tables needed for updates, making the database readonly (EXPERIMENTAL)'),
47 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
49 $bDidSomething = false;
51 // Check if osm-file is set and points to a valid file if --all or --import-data is given
52 checkInFile($aCMDResult);
54 // get info how many processors and huch much cache mem we can use
55 $prepSreturn = prepSystem($aCMDResult);
56 $iCacheMemory = $prepSreturn[0];
57 $iInstances = $prepSreturn[1];
59 // prepares DB for import or update, returns Data Source Name
60 $aDSNInfo = prepDB($aCMDResult);
62 if ($aCMDResult['import-data'] || $aCMDResult['all']) {
63 $bDidSomething = true;
64 import_data($aCMDResult, $iCacheMemory, $aDSNInfo);
67 if ($aCMDResult['create-functions'] || $aCMDResult['all']) {
68 $bDidSomething = true;
69 create_functions($aCMDResult);
72 if ($aCMDResult['create-tables'] || $aCMDResult['all']) {
73 $bDidSomething = true;
74 create_tables($aCMDResult);
77 if ($aCMDResult['create-partition-tables'] || $aCMDResult['all']) {
78 $bDidSomething = true;
79 create_partition_tables($aCMDResult);
82 if ($aCMDResult['create-partition-functions'] || $aCMDResult['all']) {
83 $bDidSomething = true;
84 create_partition_functions();
87 if ($aCMDResult['import-wikipedia-articles'] || $aCMDResult['all']) {
88 $bDidSomething = true;
89 import_wikipedia_articles();
93 if ($aCMDResult['load-data'] || $aCMDResult['all']) {
94 $bDidSomething = true;
95 load_data($aCMDResult, $iInstances);
98 if ($aCMDResult['import-tiger-data']) {
99 $bDidSomething = true;
100 import_tiger_data($iInstances);
103 if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) {
104 $bDidSomething = true;
105 calculate_postcodes($aCMDResult);
108 if ($aCMDResult['osmosis-init']) {
109 $bDidSomething = true;
113 if ($aCMDResult['index'] || $aCMDResult['all']) {
114 $bDidSomething = true;
115 index($aCMDResult, $aDSNInfo, $iInstances);
118 if ($aCMDResult['create-search-indices'] || $aCMDResult['all']) {
119 $bDidSomething = true;
120 create_search_indices($aCMDResult);
123 if ($aCMDResult['create-country-names'] || $aCMDResult['all']) {
124 $bDidSomething = true;
125 create_country_names();
128 if ($aCMDResult['drop']) {
129 $bDidSomething = true;
133 didsomething($bDidSomething);