1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Refactor for observers

This commit is contained in:
David Bomba 2023-01-31 23:53:54 +11:00
parent b260a62a73
commit 399b397ecf
12 changed files with 280 additions and 111 deletions

View File

@ -116,11 +116,36 @@ class Webhook extends BaseModel
const EVENT_RESTORE_VENDOR = 49;
const EVENT_CREATE_PRODUCT = 50;
const EVENT_UPDATE_PRODUCT = 51;
const EVENT_DELETE_PRODUCT = 52;
const EVENT_RESTORE_PRODUCT = 53;
const EVENT_ARCHIVE_PRODUCT = 54;
const EVENT_CREATE_PURCHASE_ORDER = 55;
const EVENT_UPDATE_PURCHASE_ORDER = 56;
const EVENT_DELETE_PURCHASE_ORDER = 57;
const EVENT_RESTORE_PURCHASE_ORDER = 58;
const EVENT_ARCHIVE_PURCHASE_ORDER = 59;
public static $valid_events = [
self::EVENT_CREATE_PURCHASE_ORDER,
self::EVENT_UPDATE_PURCHASE_ORDER,
self::EVENT_DELETE_PURCHASE_ORDER,
self::EVENT_RESTORE_PURCHASE_ORDER,
self::EVENT_ARCHIVE_PURCHASE_ORDER,
self::EVENT_UPDATE_PRODUCT,
self::EVENT_DELETE_PRODUCT,
self::EVENT_RESTORE_PRODUCT,
self::EVENT_ARCHIVE_PRODUCT,
self::EVENT_CREATE_CLIENT,
self::EVENT_CREATE_INVOICE,
self::EVENT_CREATE_QUOTE,

View File

@ -26,12 +26,12 @@ class ClientObserver
*/
public function created(Client $client)
{
$subscriptions = Webhook::where('company_id', $client->company->id)
$subscriptions = Webhook::where('company_id', $client->company_id)
->where('event_id', Webhook::EVENT_CREATE_CLIENT)
->exists();
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_CREATE_CLIENT, $client, $client->company)->delay(now()->addSeconds(rand(1,5)));
WebhookHandler::dispatch(Webhook::EVENT_CREATE_CLIENT, $client, $client->company)->delay(rand(1,5));
}
@ -53,12 +53,12 @@ class ClientObserver
$event = Webhook::EVENT_DELETE_CLIENT;
$subscriptions = Webhook::where('company_id', $client->company->id)
$subscriptions = Webhook::where('company_id', $client->company_id)
->where('event_id', $event)
->exists();
if ($subscriptions)
WebhookHandler::dispatch($event, $client, $client->company)->delay(now()->addSeconds(rand(1,5)));
WebhookHandler::dispatch($event, $client, $client->company)->delay(rand(1,5));
}
@ -74,12 +74,12 @@ class ClientObserver
if($client->is_deleted)
return;
$subscriptions = Webhook::where('company_id', $client->company->id)
$subscriptions = Webhook::where('company_id', $client->company_id)
->where('event_id', Webhook::EVENT_ARCHIVE_CLIENT)
->exists();
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_CLIENT, $client, $client->company)->delay(now()->addSeconds(rand(1,5)));
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_CLIENT, $client, $client->company)->delay(rand(1,5));
}

View File

@ -32,7 +32,7 @@ class CreditObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_CREDIT, $credit, $credit->company)->delay(now()->addSeconds(rand(1,5)));
WebhookHandler::dispatch(Webhook::EVENT_CREATE_CREDIT, $credit, $credit->company)->delay(rand(1,5));
}
}
@ -53,12 +53,12 @@ class CreditObserver
$event = Webhook::EVENT_DELETE_CREDIT;
$subscriptions = Webhook::where('company_id', $credit->company->id)
->where('event_id', Webhook::EVENT_UPDATE_CREDIT)
->where('event_id', $event)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_CREDIT, $credit, $credit->company)->delay(now()->addSeconds(rand(1,5)));
}
if ($subscriptions)
WebhookHandler::dispatch($event, $credit, $credit->company)->delay(rand(1,5));
}
/**
@ -73,11 +73,11 @@ class CreditObserver
return;
$subscriptions = Webhook::where('company_id', $credit->company->id)
->where('event_id', Webhook::EVENT_DELETE_CREDIT)
->where('event_id', Webhook::EVENT_ARCHIVE_CREDIT)
->exists();
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_CREDIT, $credit, $credit->company)->delay(now()->addSeconds(rand(1,5)));
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_CREDIT, $credit, $credit->company)->delay(rand(1,5));
}

View File

@ -30,7 +30,7 @@ class ExpenseObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_EXPENSE, $expense, $expense->company)->delay(now()->addSeconds(rand(1,5)));
WebhookHandler::dispatch(Webhook::EVENT_CREATE_EXPENSE, $expense, $expense->company)->delay(rand(1,5));
}
}
@ -42,13 +42,22 @@ class ExpenseObserver
*/
public function updated(Expense $expense)
{
$subscriptions = Webhook::where('company_id', $expense->company->id)
->where('event_id', Webhook::EVENT_UPDATE_EXPENSE)
->exists();
$event = Webhook::EVENT_UPDATE_EXPENSE;
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_EXPENSE, $expense, $expense->company)->delay(now()->addSeconds(rand(1,5)));
}
if($expense->getOriginal('deleted_at') && !$expense->deleted_at)
$event = Webhook::EVENT_RESTORE_EXPENSE;
if($expense->is_deleted)
$event = Webhook::EVENT_DELETE_EXPENSE;
$subscriptions = Webhook::where('company_id', $expense->company->id)
->where('event_id', $event)
->exists();
if ($subscriptions)
WebhookHandler::dispatch($event, $expense, $expense->company)->delay(rand(1,5));
}
/**
@ -59,13 +68,16 @@ class ExpenseObserver
*/
public function deleted(Expense $expense)
{
if($expense->is_deleted)
return;
$subscriptions = Webhook::where('company_id', $expense->company->id)
->where('event_id', Webhook::EVENT_DELETE_EXPENSE)
->where('event_id', Webhook::EVENT_ARCHIVE_EXPENSE)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_EXPENSE, $expense, $expense->company)->delay(now()->addSeconds(rand(1,5)));
}
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_EXPENSE, $expense, $expense->company)->delay(rand(1,5));
}
/**

View File

@ -11,9 +11,7 @@
namespace App\Observers;
use App\Jobs\Util\UnlinkFile;
use App\Jobs\Util\WebhookHandler;
use App\Models\Client;
use App\Models\Invoice;
use App\Models\Webhook;
@ -34,7 +32,7 @@ class InvoiceObserver
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(rand(1,5)));
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company, 'client')->delay(rand(1,5));
}
}
@ -46,13 +44,21 @@ class InvoiceObserver
*/
public function updated(Invoice $invoice)
{
$subscriptions = Webhook::where('company_id', $invoice->company_id)
->where('event_id', Webhook::EVENT_UPDATE_INVOICE)
->exists();
$event = Webhook::EVENT_UPDATE_INVOICE;
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(rand(1,5)));
}
if($invoice->getOriginal('deleted_at') && !$invoice->deleted_at)
$event = Webhook::EVENT_RESTORE_INVOICE;
if($invoice->is_deleted)
$event = Webhook::EVENT_DELETE_INVOICE;
$subscriptions = Webhook::where('company_id', $invoice->company->id)
->where('event_id', $event)
->exists();
if ($subscriptions)
WebhookHandler::dispatch($event, $invoice, $invoice->company)->delay(rand(1,5));
}
/**
@ -63,13 +69,16 @@ class InvoiceObserver
*/
public function deleted(Invoice $invoice)
{
if($invoice->is_deleted)
return;
$subscriptions = Webhook::where('company_id', $invoice->company_id)
->where('event_id', Webhook::EVENT_DELETE_INVOICE)
->where('event_id', Webhook::EVENT_ARCHIVE_INVOICE)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(rand(1,5)));
}
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_INVOICE, $invoice, $invoice->company, 'client')->delay(rand(1,5));
}
/**

View File

@ -25,13 +25,13 @@ class PaymentObserver
*/
public function created(Payment $payment)
{
$subscriptions = Webhook::where('company_id', $payment->company->id)
$subscriptions = Webhook::where('company_id', $payment->company_id)
->where('event_id', Webhook::EVENT_CREATE_PAYMENT)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company, 'invoices,client')->delay(now()->addSeconds(20));
}
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company, 'invoices,client')->delay(20);
}
/**
@ -42,13 +42,21 @@ class PaymentObserver
*/
public function updated(Payment $payment)
{
$subscriptions = Webhook::where('company_id', $payment->company->id)
->where('event_id', Webhook::EVENT_UPDATE_PAYMENT)
->exists();
$event = Webhook::EVENT_UPDATE_PAYMENT;
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_PAYMENT, $payment, $payment->company, 'invoices,client')->delay(now()->addSeconds(20));
}
if($payment->getOriginal('deleted_at') && !$payment->deleted_at)
$event = Webhook::EVENT_RESTORE_PAYMENT;
if($payment->is_deleted)
$event = Webhook::EVENT_DELETE_PAYMENT;
$subscriptions = Webhook::where('company_id', $payment->company_id)
->where('event_id', $event)
->exists();
if ($subscriptions)
WebhookHandler::dispatch($event, $payment, $payment->company, 'invoices,client')->delay(20);
}
/**
@ -59,12 +67,15 @@ class PaymentObserver
*/
public function deleted(Payment $payment)
{
$subscriptions = Webhook::where('company_id', $payment->company->id)
->where('event_id', Webhook::EVENT_DELETE_PAYMENT)
if($payment->is_deleted)
return;
$subscriptions = Webhook::where('company_id', $payment->company_id)
->where('event_id', Webhook::EVENT_ARCHIVE_PAYMENT)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company, 'invoices,client')->delay(now()->addSeconds(20));
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_PAYMENT, $payment, $payment->company, 'invoices,client')->delay(20);
}
}

View File

@ -11,7 +11,9 @@
namespace App\Observers;
use App\Jobs\Util\WebhookHandler;
use App\Models\Product;
use App\Models\Webhook;
class ProductObserver
{
@ -23,7 +25,12 @@ 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(rand(1,5));
}
/**
@ -34,7 +41,23 @@ class ProductObserver
*/
public function updated(Product $product)
{
//
$event = Webhook::EVENT_UPDATE_PRODUCT;
if($product->getOriginal('deleted_at') && !$product->deleted_at)
$event = Webhook::EVENT_RESTORE_PRODUCT;
if($product->is_deleted)
$event = Webhook::EVENT_DELETE_PRODUCT;
$subscriptions = Webhook::where('company_id', $product->company_id)
->where('event_id', $event)
->exists();
if ($subscriptions)
WebhookHandler::dispatch($event, $product, $product->company)->delay(rand(1,5));
}
/**
@ -45,7 +68,15 @@ class ProductObserver
*/
public function deleted(Product $product)
{
//
if($product->is_deleted)
return;
$subscriptions = Webhook::where('company_id', $product->company_id)
->where('event_id', Webhook::EVENT_ARCHIVE_PRODUCT)
->exists();
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_PRODUCT, $product, $product->company)->delay(rand(1,5));
}
/**

View File

@ -31,9 +31,9 @@ class ProjectObserver
->where('event_id', Webhook::EVENT_PROJECT_CREATE)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_CREATE, $project, $project->company, 'client')->delay(now()->addSeconds(rand(1,5)));
}
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_CREATE, $project, $project->company, 'client')->delay(rand(1,5));
}
/**
@ -44,13 +44,23 @@ class ProjectObserver
*/
public function updated(Project $project)
{
$subscriptions = Webhook::where('company_id', $project->company_id)
->where('event_id', Webhook::EVENT_PROJECT_UPDATE)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_UPDATE, $project, $project->company, 'client')->delay(now()->addSeconds(rand(1,5)));
}
$event = Webhook::EVENT_PROJECT_UPDATE;
if($project->getOriginal('deleted_at') && !$project->deleted_at)
$event = Webhook::EVENT_RESTORE_PROJECT;
if($project->is_deleted)
$event = Webhook::EVENT_PROJECT_DELETE;
$subscriptions = Webhook::where('company_id', $project->company_id)
->where('event_id', $event)
->exists();
if ($subscriptions)
WebhookHandler::dispatch($event, $project, $project->company, 'client')->delay(rand(1,5));
}
/**
@ -61,14 +71,16 @@ class ProjectObserver
*/
public function deleted(Project $project)
{
//EVENT_PROJECT_DELETE
if($project->is_deleted)
return;
$subscriptions = Webhook::where('company_id', $project->company_id)
->where('event_id', Webhook::EVENT_PROJECT_DELETE)
->where('event_id', Webhook::EVENT_ARCHIVE_PROJECT)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_DELETE, $project, $project->company, 'client')->delay(now()->addSeconds(rand(1,5)));
}
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_PROJECT, $project, $project->company, 'client')->delay(rand(1,5));
}
/**

View File

@ -11,7 +11,9 @@
namespace App\Observers;
use App\Jobs\Util\WebhookHandler;
use App\Models\PurchaseOrder;
use App\Models\Webhook;
class PurchaseOrderObserver
{
@ -23,6 +25,14 @@ class PurchaseOrderObserver
*/
public function created(PurchaseOrder $purchase_order)
{
$subscriptions = Webhook::where('company_id', $purchase_order->company_id)
->where('event_id', Webhook::EVENT_CREATE_PURCHASE_ORDER)
->exists();
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PURCHASE_ORDER, $purchase_order, $purchase_order->company, 'vendor')->delay(rand(1,5));
}
/**
@ -33,6 +43,23 @@ class PurchaseOrderObserver
*/
public function updated(PurchaseOrder $purchase_order)
{
$event = Webhook::EVENT_UPDATE_PURCHASE_ORDER;
if($purchase_order->getOriginal('deleted_at') && !$purchase_order->deleted_at)
$event = Webhook::EVENT_RESTORE_PURCHASE_ORDER;
if($purchase_order->is_deleted)
$event = Webhook::EVENT_DELETE_PURCHASE_ORDER;
$subscriptions = Webhook::where('company_id', $purchase_order->company_id)
->where('event_id', $event)
->exists();
if ($subscriptions)
WebhookHandler::dispatch($event, $purchase_order, $purchase_order->company, 'vendor')->delay(rand(1,5));
}
/**
@ -43,6 +70,16 @@ class PurchaseOrderObserver
*/
public function deleted(PurchaseOrder $purchase_order)
{
if($purchase_order->is_deleted)
return;
$subscriptions = Webhook::where('company_id', $purchase_order->company_id)
->where('event_id', Webhook::EVENT_ARCHIVE_PURCHASE_ORDER)
->exists();
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_PURCHASE_ORDER, $purchase_order, $purchase_order->company, 'vendor')->delay(rand(1,5));
}
/**

View File

@ -11,7 +11,6 @@
namespace App\Observers;
use App\Jobs\Util\UnlinkFile;
use App\Jobs\Util\WebhookHandler;
use App\Models\Quote;
use App\Models\Webhook;
@ -26,14 +25,14 @@ class QuoteObserver
*/
public function created(Quote $quote)
{
$subscriptions = Webhook::where('company_id', $quote->company->id)
$subscriptions = Webhook::where('company_id', $quote->company_id)
->where('event_id', Webhook::EVENT_CREATE_QUOTE)
->exists();
if ($subscriptions) {
$quote->load('client');
WebhookHandler::dispatch(Webhook::EVENT_CREATE_QUOTE, $quote, $quote->company, 'client')->delay(now()->addSeconds(rand(1,5)));
}
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_CREATE_QUOTE, $quote, $quote->company, 'client')->delay(rand(1,5));
}
/**
@ -44,14 +43,23 @@ class QuoteObserver
*/
public function updated(Quote $quote)
{
$subscriptions = Webhook::where('company_id', $quote->company->id)
->where('event_id', Webhook::EVENT_UPDATE_QUOTE)
->exists();
if ($subscriptions) {
$quote->load('client');
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote, $quote->company, 'client')->delay(now()->addSeconds(rand(1,5)));
}
$event = Webhook::EVENT_UPDATE_QUOTE;
if($quote->getOriginal('deleted_at') && !$quote->deleted_at)
$event = Webhook::EVENT_RESTORE_QUOTE;
if($quote->is_deleted)
$event = Webhook::EVENT_DELETE_QUOTE;
$subscriptions = Webhook::where('company_id', $quote->company_id)
->where('event_id', $event)
->exists();
if ($subscriptions)
WebhookHandler::dispatch($event, $quote, $quote->company, 'client')->delay(rand(1,5));
}
/**
@ -62,14 +70,16 @@ class QuoteObserver
*/
public function deleted(Quote $quote)
{
$subscriptions = Webhook::where('company_id', $quote->company->id)
->where('event_id', Webhook::EVENT_DELETE_QUOTE)
if($quote->is_deleted)
return;
$subscriptions = Webhook::where('company_id', $quote->company_id)
->where('event_id', Webhook::EVENT_ARCHIVE_QUOTE)
->exists();
if ($subscriptions) {
$quote->load('client');
WebhookHandler::dispatch(Webhook::EVENT_DELETE_QUOTE, $quote, $quote->company, 'client')->delay(now()->addSeconds(rand(1,5)));
}
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_QUOTE, $quote, $quote->company, 'client')->delay(rand(1,5));
}
/**

View File

@ -25,13 +25,13 @@ class TaskObserver
*/
public function created(Task $task)
{
$subscriptions = Webhook::where('company_id', $task->company->id)
$subscriptions = Webhook::where('company_id', $task->company_id)
->where('event_id', Webhook::EVENT_CREATE_TASK)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_TASK, $task, $task->company)->delay(now()->addSeconds(rand(1,5)));
}
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_CREATE_TASK, $task, $task->company)->delay(rand(1,5));
}
/**
@ -42,13 +42,21 @@ class TaskObserver
*/
public function updated(Task $task)
{
$subscriptions = Webhook::where('company_id', $task->company->id)
->where('event_id', Webhook::EVENT_UPDATE_TASK)
->exists();
$event = Webhook::EVENT_UPDATE_TASK;
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_TASK, $task, $task->company)->delay(now()->addSeconds(rand(1,5)));
}
if($task->getOriginal('deleted_at') && !$task->deleted_at)
$event = Webhook::EVENT_RESTORE_TASK;
if($task->is_deleted)
$event = Webhook::EVENT_DELETE_TASK;
$subscriptions = Webhook::where('company_id', $task->company_id)
->where('event_id', $event)
->exists();
if ($subscriptions)
WebhookHandler::dispatch($event, $task, $task->company)->delay(rand(1,5));
}
/**
@ -59,13 +67,16 @@ class TaskObserver
*/
public function deleted(Task $task)
{
$subscriptions = Webhook::where('company_id', $task->company->id)
->where('event_id', Webhook::EVENT_DELETE_TASK)
if($task->is_deleted)
return;
$subscriptions = Webhook::where('company_id', $task->company_id)
->where('event_id', Webhook::EVENT_ARCHIVE_TASK)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_TASK, $task, $task->company)->delay(now()->addSeconds(rand(1,5)));
}
if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_TASK, $task, $task->company)->delay(rand(1,5));
}
/**

View File

@ -25,12 +25,12 @@ class VendorObserver
*/
public function created(Vendor $vendor)
{
$subscriptions = Webhook::where('company_id', $vendor->company->id)
$subscriptions = Webhook::where('company_id', $vendor->company_id)
->where('event_id', Webhook::EVENT_CREATE_VENDOR)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_VENDOR, $vendor, $vendor->company)->delay(now()->addSeconds(rand(1,5)));
WebhookHandler::dispatch(Webhook::EVENT_CREATE_VENDOR, $vendor, $vendor->company)->delay(rand(1,5));
}
}
@ -42,13 +42,21 @@ class VendorObserver
*/
public function updated(Vendor $vendor)
{
$subscriptions = Webhook::where('company_id', $vendor->company->id)
->where('event_id', Webhook::EVENT_UPDATE_VENDOR)
$event = Webhook::EVENT_UPDATE_VENDOR;
if($vendor->getOriginal('deleted_at') && !$vendor->deleted_at)
$event = Webhook::EVENT_RESTORE_VENDOR;
if($vendor->is_deleted)
$event = Webhook::EVENT_DELETE_VENDOR;
$subscriptions = Webhook::where('company_id', $vendor->company_id)
->where('event_id', $event)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_VENDOR, $vendor, $vendor->company)->delay(now()->addSeconds(rand(1,5)));
}
if ($subscriptions)
WebhookHandler::dispatch($event, $vendor, $vendor->company)->delay(rand(1,5));
}
/**
@ -59,12 +67,15 @@ class VendorObserver
*/
public function deleted(Vendor $vendor)
{
$subscriptions = Webhook::where('company_id', $vendor->company->id)
->where('event_id', Webhook::EVENT_DELETE_VENDOR)
if($vendor->is_deleted)
return;
$subscriptions = Webhook::where('company_id', $vendor->company_id)
->where('event_id', Webhook::EVENT_ARCHIVE_VENDOR)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_VENDOR, $vendor, $vendor->company)->delay(now()->addSeconds(rand(1,5)));
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_VENDOR, $vendor, $vendor->company)->delay(rand(1,5));
}
}