| Server IP : 52.25.153.185 / Your IP : 216.73.216.194 Web Server : Apache System : Linux ip-172-26-6-158 5.10.0-45-cloud-amd64 #1 SMP Debian 5.10.259-1 (2026-07-02) x86_64 User : daemon ( 1) PHP Version : 8.1.10 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /bitnami/wordpress/wp-content/plugins/fluent-crm/app/Models/ |
Upload File : |
<?php
namespace FluentCrm\App\Models;
use FluentCrm\App\Services\Helper;
use FluentCrm\Framework\Support\Arr;
/**
* Webhook Model - DB Model for Webhooks
*
* Database Model
*
* @package FluentCrm\App\Models
*
* @version 1.0.0
*/
class Webhook extends Meta
{
protected $fillable = [
'id',
'key',
'value',
'object_type'
];
public static function boot()
{
parent::boot();
static::addGlobalScope('type', function ($builder) {
$builder->where(function($query) {
$query->where('object_type', '=', 'webhook')
->orWhere('object_type', 'LIKE', 'webhook_%');
});
});
}
public function getFields()
{
$contactFields = [
'fields' => [],
'custom_fields' => []
];
foreach (Subscriber::mappables() as $key => $column) {
$contactFields['fields'][] = ['key' => $key, 'field' => $column];
}
foreach ((new CustomContactField)->getGlobalFields()['fields'] as $field) {
$contactFields['custom_fields'][] = ['key' => $field['slug'], 'field' => $field['label']];
}
return $contactFields;
}
public function getSchema()
{
$schema = [
'name' => '',
'lists' => [],
'tags' => [],
'url' => '',
'status' => ''
];
if (Helper::isCompanyEnabled()) {
$schema['companies'] = [];
}
return $schema;
}
public function store($data)
{
$key = wp_generate_uuid4();
$webhookUrl = add_query_arg([
FLUENTCRM_EXTERNAL_URL_PARAM => 1,
'route' => 'contact',
'hash' => $key
], site_url('/'));
return static::create([
'object_type' => 'webhook',
'key' => $key,
'value' => array_merge($data, [
'url' => $webhookUrl
]),
]);
}
public function saveChanges($data)
{
$data['tags'] = Arr::get($data, 'tags', []);
$data['lists'] = Arr::get($data, 'lists', []);
$data['companies'] = Arr::get($data, 'companies', []);
$this->value = array_merge(
$this->value,
array_diff_key($data, [
'id' => '', 'url' => ''
])
);
$this->save();
return $this;
}
}