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