From 508d7677a4c7259f992428ed505e1cc0669a20ae Mon Sep 17 00:00:00 2001 From: john-gom <116556069+john-gom@users.noreply.github.com> Date: Fri, 13 Sep 2024 14:06:37 +0100 Subject: [PATCH] fix: Determine obsolete and deleted from the product revision (#10791) Signed-off-by: John Gomersall ### What Use the product revision to determine delete and obsolete status - Fixes #10789 --------- Signed-off-by: John Gomersall --- .../product_revision_to_historical_events.pl | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/scripts/product_revision_to_historical_events.pl b/scripts/product_revision_to_historical_events.pl index 80e1152a76866..0690279e8b9ed 100755 --- a/scripts/product_revision_to_historical_events.pl +++ b/scripts/product_revision_to_historical_events.pl @@ -72,43 +72,53 @@ ($path, $code) #my $code = product_id_from_path($path); my $change_count = @$changes; # some $product don't have a 'rev' my $rev = 0; # some $change don't have a 'rev' - + my $obsolete = 0; + my $deleted = 0; foreach my $change (@{$changes}) { $rev++; - # my $product = retrieve($path . "/" . $rev . ".sto"); - - if (not $can_process and $rev == $last_processed_rev) { - $can_process = 1; - print "Resuming from '$last_processed_path' revision $last_processed_rev\n"; - next; # we don't want to process the revision again + my $product = retrieve($path . "/" . $rev . ".sto"); + if (!defined $product) { + print '[' . localtime() . "] Unable to open $path/$rev.sto\n"; + next; } - next if not $can_process; - - my $timestamp = $change->{t} // 0; - next if ($timestamp < $start_from or $timestamp >= $end_before); + my $isDeleted = $product->{deleted}; + my $isObsolete = $product->{obsolete}; my $action = 'updated'; if ($rev eq 1) { $action = 'created'; } - elsif ( $rev == $change_count - and $change->{comment} =~ /^Deleting product/) - { + elsif ($isDeleted && !$deleted) { $action = 'deleted'; } - - if (exists $change->{diffs}{fields}{add} - and (grep {$_ eq 'obsolete'} @{$change->{diffs}{fields}{add}})) - { + # Note we treat undeleted as "updated" for consitency with current behaviour + # elsif (!$isDeleted and $deleted) { + # $action = 'undeleted'; + # } + elsif ($isObsolete && !$obsolete) { $action = 'archived'; } - if (exists $change->{diffs}{fields}{delete} - and (grep {$_ eq 'obsolete'} @{$change->{diffs}{fields}{delete}})) - { + elsif (!$isObsolete && $obsolete) { $action = 'unarchived'; } + $deleted = $isDeleted; + $obsolete = $isObsolete; + + # Need to figure out action before testing checkpoint as we need the version history + # to know where we are + if (not $can_process and $rev == $last_processed_rev) { + $can_process = 1; + print "Resuming from '$last_processed_path' revision $last_processed_rev\n"; + next; # we don't want to process the revision again + } + + next if not $can_process; + + my $timestamp = $change->{t} // 0; + next if ($timestamp < $start_from or $timestamp >= $end_before); + push( @events, {