Skip to content

Commit

Permalink
fix: export obsolete products - draft (#8397)
Browse files Browse the repository at this point in the history
Show the number of products that are not exported in both products and products_obsolete collections, and export both.
  • Loading branch information
stephanegigandet authored May 11, 2023
1 parent 1d8583b commit efa8c72
Show file tree
Hide file tree
Showing 8 changed files with 370 additions and 356 deletions.
21 changes: 3 additions & 18 deletions cgi/export_products.pl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

if ($action eq "display") {

my $template_data_ref = {lang => \&lang,};
my $template_data_ref = {};

# Query filters

Expand All @@ -95,25 +95,10 @@
}
}

# Number of products matching the optional query
my $count = count_products({}, $query_ref);

# Number of products matching the query with changes that have not yet been imported
$query_ref->{states_tags} = "en:to-be-exported";
my $count_to_be_exported = count_products({}, $query_ref);

$template_data_ref->{count} = $count;
$template_data_ref->{count_to_be_exported} = $count_to_be_exported;

if ($count == 0) {
$template_data_ref->{n_products_will_be_exported} = lang("no_products_to_export");
}
elsif ($count == 1) {
$template_data_ref->{n_products_will_be_exported} = lang("one_product_will_be_exported");
}
else {
$template_data_ref->{n_products_will_be_exported} = sprintf(lang("n_products_will_be_exported"), $count);
}
$template_data_ref->{count_to_be_exported} = count_products({}, $query_ref);
$template_data_ref->{count_obsolete_to_be_exported} = count_products({}, $query_ref, 1);

my $export_photos_value = "";
my $replace_selected_photos_value = "";
Expand Down
16 changes: 5 additions & 11 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1027,15 +1027,10 @@ sub display_index_for_producer ($request_ref) {
}

# Display a message if some product updates have not been published yet
# Updates can also be on obsolete products

my $count = count_products($request_ref, {states_tags => "en:to-be-exported"});

if ($count == 1) {
$template_data_ref->{products_to_be_exported} = lang("one_product_will_be_exported");
}
elsif ($count > 1) {
$template_data_ref->{products_to_be_exported} = sprintf(lang("n_products_will_be_exported"), $count);
}
$template_data_ref->{count_to_be_exported} = count_products({}, {states_tags => "en:to-be-exported"});
$template_data_ref->{count_obsolete_to_be_exported} = count_products({}, {states_tags => "en:to-be-exported"}, 1);

my $html;

Expand Down Expand Up @@ -4373,7 +4368,7 @@ sub add_country_and_owner_filters_to_query ($request_ref, $query_ref) {
return;
}

sub count_products ($request_ref, $query_ref) {
sub count_products ($request_ref, $query_ref, $obsolete = 0) {

add_country_and_owner_filters_to_query($request_ref, $query_ref);

Expand All @@ -4383,8 +4378,7 @@ sub count_products ($request_ref, $query_ref) {
$log->debug("Counting MongoDB documents for query", {query => $query_ref}) if $log->is_debug();
$count = execute_query(
sub {
return get_products_collection({obsolete => request_param($request_ref, "obsolete")})
->count_documents($query_ref);
return get_products_collection({obsolete => $obsolete})->count_documents($query_ref);
}
);
};
Expand Down
Loading

0 comments on commit efa8c72

Please sign in to comment.