]> git.openstreetmap.org Git - nominatim.git/blob - utils/setup.php
moving comment to right position
[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 // ->indirect via init-cmd.php->/lib/cmd.php                for runWithEnv, getCmdOpt
7 // ->indirect via init-cmd.php->/lib/init.php->db.php       for &getDB()
8
9 require_once(CONST_BasePath.'/lib/classes/SetupClass.php');
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 }
29
30 // osmosis init is no longer supported
31 if ($aCMDResult['osmosis-init']) {
32     $bDidSomething = true;
33     echo "Command 'osmosis-init' no longer available, please use utils/update.php --init-updates.\n";
34 }
35
36 // ******************************************************
37 // instantiate Setup class
38 $cSetup = new SetupFunctions($aCMDResult);
39
40 // *******************************************************
41 // go through complete process if 'all' is selected or start selected functions
42 if ($aCMDResult['create-db'] || $aCMDResult['all']) {
43     $bDidSomething = true;
44     $cSetup->createDB();
45 }
46
47 if ($aCMDResult['setup-db'] || $aCMDResult['all']) {
48     $bDidSomething = true;
49     $cSetup->setupDB();
50 }
51
52 // Try accessing the C module, so we know early if something is wrong
53 if (!checkModulePresence()) {
54     fail('error loading nominatim.so module');
55 }
56
57 if ($aCMDResult['import-data'] || $aCMDResult['all']) {
58     $bDidSomething = true;
59     $cSetup->importData($aCMDResult['osm-file']);
60 }
61
62 if ($aCMDResult['create-functions'] || $aCMDResult['all']) {
63     $bDidSomething = true;
64     $cSetup->createFunctions();
65 }
66
67 if ($aCMDResult['create-tables'] || $aCMDResult['all']) {
68     $bDidSomething = true;
69     $cSetup->createTables();
70     $cSetup->createFunctions();
71 }
72
73 if ($aCMDResult['create-partition-tables'] || $aCMDResult['all']) {
74     $bDidSomething = true;
75     $cSetup->createPartitionTables();
76 }
77
78 if ($aCMDResult['create-partition-functions'] || $aCMDResult['all']) {
79     $bDidSomething = true;
80     $cSetup->createPartitionFunctions();
81 }
82
83 if ($aCMDResult['import-wikipedia-articles'] || $aCMDResult['all']) {
84     $bDidSomething = true;
85     $cSetup->importWikipediaArticles();
86 }
87
88 if ($aCMDResult['load-data'] || $aCMDResult['all']) {
89     $bDidSomething = true;
90     $cSetup->loadData($aCMDResult['disable-token-precalc']);
91 }
92
93 if ($aCMDResult['import-tiger-data']) {
94     $bDidSomething = true;
95     $cSetup->importTigerData();
96 }
97
98 if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) {
99     $bDidSomething = true;
100     $cSetup->calculatePostcodes($aCMDResult['all']);
101 }
102
103 if ($aCMDResult['index'] || $aCMDResult['all']) {
104     $bDidSomething = true;
105     $cSetup->index($aCMDResult['index-noanalyse']);
106 }
107
108 if ($aCMDResult['create-search-indices'] || $aCMDResult['all']) {
109     $bDidSomething = true;
110     $cSetup->createSearchIndices();
111 }
112
113 if ($aCMDResult['create-country-names'] || $aCMDResult['all']) {
114     $bDidSomething = true;
115     $cSetup->createCountryNames($aCMDResult);
116 }
117
118 if ($aCMDResult['drop']) {
119     $bDidSomething = true;
120     $cSetup->drop($aCMDResult);
121 }
122
123 // ******************************************************
124 // If we did something, repeat the warnings
125 if (!$bDidSomething) {
126     showUsage($aCMDOptions, true);
127 } else {
128     echo "Summary of warnings:\n\n";
129     repeatWarnings();
130     echo "\n";
131     info('Setup finished.');
132 }