From 339dbc453bbba78de561149cd5c8f583871ba301 Mon Sep 17 00:00:00 2001 From: Antoine B <56827368+4nt0ineB@users.noreply.github.com> Date: Tue, 23 Jul 2024 09:13:48 +0200 Subject: [PATCH] feat: add new product event types for redis queue (#10530) ### What - Added event types : created / imported / archived ### Related issue(s) and discussion - Fixes #10527 --- lib/ProductOpener/Products.pm | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index 3286e59d32d20..3fa528a5791ea 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -1177,6 +1177,7 @@ sub store_product ($user_id, $product_ref, $comment) { my $product_id = $product_ref->{_id}; my $path = product_path($product_ref); my $rev = $product_ref->{rev}; + my $action = "updated"; $log->debug( "store_product - start", @@ -1221,6 +1222,13 @@ sub store_product ($user_id, $product_ref, $comment) { } ) if $log->is_debug(); $delete_from_previous_products_collection = 1; + + if ($product_ref->{obsolete} eq 'on') { + $action = "archived"; + } + elsif ($product_ref->{was_obsolete} eq 'on') { + $action = "unarchived"; + } } delete $product_ref->{was_obsolete}; @@ -1501,12 +1509,18 @@ sub store_product ($user_id, $product_ref, $comment) { $log->debug("store_product - done", {code => $code, product_id => $product_id}) if $log->is_debug(); - my $update_type = $product_ref->{deleted} ? "deleted" : "updated"; + if ($product_ref->{deleted}) { + $action = "deleted"; + } + elsif ($rev == 1) { + $action = "created"; + } + # Publish information about update on Redis stream - push_to_redis_stream($user_id, $product_ref, $update_type, $comment, $diffs); + push_to_redis_stream($user_id, $product_ref, $action, $comment, $diffs); # Notify Robotoff - send_notification_for_product_change($user_id, $product_ref, $update_type, $comment, $diffs); + send_notification_for_product_change($user_id, $product_ref, $action, $comment, $diffs); return 1; }