Skip to content

Commit

Permalink
notify robotoff when products change, bug #1706
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Apr 22, 2019
1 parent dc912f0 commit 4d012cd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cgi/product_jqm_multilingual.pl
Expand Up @@ -353,6 +353,9 @@
my $time = time();
$comment = $comment . remove_tags_and_quote(decode utf8=>param('comment'));
store_product($product_ref, $comment);

# Notify robotoff
send_notification_for_product_change($product_ref, "updated");

$response{status} = 1;
$response{status_verbose} = 'fields saved';
Expand Down
7 changes: 7 additions & 0 deletions cgi/product_multilingual.pl
Expand Up @@ -2155,6 +2155,10 @@ ($$$$$$)
. lang("see_product_page") . "</a></p>";
}
elsif ($type eq 'delete') {

# Notify robotoff
send_notification_for_product_change($product_ref, "deleted");

my $email = <<MAIL
$User_id $Lang{has_deleted_product}{$lc}:
Expand All @@ -2166,6 +2170,9 @@ ($$$$$$)

} else {

# Notify robotoff
send_notification_for_product_change($product_ref, "updated");

# warning: this option is very slow
if ((defined $options{display_random_sample_of_products_after_edits}) and ($options{display_random_sample_of_products_after_edits})) {

Expand Down
18 changes: 18 additions & 0 deletions lib/ProductOpener/Products.pm
Expand Up @@ -37,6 +37,7 @@ BEGIN
&retrieve_product_or_deleted_product
&retrieve_product_rev
&store_product
&send_notification_for_product_change
&product_name_brand
&product_name_brand_quantity
&product_url
Expand Down Expand Up @@ -74,6 +75,7 @@ use CGI qw/:cgi :form escapeHTML/;
use Encode;
use Log::Any qw($log);

use LWP::UserAgent;
use Storable qw(dclone);

use Algorithm::CheckDigits;
Expand Down Expand Up @@ -209,6 +211,22 @@ sub init_product($) {
return $product_ref;
}

# Notify robotoff when products are updated

sub send_notification_for_product_change($$) {

my $product_ref = shift;
my $action = shift;

my $ua = LWP::UserAgent->new();

my $response = $ua->post( "https://robotoff.openfoodfacts.org/api/v1/webhook/product", {

This comment has been minimized.

Copy link
@hangy

hangy Apr 25, 2019

Member

Should this be done on every deployment (local development, central dev, test, integration), and also for OpenBeautyFacts, OpenPetFoodFacts, and OpenProductFacts with the same robotoff instance? I believe, we have $ProductOpener::Config2::robotoff_url that could be used to control this.

'barcode' => $product_ref->{code},
'action' => $action,
'server_domain' => "api." . $server_domain
} );
}

sub retrieve_product($) {

my $code = shift;
Expand Down

1 comment on commit 4d012cd

@hangy
Copy link
Member

@hangy hangy commented on 4d012cd Apr 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1706 is unrelated - the correct issue is #1707 馃槈

Please sign in to comment.