[4/5] locations-functions.pl: Allow get_locations() function to skip special locations.

Message ID 20201107184724.3590-4-stefan.schantl@ipfire.org
State Accepted
Commit 427190d5789b02331cb91d72f0fb7f97374a0aa0
Headers
Series [1/5] location-functions.pl: Use a single script-wide db_handle. |

Commit Message

Stefan Schantl Nov. 7, 2020, 6:47 p.m. UTC
  When adding "no_special_locations" to the function call as argument
the special locations liks "A1, A2, A3 etc" will not be added to the
returned array as available locations.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
 config/cfgroot/location-functions.pl | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
  

Comments

Michael Tremer Nov. 9, 2020, 11:49 a.m. UTC | #1
Hi,

Where is this being used?

-Michael

> On 7 Nov 2020, at 18:47, Stefan Schantl <stefan.schantl@ipfire.org> wrote:
> 
> When adding "no_special_locations" to the function call as argument
> the special locations liks "A1, A2, A3 etc" will not be added to the
> returned array as available locations.
> 
> Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
> ---
> config/cfgroot/location-functions.pl | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/config/cfgroot/location-functions.pl b/config/cfgroot/location-functions.pl
> index e8db4ba9b..fdf2c6efe 100644
> --- a/config/cfgroot/location-functions.pl
> +++ b/config/cfgroot/location-functions.pl
> @@ -177,16 +177,24 @@ sub get_full_country_name($) {
> 
> # Function to get all available locations.
> sub get_locations() {
> +	my ($mode) = @_;
> +
> +	# Set default mode to add_special_locations.
> +	$mode = $mode ? $mode : "add_special_locations";
> +
> 	# Get locations which are stored in the location database.
> -	my @database_locations = &Location::database_countries($db_handle);
> +	my @locations = &Location::database_countries($db_handle);
> 
> -	# Merge special locations array and the database locations array.
> -	my @locations = (@special_locations, @database_locations);
> +	# Check if the special locations should be added.
> +	if ($mode ne "no_special_locations") {
> +		# Merge special locations array and the database locations array.
> +		@locations = (@special_locations, @locations);
> +	}
> 
> 	# Sort locations array in alphabetical order.
> 	my @sorted_locations = sort(@locations);
> 
> -	# Return the array..
> +	# Return the array.
> 	return @sorted_locations;
> }
> 
> -- 
> 2.20.1
>
  

Patch

diff --git a/config/cfgroot/location-functions.pl b/config/cfgroot/location-functions.pl
index e8db4ba9b..fdf2c6efe 100644
--- a/config/cfgroot/location-functions.pl
+++ b/config/cfgroot/location-functions.pl
@@ -177,16 +177,24 @@  sub get_full_country_name($) {
 
 # Function to get all available locations.
 sub get_locations() {
+	my ($mode) = @_;
+
+	# Set default mode to add_special_locations.
+	$mode = $mode ? $mode : "add_special_locations";
+
 	# Get locations which are stored in the location database.
-	my @database_locations = &Location::database_countries($db_handle);
+	my @locations = &Location::database_countries($db_handle);
 
-	# Merge special locations array and the database locations array.
-	my @locations = (@special_locations, @database_locations);
+	# Check if the special locations should be added.
+	if ($mode ne "no_special_locations") {
+		# Merge special locations array and the database locations array.
+		@locations = (@special_locations, @locations);
+	}
 
 	# Sort locations array in alphabetical order.
 	my @sorted_locations = sort(@locations);
 
-	# Return the array..
+	# Return the array.
 	return @sorted_locations;
 }