webhook service refactoring

This commit is contained in:
Yuri Kuznetsov
2020-06-27 12:13:20 +03:00
parent fd4c49d3d2
commit aef08dcd75
3 changed files with 90 additions and 13 deletions
@@ -0,0 +1,37 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Di;
use Espo\Core\Webhook\Manager;
interface WebhookManagerAware
{
public function setWebhookManager(Manager $webhookManager);
}
@@ -0,0 +1,42 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Di;
use Espo\Core\Webhook\Manager;
trait WebhookManagerSetter
{
protected $webhookManager;
public function setWebhookManager(Manager $webhookManager)
{
$this->webhookManager = $webhookManager;
}
}
+11 -13
View File
@@ -35,8 +35,14 @@ use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\BadRequest;
class Webhook extends Record
use Espo\Core\Di;
class Webhook extends Record implements
Di\WebhookManagerAware
{
use Di\WebhookManagerSetter;
const WEBHOOK_MAX_COUNT_PER_USER = 50;
protected $eventTypeList = [
@@ -50,14 +56,6 @@ class Webhook extends Record
protected $readOnlyAttributeList = ['secretKey'];
protected function init()
{
parent::init();
$this->addDependencyList([
'webhookManager',
]);
}
public function populateDefaults(Entity $entity, $data)
{
parent::populateDefaults($entity, $data);
@@ -170,14 +168,14 @@ class Webhook extends Record
protected function afterCreateEntity(Entity $entity, $data)
{
if ($entity->get('isActive')) {
$this->getInjection('webhookManager')->addEvent($entity->get('event'));
$this->webhookManager->addEvent($entity->get('event'));
}
}
protected function afterDeleteEntity(Entity $entity)
{
if ($entity->get('isActive')) {
$this->getInjection('webhookManager')->removeEvent($entity->get('event'));
$this->webhookManager->removeEvent($entity->get('event'));
}
}
@@ -185,9 +183,9 @@ class Webhook extends Record
{
if (isset($data->isActive)) {
if ($entity->get('isActive')) {
$this->getInjection('webhookManager')->addEvent($entity->get('event'));
$this->webhookManager->addEvent($entity->get('event'));
} else {
$this->getInjection('webhookManager')->removeEvent($entity->get('event'));
$this->webhookManager->removeEvent($entity->get('event'));
}
}
}