Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export obsolete products only once and include "obsolete" field in CSV export #10077

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions scripts/export_database.pl
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ sub sanitize_field_content {
$csv .= "${nid}_100g" . "\t";
}

if (grep { $_ eq 'products_obsolete' } @collections) {
$csv .= "obsolete\t";
}
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved

$csv =~ s/\t$/\n/;
print $OUT $csv;

Expand All @@ -274,6 +278,7 @@ sub sanitize_field_content {
get_products_collection({obsolete => 1, timeout => 3 * 60 * 60 * 1000})
);

push @export_fields, "obsolete";
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved
my $count = 0;
my %ingredients = ();

Expand All @@ -298,6 +303,12 @@ sub sanitize_field_content {
my $url = "http://world-$lc.$server_domain" . product_url($product_ref);
my $code = ($product_ref->{code} // '');

if ($product_ref->{obsolete}) {
if ($exported_products{$code}) {
next;
}
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved
}

$code eq '' and next;
$code < 1 and next;

Expand Down Expand Up @@ -339,6 +350,15 @@ sub sanitize_field_content {
$field_value = sanitize_field_content($field_value, $BAD, "$code barcode -> field $field:");
}

#Obsolete field
if ($field eq "obsolete") {
$field_value = $product_ref->{obsolete} ? 1 : 0;
}

else {
$field_value = ($product_ref->{$field} // "");
}
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved

# Add field value to CSV file
$csv .= $field_value . "\t";

Expand Down Expand Up @@ -509,6 +529,7 @@ sub sanitize_field_content {

print $OUT $csv;
print $RDF $rdf;
$exported_products{$code} = 1;
}
}

Expand Down
Loading