websocket ref
This commit is contained in:
@@ -29,29 +29,29 @@
|
||||
|
||||
namespace Espo\Hooks\Common;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Core\WebSocket\ConfigDataProvider;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
use Espo\Core\ORM\Repository\Option\SaveOption;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Core\WebSocket\Submission as WebSocketSubmission;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
|
||||
class WebSocketSubmit
|
||||
/**
|
||||
* @implements AfterSave<Entity>
|
||||
*/
|
||||
class WebSocketSubmit implements AfterSave
|
||||
{
|
||||
public static int $order = 20;
|
||||
|
||||
public function __construct(
|
||||
private Metadata $metadata,
|
||||
private WebSocketSubmission $webSocketSubmission,
|
||||
private Config $config
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function afterSave(Entity $entity, array $options): void
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if ($options[SaveOption::SILENT] ?? false) {
|
||||
if ($options->get(SaveOption::SILENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,19 +59,15 @@ class WebSocketSubmit
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->config->get('useWebSocket')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$scope = $entity->getEntityType();
|
||||
$id = $entity->getId();
|
||||
|
||||
if (!$this->metadata->get(['scopes', $scope, 'object'])) {
|
||||
if (!$this->metadata->get("scopes.$scope.object")) {
|
||||
return;
|
||||
}
|
||||
|
||||
$topic = "recordUpdate.{$scope}.{$id}";
|
||||
$topic = "recordUpdate.$scope.$id";
|
||||
|
||||
$this->webSocketSubmission->submit($topic, null);
|
||||
$this->webSocketSubmission->submit($topic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ namespace Espo\Hooks\Note;
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Entities\Note;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\WebSocket\Submission as WebSocketSubmission;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
|
||||
@@ -45,15 +44,10 @@ class WebSocketSubmit implements AfterSave
|
||||
|
||||
public function __construct(
|
||||
private WebSocketSubmission $webSocketSubmission,
|
||||
private Config $config
|
||||
) {}
|
||||
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if (!$this->config->get('useWebSocket')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$parentId = $entity->getParentId();
|
||||
$parentType = $entity->getParentType();
|
||||
|
||||
|
||||
@@ -29,29 +29,30 @@
|
||||
|
||||
namespace Espo\Hooks\Notification;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Entities\Notification;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\WebSocket\Submission as WebSocketSubmission;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
|
||||
class WebSocketSubmit
|
||||
/**
|
||||
* @implements AfterSave<Notification>
|
||||
*/
|
||||
class WebSocketSubmit implements AfterSave
|
||||
{
|
||||
public static int $order = 20;
|
||||
|
||||
public function __construct(private WebSocketSubmission $webSocketSubmission, private Config $config)
|
||||
{}
|
||||
public function __construct(
|
||||
private WebSocketSubmission $webSocketSubmission,
|
||||
) {}
|
||||
|
||||
public function afterSave(Entity $entity): void
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if (!$this->config->get('useWebSocket')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$entity->isNew()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$userId = $entity->get('userId');
|
||||
$userId = $entity->getUserId();
|
||||
|
||||
if (!$userId) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user