Skip to content

Commit

Permalink
feat: add new product event types for redis queue (#10530)
Browse files Browse the repository at this point in the history
<!-- IMPORTANT CHECKLIST
Make sure you've done all the following (You can delete the checklist
before submitting)
- [ ] PR title is prefixed by one of the following: feat, fix, docs,
style, refactor, test, build, ci, chore, revert, l10n, taxonomy
- [ ] Code is well documented
- [ ] Include unit tests for new functionality
- [ ] Code passes GitHub workflow checks in your branch
- [ ] If you have multiple commits please combine them into one commit
by squashing them.
- [ ] Read and understood the [contribution
guidelines](https://github.com/openfoodfacts/openfoodfacts-server/blob/main/CONTRIBUTING.md)
-->
### What

- Added event types : created / imported / archived 

### Related issue(s) and discussion
<!-- Please add the issue number this issue will close, that way, once
your pull request is merged, the issue will be closed as well -->
- Fixes #10527
  • Loading branch information
4nt0ineB authored Jul 23, 2024
1 parent ce60b8f commit 339dbc4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/ProductOpener/Products.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 339dbc4

Please sign in to comment.