simplify constructor of SetupFunctions

Also cleans up spacing.
This commit is contained in:
Sarah Hoffmann
2018-10-02 22:59:10 +02:00
parent f45b3fa3f2
commit 3afd12f977
3 changed files with 68 additions and 72 deletions

View File

@@ -16,14 +16,13 @@ class SetupFunctions
protected $oDB = null; // set in setupDB (earliest) or later in loadData, importData, drop, createSqlFunctions, importTigerData protected $oDB = null; // set in setupDB (earliest) or later in loadData, importData, drop, createSqlFunctions, importTigerData
// pgsqlRunPartitionScript, calculatePostcodes, ..if no already set // pgsqlRunPartitionScript, calculatePostcodes, ..if no already set
public function __construct($callingFunction, array $aCMDResult = array()) public function __construct(array $aCMDResult)
{ {
// by default, use all but one processor, but never more than 15. // by default, use all but one processor, but never more than 15.
$this->iInstances = isset($aCMDResult['threads']) $this->iInstances = isset($aCMDResult['threads'])
? $aCMDResult['threads'] ? $aCMDResult['threads']
: (min(16, getProcessorCount()) - 1); : (min(16, getProcessorCount()) - 1);
if ($this->iInstances < 1) { if ($this->iInstances < 1) {
$this->iInstances = 1; $this->iInstances = 1;
warn('resetting threads to '.$this->iInstances); warn('resetting threads to '.$this->iInstances);
@@ -62,13 +61,10 @@ class SetupFunctions
} else { } else {
$this->bNoPartitions = false; $this->bNoPartitions = false;
} }
if (isset($aCMDResult['enable-diff-updates'])) {
// if class is instantiated by update.php, we have to set EnableDiffUpdates to true
// otherwise set to value provided by setup.php's command line arg array
if ($callingFunction == 'update') {
$this->bEnableDiffUpdates = true;
} elseif ($callingFunction == 'setup') {
$this->bEnableDiffUpdates = $aCMDResult['enable-diff-updates']; $this->bEnableDiffUpdates = $aCMDResult['enable-diff-updates'];
} else {
$this->bEnableDiffUpdates = false;
} }
} }
@@ -158,7 +154,6 @@ class SetupFunctions
$this->pgsqlRunScriptFile(CONST_BasePath.'/data/country_osm_grid.sql.gz'); $this->pgsqlRunScriptFile(CONST_BasePath.'/data/country_osm_grid.sql.gz');
$this->pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_table.sql'); $this->pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_table.sql');
if (file_exists(CONST_BasePath.'/data/gb_postcode_data.sql.gz')) { if (file_exists(CONST_BasePath.'/data/gb_postcode_data.sql.gz')) {
$this->pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_data.sql.gz'); $this->pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_data.sql.gz');
} else { } else {
@@ -192,8 +187,6 @@ class SetupFunctions
fail("osm2pgsql not found in '$osm2pgsql'"); fail("osm2pgsql not found in '$osm2pgsql'");
} }
if (!is_null(CONST_Osm2pgsql_Flatnode_File) && CONST_Osm2pgsql_Flatnode_File) { if (!is_null(CONST_Osm2pgsql_Flatnode_File) && CONST_Osm2pgsql_Flatnode_File) {
$osm2pgsql .= ' --flat-nodes '.CONST_Osm2pgsql_Flatnode_File; $osm2pgsql .= ' --flat-nodes '.CONST_Osm2pgsql_Flatnode_File;
} }

View File

@@ -48,7 +48,7 @@ $aCMDOptions
array('create-search-indices', '', 0, 1, 0, 0, 'bool', 'Create additional indices required for search and update'), array('create-search-indices', '', 0, 1, 0, 0, 'bool', 'Create additional indices required for search and update'),
array('create-country-names', '', 0, 1, 0, 0, 'bool', 'Create default list of searchable country names'), array('create-country-names', '', 0, 1, 0, 0, 'bool', 'Create default list of searchable country names'),
array('drop', '', 0, 1, 0, 0, 'bool', 'Drop tables needed for updates, making the database readonly (EXPERIMENTAL)'), array('drop', '', 0, 1, 0, 0, 'bool', 'Drop tables needed for updates, making the database readonly (EXPERIMENTAL)'),
); );
// $aCMDOptions passed to getCmdOpt by reference // $aCMDOptions passed to getCmdOpt by reference
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true); getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
@@ -71,7 +71,7 @@ if ($aCMDResult['osmosis-init']) {
// ****************************************************** // ******************************************************
// instantiate Setup class // instantiate Setup class
$cSetup = new SetupFunctions('setup', $aCMDResult); $cSetup = new SetupFunctions($aCMDResult);
// ******************************************************* // *******************************************************
// go through complete process if 'all' is selected or start selected functions // go through complete process if 'all' is selected or start selected functions

View File

@@ -43,7 +43,7 @@ $aCMDOptions
array('deduplicate', '', 0, 1, 0, 0, 'bool', 'Deduplicate tokens'), array('deduplicate', '', 0, 1, 0, 0, 'bool', 'Deduplicate tokens'),
array('recompute-word-counts', '', 0, 1, 0, 0, 'bool', 'Compute frequency of full-word search terms'), array('recompute-word-counts', '', 0, 1, 0, 0, 'bool', 'Compute frequency of full-word search terms'),
array('no-npi', '', 0, 1, 0, 0, 'bool', '(obsolete)'), array('no-npi', '', 0, 1, 0, 0, 'bool', '(obsolete)'),
); );
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true); getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
@@ -106,7 +106,10 @@ if ($aResult['init-updates']) {
if (!$aResult['no-update-functions']) { if (!$aResult['no-update-functions']) {
// instantiate setupClass to use the function therein // instantiate setupClass to use the function therein
$cSetup = new SetupFunctions('update'); $cSetup = new SetupFunctions(array(
'enable-diff-updates' => true,
'verbose' => $aResult['verbose']
));
$cSetup->createFunctions(); $cSetup->createFunctions();
} }