EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
ref
Yuri Kuznetsov0fa05c5be2ae
diff --git a/application/Espo/Core/Webhook/Manager.php b/application/Espo/Core/Webhook/Manager.phpindex 8064afe814..7da15eae0a 100644--- a/application/Espo/Core/Webhook/Manager.php+++ b/application/Espo/Core/Webhook/Manager.php@@ -73,7 +73,6 @@ class Managerprivate Log $log,private SystemConfig $systemConfig,) {-$this->loadData();}@@ -112,7 +111,7 @@ class Manager$data = [];$list = $this->entityManager- ->getRDBRepository(Webhook::ENTITY_TYPE)+ ->getRDBRepositoryByClass(Webhook::class)->select(['event'])->group(['event'])->where([@@ -122,7 +121,6 @@ class Manager->find();foreach ($list as $webhook) {- /** @var string $event */$event = $webhook->getEvent();$data[$event] = true;@@ -148,8 +146,8 @@ class Manager*/public function removeEvent(string $event): void{- $notExists = !$this->entityManager- ->getRDBRepository(Webhook::ENTITY_TYPE)+ $one = !$this->entityManager+ ->getRDBRepositoryByClass(Webhook::class)->select([Attribute::ID])->where(['event' => $event,@@ -157,21 +155,23 @@ class Manager])->findOne();- if ($notExists) {- unset($this->data[$event]);+ if (!$one) {+ return;+ }- if ($this->systemConfig->useCache()) {- $this->storeDataToCache();- }+ unset($this->data[$event]);++ if ($this->systemConfig->useCache()) {+ $this->storeDataToCache();}}- protected function eventExists(string $event): bool+ private function eventExists(string $event): bool{return isset($this->data[$event]);}- protected function logDebugEvent(string $event, Entity $entity): void+ private function logDebugEvent(string $event, Entity $entity): void{$this->log->debug("Webhook: {$event} on record {$entity->getId()}.");}@@ -181,7 +181,7 @@ class Manager*/public function processCreate(Entity $entity): void{- $event = $entity->getEntityType() . '.create';+ $event = "{$entity->getEntityType()}.create";if (!$this->eventExists($event)) {return;@@ -202,7 +202,7 @@ class Manager*/public function processDelete(Entity $entity): void{- $event = $entity->getEntityType() . '.delete';+ $event = "{$entity->getEntityType()}.delete";if (!$this->eventExists($event)) {return;@@ -225,7 +225,7 @@ class Manager*/public function processUpdate(Entity $entity): void{- $event = $entity->getEntityType() . '.update';+ $event = "{$entity->getEntityType()}.update";$data = (object) [];@@ -257,7 +257,7 @@ class Manager}foreach ($this->fieldUtil->getEntityTypeFieldList($entity->getEntityType()) as $field) {- $itemEvent = $entity->getEntityType() . '.fieldUpdate.' . $field;+ $itemEvent = "{$entity->getEntityType()}.fieldUpdate.$field";if (!$this->eventExists($itemEvent)) {continue;diff --git a/application/Espo/Core/Webhook/Queue.php b/application/Espo/Core/Webhook/Queue.phpindex b9c7597aba..0b89fa3613 100644--- a/application/Espo/Core/Webhook/Queue.php+++ b/application/Espo/Core/Webhook/Queue.php@@ -77,15 +77,14 @@ class Queue{$portionSize = $this->config->get('webhookQueueEventPortionSize', self::EVENT_PORTION_SIZE);- /** @var iterable<WebhookEventQueueItem> $itemList */- $itemList = $this->entityManager- ->getRDBRepository(WebhookEventQueueItem::ENTITY_TYPE)+ $items = $this->entityManager+ ->getRDBRepositoryByClass(WebhookEventQueueItem::class)->where(['isProcessed' => false])->order('number')->limit(0, $portionSize)->find();- foreach ($itemList as $item) {+ foreach ($items as $item) {$this->createQueueFromEvent($item);$item->setIsProcessed();@@ -129,8 +128,8 @@ class Queue{$portionSize = $this->config->get('webhookQueuePortionSize', self::PORTION_SIZE);- $groupedItemList = $this->entityManager- ->getRDBRepository(WebhookQueueItem::ENTITY_TYPE)+ $groupedItems = $this->entityManager+ ->getRDBRepositoryByClass(WebhookQueueItem::class)->select(['webhookId','number',@@ -157,8 +156,8 @@ class Queue->order('number')->find();- foreach ($groupedItemList as $groupItem) {- $this->processSendingGroup($groupItem->get('webhookId'));+ foreach ($groupedItems as $groupItem) {+ $this->processSendingGroup($groupItem->getWebhookId());}}@@ -166,8 +165,8 @@ class Queue{$batchSize = $this->config->get('webhookBatchSize', self::BATCH_SIZE);- $itemList = $this->entityManager- ->getRDBRepository(WebhookQueueItem::ENTITY_TYPE)+ $items = $this->entityManager+ ->getRDBRepositoryByClass(WebhookQueueItem::class)->where(['webhookId' => $webhookId,'status' => WebhookQueueItem::STATUS_PENDING,@@ -183,7 +182,7 @@ class Queue$webhook = $this->entityManager->getRDBRepositoryByClass(Webhook::class)->getById($webhookId);if (!$webhook || !$webhook->isActive()) {- foreach ($itemList as $item) {+ foreach ($items as $item) {$this->deleteQueueItem($item);}@@ -198,7 +197,7 @@ class Queue$user = $this->entityManager->getRDBRepositoryByClass(User::class)->getById($webhook->getUserId());if (!$user) {- foreach ($itemList as $item) {+ foreach ($items as $item) {$this->deleteQueueItem($item);}@@ -213,7 +212,7 @@ class Queue$dataList = [];- foreach ($itemList as $item) {+ foreach ($items as $item) {$data = $this->prepareItemData($item, $user, $forbiddenAttributeList);if ($data === null) {@@ -225,7 +224,7 @@ class Queue$dataList[] = $data;}- if (empty($dataList)) {+ if ($dataList === []) {return;}@@ -348,8 +347,8 @@ class Queueprotected function dropWebhook(Webhook $webhook): void{- $itemList = $this->entityManager- ->getRDBRepository(WebhookQueueItem::ENTITY_TYPE)+ $items = $this->entityManager+ ->getRDBRepositoryByClass(WebhookQueueItem::class)->where(['status' => WebhookQueueItem::STATUS_PENDING,'webhookId' => $webhook->getId(),@@ -357,7 +356,7 @@ class Queue->order('number')->find();- foreach ($itemList as $item) {+ foreach ($items as $item) {$this->deleteQueueItem($item);}@@ -366,7 +365,6 @@ class Queueprotected function succeedQueueItem(WebhookQueueItem $item): void{-$item->setAttempts($item->getAttempts() + 1)->setStatus(WebhookQueueItem::STATUS_SUCCESS)diff --git a/application/Espo/Entities/Webhook.php b/application/Espo/Entities/Webhook.phpindex e80571977c..b56111fc31 100644--- a/application/Espo/Entities/Webhook.php+++ b/application/Espo/Entities/Webhook.php@@ -35,9 +35,9 @@ class Webhook extends Entity{public const ENTITY_TYPE = 'Webhook';- public function getEvent(): ?string+ public function getEvent(): string{- return $this->get('event');+ return $this->get('event') ?? '';}public function getSecretKey(): ?stringdiff --git a/application/Espo/Entities/WebhookQueueItem.php b/application/Espo/Entities/WebhookQueueItem.phpindex e66f9b1f53..71f3c0e409 100644--- a/application/Espo/Entities/WebhookQueueItem.php+++ b/application/Espo/Entities/WebhookQueueItem.php@@ -98,6 +98,11 @@ class WebhookQueueItem extends Entityreturn $this->get('targetId');}+ public function getWebhookId(): string+ {+ return $this->get('webhookId') ?? '';+ }+public function getData(): stdClass{return $this->get('data') ?? (object) [];