From 7dceea2df879a5bfeb1f86884b9d48f7a56e8a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Gigandet?= Date: Thu, 4 Nov 2021 10:17:43 +0100 Subject: [PATCH] fix: add countries correctly in scanbot (#6014) * fix: add countries correctly - fixes #4870 * remove useless code --- scripts/scanbot.pl | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/scripts/scanbot.pl b/scripts/scanbot.pl index 2fec723edf9dd..72d04472848dc 100755 --- a/scripts/scanbot.pl +++ b/scripts/scanbot.pl @@ -87,7 +87,6 @@ exit(); } - print STDERR "Running scanbot for year $year\n"; my %codes = (); @@ -332,8 +331,6 @@ $source = "producers"; } - $lc = $product_ref->{lc}; - $product_ref->{unique_scans_n} = $unique_scans_n + 0; $product_ref->{scans_n} = $scans_n + 0; @@ -379,9 +376,7 @@ } # Add countries tags based on scans - my $field = 'countries'; - - my $current_countries = $product_ref->{$field}; + my $current_countries = $product_ref->{'countries'}; my %existing = (); foreach my $countryid (@{$product_ref->{countries_tags}}) { @@ -417,7 +412,7 @@ # (codes can be reused by different companies in different countries) if (($add_countries) and ($code !~ /^(02|2)/) and (not exists $existing{$country})) { print "- adding $country to $product_ref->{countries}\n"; - $product_ref->{countries} .= ", $country"; + add_tags_to_field($product_ref, "en", "countries", $country); $bot .= "+$country "; $added_countries++; $added_countries_list .= $country .','; @@ -431,32 +426,10 @@ } } - if ($product_ref->{$field} ne $current_countries) { + if ($added_countries_list ne "") { $product_ref->{"countries_beforescanbot"} = $current_countries; $changed_products++; - if ($product_ref->{$field} =~ /^, /) { - $product_ref->{$field} = $'; - } - - if (defined $taxonomy_fields{$field}) { - $product_ref->{$field . "_hierarchy" } = [ gen_tags_hierarchy_taxonomy($lc, $field, $product_ref->{$field}) ]; - $product_ref->{$field . "_tags" } = []; - foreach my $tag (@{$product_ref->{$field . "_hierarchy" }}) { - push @{$product_ref->{$field . "_tags" }}, get_taxonomyid($lc, $tag); - } - } - - if (defined $hierarchy_fields{$field}) { - $product_ref->{$field . "_hierarchy" } = [ gen_tags_hierarchy($field, $product_ref->{$field}) ]; - $product_ref->{$field . "_tags" } = []; - foreach my $tag (@{$product_ref->{$field . "_hierarchy" }}) { - if (get_fileid($tag) ne '') { - push @{$product_ref->{$field . "_tags" }}, get_fileid($tag); - } - } - } - my $comment = $bot; if (0) { @@ -496,8 +469,7 @@ } } - $User_id = 'scanbot'; - store_product($product_ref, $comment); + store_product('scanbot', $product_ref, $comment); } else { print "updating scan count for $code\n";