Skip to content

Commit

Permalink
fix: Determine obsolete and deleted from the product revision (#10791)
Browse files Browse the repository at this point in the history
Signed-off-by: John Gomersall <[email protected]>

### What

Use the product revision to determine delete and obsolete status

- Fixes #10789

---------

Signed-off-by: John Gomersall <[email protected]>
  • Loading branch information
john-gom committed Sep 13, 2024
1 parent 959c74c commit 508d767
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions scripts/product_revision_to_historical_events.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand Down

0 comments on commit 508d767

Please sign in to comment.