mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
adding webhooks for products
This commit is contained in:
parent
58e53aa961
commit
e1fbbe4268
@ -116,6 +116,16 @@ class Webhook extends BaseModel
|
||||
|
||||
const EVENT_RESTORE_VENDOR = 49;
|
||||
|
||||
const EVENT_CREATE_PRODUCT = 50;
|
||||
|
||||
const EVENT_UPDATE_PRODUCT = 51;
|
||||
|
||||
const EVENT_ARCHIVE_PRODUCT = 52;
|
||||
|
||||
const EVENT_RESTORE_PRODUCT = 53;
|
||||
|
||||
const EVENT_DELETE_PRODUCT = 54;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -169,7 +179,12 @@ class Webhook extends BaseModel
|
||||
self::EVENT_RESTORE_QUOTE,
|
||||
self::EVENT_RESTORE_INVOICE,
|
||||
self::EVENT_RESTORE_PAYMENT,
|
||||
self::EVENT_RESTORE_VENDOR
|
||||
self::EVENT_RESTORE_VENDOR,
|
||||
self::EVENT_CREATE_PRODUCT,
|
||||
self::EVENT_UPDATE_PRODUCT,
|
||||
self::EVENT_ARCHIVE_PRODUCT,
|
||||
self::EVENT_RESTORE_PRODUCT,
|
||||
self::EVENT_DELETE_PRODUCT
|
||||
|
||||
];
|
||||
|
||||
|
@ -23,7 +23,13 @@ class ProductObserver
|
||||
*/
|
||||
public function created(Product $product)
|
||||
{
|
||||
//
|
||||
$subscriptions = Webhook::where('company_id', $product->company->id)
|
||||
->where('event_id', Webhook::EVENT_CREATE_PRODUCT)
|
||||
->exists();
|
||||
|
||||
if ($subscriptions) {
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PRODUCT, $product, $product->company)->delay(now()->addSeconds(2));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,7 +40,13 @@ class ProductObserver
|
||||
*/
|
||||
public function updated(Product $product)
|
||||
{
|
||||
//
|
||||
$subscriptions = Webhook::where('company_id', $product->company->id)
|
||||
->where('event_id', Webhook::EVENT_UPDATE_PRODUCT)
|
||||
->exists();
|
||||
|
||||
if ($subscriptions) {
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_PRODUCT, $product, $product->company)->delay(now()->addSeconds(2));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,7 +57,13 @@ class ProductObserver
|
||||
*/
|
||||
public function deleted(Product $product)
|
||||
{
|
||||
//
|
||||
$subscriptions = Webhook::where('company_id', $product->company->id)
|
||||
->where('event_id', Webhook::EVENT_DELETE_PRODUCT)
|
||||
->exists();
|
||||
|
||||
if ($subscriptions) {
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_PRODUCT, $product, $product->company)->delay(now()->addSeconds(2));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,7 @@ use App\Models\Credit;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Product;
|
||||
use App\Models\Project;
|
||||
use App\Models\Quote;
|
||||
use App\Models\RecurringInvoice;
|
||||
@ -143,6 +144,13 @@ class BaseRepository
|
||||
else {
|
||||
$webhookEvent = Webhook::EVENT_ARCHIVE_PROJECT;}
|
||||
break;
|
||||
case $entity instanceof Product:
|
||||
if ($restore){
|
||||
$webhookEvent = Webhook::EVENT_RESTORE_PRODUCT;
|
||||
}
|
||||
else {
|
||||
$webhookEvent = Webhook::EVENT_ARCHIVE_PRODUCT;}
|
||||
break;
|
||||
case $entity instanceof Client:
|
||||
if ($restore){
|
||||
$webhookEvent = Webhook::EVENT_RESTORE_CLIENT;
|
||||
@ -185,6 +193,8 @@ class BaseRepository
|
||||
case $webhookEvent == Webhook::EVENT_RESTORE_CREDIT:
|
||||
case $webhookEvent == Webhook::EVENT_RESTORE_CLIENT:
|
||||
case $webhookEvent == Webhook::EVENT_ARCHIVE_CLIENT:
|
||||
case $webhookEvent == Webhook::EVENT_RESTORE_PRODUCT:
|
||||
case $webhookEvent == Webhook::EVENT_ARCHIVE_PRODUCT:
|
||||
WebhookHandler::dispatch($webhookEvent, $entity, $entity->company)->delay(now()->addSeconds(2));
|
||||
break;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user