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: Eval parse datetime in producers import to continue if dates strings are broken #7741

Merged
merged 2 commits into from
Nov 22, 2022
Merged
Changes from all commits
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
23 changes: 19 additions & 4 deletions lib/ProductOpener/Import.pm
Original file line number Diff line number Diff line change
Expand Up @@ -962,11 +962,26 @@ sub import_csv_file ($args_ref) {
my $existing_date = $product_ref->{sources_fields}{"org-gs1"}{publicationDateTime}
// $product_ref->{sources_fields}{"org-gs1"}{lastChangeDateTime};

if ((defined $imported_date) and (defined $existing_date)) {
if ( (defined $imported_date)
and ($imported_date ne "")
and (defined $existing_date)
and ($existing_date ne ""))
{

if (DateTime::Format::ISO8601->parse_datetime($imported_date)->epoch
< DateTime::Format::ISO8601->parse_datetime($existing_date)->epoch)
{
# Broken date strings can cause parse_datetime to fail
my $imported_date_t;
my $existing_date_t;
eval {
$imported_date_t = DateTime::Format::ISO8601->parse_datetime($imported_date)->epoch;
$existing_date_t = DateTime::Format::ISO8601->parse_datetime($existing_date)->epoch;
};

if ($@) {
$log->warn("Could not parse imported or existing dates",
{imported_date => $imported_date, existing_date => $existing_date, error => $@})
if $log->is_warn();
}
elsif ($imported_date_t < $existing_date_t) {
$log->debug(
"existing GS1 data with a greater sources_fields:org-gs1:publicationDateTime - skipping product",
{
Expand Down