From a1b73145d5bda6e40d67a787dedf10a3942639d7 Mon Sep 17 00:00:00 2001 From: Antoine B Date: Wed, 17 Jul 2024 18:34:22 +0200 Subject: [PATCH 1/4] feat: launch the exports for all organizations that have the checkbox checked --- ...ducers_platform_data_to_public_database.sh | 68 +++++++++++++------ 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/scripts/export_producers_platform_data_to_public_database.sh b/scripts/export_producers_platform_data_to_public_database.sh index 21ec0d7bf99b4..dba05390d716a 100755 --- a/scripts/export_producers_platform_data_to_public_database.sh +++ b/scripts/export_producers_platform_data_to_public_database.sh @@ -4,28 +4,52 @@ export PERL5LIB="lib:${PERL5LIB}" -PRODUCERS=( -org-barilla-france-sa -org-ferrero-france-commerciale -org-unilever-france-gms -org-unilever-france-rhd -org-nestle-france -org-panzani-sa -org-cristalco -org-materne -org-garofalo-france -org-brasseries-kronenbourg -org-carrefour -org-lustucru-frais -org-nestle-waters -org-kambly -org-kambly-france -org-saint-hubert -org-d-aucy -org-lea-nature -org-auchan-apaw -org-les-mousquetaires -) +PRODUCERS=() + +filter_organizations_that_have_automated_export() { + perl -e ' + use strict; + use warnings; + use ProductOpener::Orgs qw/list_org_ids retrieve_org/; + + my %producers = qw( + org-barilla-france-sa + org-ferrero-france-commerciale + org-unilever-france-gms + org-unilever-france-rhd + org-nestle-france + org-panzani-sa + org-cristalco + org-materne + org-garofalo-france + org-brasseries-kronenbourg + org-carrefour + org-lustucru-frais + org-nestle-waters + org-kambly + org-kambly-france + org-saint-hubert + org-d-aucy + org-lea-nature + org-auchan-apaw + org-les-mousquetaires + ); + + my @orgs = map { + "org-" . $_->{"org_id"} + } + grep { + exists $_->{"activate_automated_daily_export_to_public_platform"} + and $_->{"activate_automated_daily_export_to_public_platform"} eq "on" + } + map { retrieve_org($_) } list_org_ids(); + + $producers{$_} = undef for @orgs; + + print "$_\n" for keys %producers; + ' +} +PRODUCERS=$(filter_organizations_that_have_automated_export) for producer in ${PRODUCERS[@]} do From 6107e250bb30d5554b6e7785c588aa8993bec8c6 Mon Sep 17 00:00:00 2001 From: Antoine B Date: Wed, 17 Jul 2024 18:38:09 +0200 Subject: [PATCH 2/4] style --- scripts/export_producers_platform_data_to_public_database.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/export_producers_platform_data_to_public_database.sh b/scripts/export_producers_platform_data_to_public_database.sh index dba05390d716a..717a46c079f3b 100755 --- a/scripts/export_producers_platform_data_to_public_database.sh +++ b/scripts/export_producers_platform_data_to_public_database.sh @@ -4,8 +4,6 @@ export PERL5LIB="lib:${PERL5LIB}" -PRODUCERS=() - filter_organizations_that_have_automated_export() { perl -e ' use strict; @@ -49,6 +47,7 @@ filter_organizations_that_have_automated_export() { print "$_\n" for keys %producers; ' } + PRODUCERS=$(filter_organizations_that_have_automated_export) for producer in ${PRODUCERS[@]} From b2d3f18e9e2e7ca6ee43141a0a1066f90999669e Mon Sep 17 00:00:00 2001 From: Antoine B Date: Thu, 18 Jul 2024 16:31:51 +0200 Subject: [PATCH 3/4] fetch orgs from mongodb --- ...ducers_platform_data_to_public_database.sh | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/scripts/export_producers_platform_data_to_public_database.sh b/scripts/export_producers_platform_data_to_public_database.sh index 717a46c079f3b..5ee8c39adf2aa 100755 --- a/scripts/export_producers_platform_data_to_public_database.sh +++ b/scripts/export_producers_platform_data_to_public_database.sh @@ -8,9 +8,9 @@ filter_organizations_that_have_automated_export() { perl -e ' use strict; use warnings; - use ProductOpener::Orgs qw/list_org_ids retrieve_org/; + use ProductOpener::Data qw/get_orgs_collection/; - my %producers = qw( + my %producers = map { $_,1 } qw( org-barilla-france-sa org-ferrero-france-commerciale org-unilever-france-gms @@ -33,24 +33,19 @@ filter_organizations_that_have_automated_export() { org-les-mousquetaires ); - my @orgs = map { - "org-" . $_->{"org_id"} - } - grep { - exists $_->{"activate_automated_daily_export_to_public_platform"} - and $_->{"activate_automated_daily_export_to_public_platform"} eq "on" - } - map { retrieve_org($_) } list_org_ids(); + my @res = get_orgs_collection() + ->find({ activate_automated_daily_export_to_public_platform => "on" }) + ->fields({ org_id => 1 }) + ->all; - $producers{$_} = undef for @orgs; + $producers{"org-" . $_->{org_id}} = undef for @res; print "$_\n" for keys %producers; + ' } -PRODUCERS=$(filter_organizations_that_have_automated_export) - -for producer in ${PRODUCERS[@]} +for producer in $(filter_organizations_that_have_automated_export) do scripts/export_and_import_to_public_database.pl --query states_tags=en:to-be-exported --owner $producer done From cd9f85009912df0e05f8f1866bf2c0f9f2b4c1bf Mon Sep 17 00:00:00 2001 From: Antoine B Date: Mon, 22 Jul 2024 14:30:31 +0200 Subject: [PATCH 4/4] remove hardcoded owners --- ...ducers_platform_data_to_public_database.sh | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/scripts/export_producers_platform_data_to_public_database.sh b/scripts/export_producers_platform_data_to_public_database.sh index 5ee8c39adf2aa..12c5c15ce403b 100755 --- a/scripts/export_producers_platform_data_to_public_database.sh +++ b/scripts/export_producers_platform_data_to_public_database.sh @@ -10,28 +10,7 @@ filter_organizations_that_have_automated_export() { use warnings; use ProductOpener::Data qw/get_orgs_collection/; - my %producers = map { $_,1 } qw( - org-barilla-france-sa - org-ferrero-france-commerciale - org-unilever-france-gms - org-unilever-france-rhd - org-nestle-france - org-panzani-sa - org-cristalco - org-materne - org-garofalo-france - org-brasseries-kronenbourg - org-carrefour - org-lustucru-frais - org-nestle-waters - org-kambly - org-kambly-france - org-saint-hubert - org-d-aucy - org-lea-nature - org-auchan-apaw - org-les-mousquetaires - ); + my %producers = (); my @res = get_orgs_collection() ->find({ activate_automated_daily_export_to_public_platform => "on" }) @@ -41,7 +20,6 @@ filter_organizations_that_have_automated_export() { $producers{"org-" . $_->{org_id}} = undef for @res; print "$_\n" for keys %producers; - ' }