]> git.openstreetmap.org Git - nominatim.git/blob - utils/setup.php
format change revert, removed bogus CL options, SetupClass to a new dir
[nominatim.git] / utils / setup.php
1 #!@PHP_BIN@ -Cq
2 <?php
3
4 require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
5 require_once(CONST_BasePath.'/lib/init-cmd.php');
6 require_once(CONST_BasePath.'/lib/classes/SetupClass.php');
7 // ->indirect via init-cmd.php->/lib/cmd.php                  for runWithEnv, getCmdOpt
8 // ->indirect via init-cmd.php->/lib/init.php->db.php       for &getDB()
9 require_once(CONST_BasePath.'/lib/setup_functions.php');
10 ini_set('memory_limit', '800M');
11
12 use Nominatim\Setup\SetupFunctions as SetupFunctions;
13
14 $aCMDOptions = createSetupArgvArray();
15
16 // $aCMDOptions passed to getCmdOpt by reference
17 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
18
19 $bDidSomething = false;
20
21 //*******************************************************
22 // Making some sanity check:
23 // Check if osm-file is set and points to a valid file
24 if ($aCMDResult['import-data'] || $aCMDResult['all']) {
25     // to remain in /lib/setup_functions.php function
26     checkInFile($aCMDResult['osm-file']);
27 }
28
29 // osmosis init is no longer supported
30 if ($aCMDResult['osmosis-init']) {
31     $bDidSomething = true;
32     echo "Command 'osmosis-init' no longer available, please use utils/update.php --init-updates.\n";
33 }
34
35 // ******************************************************
36 // instantiate Setup class
37 $cSetup = new SetupFunctions($aCMDResult);
38
39 // *******************************************************
40 // go through complete process if 'all' is selected or start selected functions
41 if ($aCMDResult['create-db'] || $aCMDResult['all']) {
42     $bDidSomething = true;
43     $cSetup->createDB();
44 }
45
46 if ($aCMDResult['setup-db'] || $aCMDResult['all']) {
47     $bDidSomething = true;
48     $cSetup->setupDB();
49 }
50
51 // Try accessing the C module, so we know early if something is wrong
52 if (!checkModulePresence()) {
53     fail('error loading nominatim.so module');
54 }
55
56 if ($aCMDResult['import-data'] || $aCMDResult['all']) {
57     $bDidSomething = true;
58     $cSetup->importData($aCMDResult['osm-file']);
59 }
60
61 if ($aCMDResult['create-functions'] || $aCMDResult['all']) {
62     $bDidSomething = true;
63     $cSetup->createFunctions();
64 }
65
66 if ($aCMDResult['create-tables'] || $aCMDResult['all']) {
67     $bDidSomething = true;
68     $cSetup->createTables();
69     $cSetup->createFunctions();
70 }
71
72 if ($aCMDResult['create-partition-tables'] || $aCMDResult['all']) {
73     $bDidSomething = true;
74     $cSetup->createPartitionTables();
75 }
76
77 if ($aCMDResult['create-partition-functions'] || $aCMDResult['all']) {
78     $bDidSomething = true;
79     $cSetup->createPartitionFunctions();
80 }
81
82 if ($aCMDResult['import-wikipedia-articles'] || $aCMDResult['all']) {
83     $bDidSomething = true;
84     $cSetup->importWikipediaArticles();
85 }
86
87 if ($aCMDResult['load-data'] || $aCMDResult['all']) {
88     $bDidSomething = true;
89     $cSetup->loadData($aCMDResult['disable-token-precalc']);
90 }
91
92 if ($aCMDResult['import-tiger-data']) {
93     $bDidSomething = true;
94     $cSetup->importTigerData();
95 }
96
97 if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) {
98     $bDidSomething = true;
99     $cSetup->calculatePostcodes($aCMDResult['all']);
100 }
101
102 if ($aCMDResult['index'] || $aCMDResult['all']) {
103     $bDidSomething = true;
104     $cSetup->index($aCMDResult['index-noanalyse']);
105 }
106
107 if ($aCMDResult['create-search-indices'] || $aCMDResult['all']) {
108     $bDidSomething = true;
109     $cSetup->createSearchIndices();
110 }
111
112 if ($aCMDResult['create-country-names'] || $aCMDResult['all']) {
113     $bDidSomething = true;
114     $cSetup->createCountryNames($aCMDResult);
115 }
116
117 if ($aCMDResult['drop']) {
118     $bDidSomething = true;
119     $cSetup->drop($aCMDResult);
120 }
121
122 // ******************************************************
123 // If we did something, repeat the warnings
124 if (!$bDidSomething) {
125     showUsage($aCMDOptions, true);
126 } else {
127     echo "Summary of warnings:\n\n";
128     repeatWarnings();
129     echo "\n";
130     info('Setup finished.');
131 }