mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Refactor Webhook to BaseModel.php
This commit is contained in:
parent
d0cfaff6d6
commit
400fb609ee
@ -12,6 +12,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\DataMapper\ClientSettings;
|
use App\DataMapper\ClientSettings;
|
||||||
|
use App\Jobs\Util\WebhookHandler;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Utils\Traits\UserSessionAttributes;
|
use App\Utils\Traits\UserSessionAttributes;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
@ -167,7 +168,7 @@ class BaseModel extends Model
|
|||||||
*/
|
*/
|
||||||
public function resolveRouteBinding($value, $field = null)
|
public function resolveRouteBinding($value, $field = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (is_numeric($value)) {
|
if (is_numeric($value)) {
|
||||||
throw new ModelNotFoundException("Record with value {$value} not found");
|
throw new ModelNotFoundException("Record with value {$value} not found");
|
||||||
}
|
}
|
||||||
@ -189,12 +190,12 @@ class BaseModel extends Model
|
|||||||
|
|
||||||
public function numberFormatter()
|
public function numberFormatter()
|
||||||
{
|
{
|
||||||
$number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
|
$number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
|
||||||
|
|
||||||
$formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $number);
|
$formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $number);
|
||||||
|
|
||||||
$formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number);
|
$formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number);
|
||||||
|
|
||||||
$formatted_number = preg_replace('/\s+/', '_', $formatted_number);
|
$formatted_number = preg_replace('/\s+/', '_', $formatted_number);
|
||||||
|
|
||||||
return $formatted_number;
|
return $formatted_number;
|
||||||
@ -205,4 +206,14 @@ class BaseModel extends Model
|
|||||||
return ctrans('texts.item');
|
return ctrans('texts.item');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function sendEvent($event_id, $additional_data){
|
||||||
|
$subscriptions = Webhook::where('company_id', $this->company_id)
|
||||||
|
->where('event_id', $event_id)
|
||||||
|
->exists();
|
||||||
|
if ($subscriptions) {
|
||||||
|
WebhookHandler::dispatch($event_id, $this, $this->company, $additional_data)->delay(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,13 +73,7 @@ class MarkSent extends AbstractService
|
|||||||
if($fire_webhook)
|
if($fire_webhook)
|
||||||
event('eloquent.updated: App\Models\Invoice', $this->invoice);
|
event('eloquent.updated: App\Models\Invoice', $this->invoice);
|
||||||
|
|
||||||
$subscriptions = Webhook::where('company_id', $this->invoice->company_id)
|
$this->invoice->sendEvent(Webhook::EVENT_SENT_INVOICE, "client");
|
||||||
->where('event_id', Webhook::EVENT_SENT_INVOICE)
|
|
||||||
->exists();
|
|
||||||
|
|
||||||
if ($subscriptions) {
|
|
||||||
WebhookHandler::dispatch(Webhook::EVENT_SENT_INVOICE, $this->invoice, $this->invoice->company, 'client')->delay(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->invoice->fresh();
|
return $this->invoice->fresh();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user