From 05d47a736c0cc003a5f91430a90669ce4f399308 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Thu, 14 Nov 2019 11:34:36 +0100 Subject: [PATCH 01/56] Remove deprecated methods --- .../Controller/AjaxController.php | 30 ------------------ .../Integration/AbstractIntegration.php | 31 ------------------- 2 files changed, 61 deletions(-) diff --git a/app/bundles/PluginBundle/Controller/AjaxController.php b/app/bundles/PluginBundle/Controller/AjaxController.php index ba494d6373c..88ca5a30fdf 100644 --- a/app/bundles/PluginBundle/Controller/AjaxController.php +++ b/app/bundles/PluginBundle/Controller/AjaxController.php @@ -130,36 +130,6 @@ protected function getIntegrationFieldsAction(Request $request) return $this->sendJsonResponse($dataArray); } - /** - * Get the HTML for list of fields. - * - * @deprecated 2.8.0 to be removed in 3.0 - * - * @return \Symfony\Component\HttpFoundation\JsonResponse - */ - protected function getIntegrationLeadFieldsAction(Request $request) - { - $request->attributes->set('object', 'lead'); - - return $this->getIntegrationFieldsAction($request); - } - - /** - * Get the HTML for list of fields. - * - * @deprecated 2.8.0 to be removed in 3.0 - * - * @param Request $request - * - * @return \Symfony\Component\HttpFoundation\JsonResponse - */ - protected function getIntegrationCompanyFieldsAction(Request $request) - { - $request->attributes->set('object', 'company'); - - return $this->getIntegrationFieldsAction($request); - } - /** * Get the HTML for integration properties. * diff --git a/app/bundles/PluginBundle/Integration/AbstractIntegration.php b/app/bundles/PluginBundle/Integration/AbstractIntegration.php index 0156b978e32..4e7a40a2190 100644 --- a/app/bundles/PluginBundle/Integration/AbstractIntegration.php +++ b/app/bundles/PluginBundle/Integration/AbstractIntegration.php @@ -231,8 +231,6 @@ public function __construct(MauticFactory $factory = null) $this->fieldModel = $factory->getModel('lead.field'); $this->integrationEntityModel = $factory->getModel('plugin.integration_entity'); } - - $this->init(); } /** @@ -387,16 +385,6 @@ public function getTranslator() return $this->translator; } - /** - * Called on construct. - * - * @deprecated 2.8.2 To be removed in 3.0 - * Setup your integration in the class constructor instead - */ - public function init() - { - } - /** * @return bool */ @@ -1600,25 +1588,6 @@ public function getBearerToken($inAuthorization = false) return ''; } - /** - * Gets the ID of the user for the integration. - * - * @param $identifier - * @param array $socialCache - * - * @deprecated To be removed 2.0 - * - * @return mixed - */ - public function getUserId($identifier, &$socialCache) - { - if (!empty($socialCache['id'])) { - return $socialCache['id']; - } - - return false; - } - /** * Get an array of public activity. * From fef2552ea7a07eb7d7c490a4b7e8029e23259dc6 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Thu, 14 Nov 2019 11:36:00 +0100 Subject: [PATCH 02/56] Remove deprecated \Mautic\PluginBundle\Integration\AbstractIntegration::setFactory --- .../PluginBundle/Integration/AbstractIntegration.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/bundles/PluginBundle/Integration/AbstractIntegration.php b/app/bundles/PluginBundle/Integration/AbstractIntegration.php index 4e7a40a2190..27ec65a12fd 100644 --- a/app/bundles/PluginBundle/Integration/AbstractIntegration.php +++ b/app/bundles/PluginBundle/Integration/AbstractIntegration.php @@ -233,17 +233,6 @@ public function __construct(MauticFactory $factory = null) } } - /** - * @param MauticFactory $factory - * - * @deprecated 2.8.2 To be removed in 3.0. Use constructor arguments - * to set dependencies instead - */ - public function setFactory(MauticFactory $factory) - { - $this->factory = $factory; - } - /** * @param FieldModel $fieldModel */ From 092fcaa71c3f25295c5d9ec0f0c7da23dba70682 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Thu, 14 Nov 2019 11:37:53 +0100 Subject: [PATCH 03/56] Remove support for deprecated 3rd party plugins in \Mautic\PluginBundle\Helper\IntegrationHelper --- .../PluginBundle/Helper/IntegrationHelper.php | 41 ------------------- 1 file changed, 41 deletions(-) diff --git a/app/bundles/PluginBundle/Helper/IntegrationHelper.php b/app/bundles/PluginBundle/Helper/IntegrationHelper.php index 2e571903e1f..b6b78a52266 100644 --- a/app/bundles/PluginBundle/Helper/IntegrationHelper.php +++ b/app/bundles/PluginBundle/Helper/IntegrationHelper.php @@ -178,30 +178,6 @@ public function getIntegrationObjects($specificIntegrations = null, $withFeature $newIntegrations[] = $newIntegration; unset($newIntegration); - } else { - /** - * @deprecated: 2.8.2 To be removed in 3.0 - * This keeps BC for 3rd party plugins - */ - $class = '\\MauticPlugin\\'.$pluginNamespace.'\\Integration\\'.$integrationName.'Integration'; - $refClass = new \ReflectionClass($class); - - if ($refClass->isInstantiable()) { - $this->integrations[$integrationName] = new $class($this->factory); - $features = $this->integrations[$integrationName]->getSupportedFeatures(); - - $newIntegration->setSupportedFeatures($features); - - // Go ahead and stash it since it's built already - $this->integrations[$integrationName]->setIntegrationSettings($newIntegration); - - $newIntegrations[] = $newIntegration; - - unset($newIntegration); - } else { - // Something is bad so ignore - continue; - } } } @@ -334,23 +310,6 @@ public function getIntegrationObjects($specificIntegrations = null, $withFeature if ($this->container->has($integrationContainerKey)) { $this->integrations[$integrationName] = $this->container->get($integrationContainerKey); $this->integrations[$integrationName]->setIntegrationSettings($integration['settings']); - } else { - /** - * @deprecated: 2.8.2 To be removed in 3.0 - * This keeps BC for 3rd party plugins - */ - $rootNamespace = $integration['isPlugin'] ? '\\MauticPlugin\\' : '\\Mautic\\'; - $class = $rootNamespace.$integration['namespace'].'\\Integration\\'.$integrationName.'Integration'; - $refClass = new \ReflectionClass($class); - - if ($refClass->isInstantiable()) { - $this->integrations[$integrationName] = new $class($this->factory); - - $this->integrations[$integrationName]->setIntegrationSettings($integration['settings']); - } else { - // Something is bad so ignore - continue; - } } } From df02bdff2c05351a620b7c06e69a37f3fbaea989 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Thu, 14 Nov 2019 11:39:03 +0100 Subject: [PATCH 04/56] Revert "Remove deprecated \Mautic\PluginBundle\Integration\AbstractIntegration::setFactory" This reverts commit fef2552ea7a07eb7d7c490a4b7e8029e23259dc6. --- .../PluginBundle/Integration/AbstractIntegration.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/bundles/PluginBundle/Integration/AbstractIntegration.php b/app/bundles/PluginBundle/Integration/AbstractIntegration.php index 27ec65a12fd..4e7a40a2190 100644 --- a/app/bundles/PluginBundle/Integration/AbstractIntegration.php +++ b/app/bundles/PluginBundle/Integration/AbstractIntegration.php @@ -233,6 +233,17 @@ public function __construct(MauticFactory $factory = null) } } + /** + * @param MauticFactory $factory + * + * @deprecated 2.8.2 To be removed in 3.0. Use constructor arguments + * to set dependencies instead + */ + public function setFactory(MauticFactory $factory) + { + $this->factory = $factory; + } + /** * @param FieldModel $fieldModel */ From 331157338b9b4795c4a05df8ac4f5e2249e1659a Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Thu, 14 Nov 2019 13:24:34 +0100 Subject: [PATCH 05/56] Remove MauticFactory from \Mautic\PluginBundle\Integration\AbstractIntegration constructor --- .../NotificationBundle/Config/config.php | 19 ++++- .../Integration/AbstractIntegration.php | 78 ++++++++++++------- app/bundles/SmsBundle/Config/config.php | 19 ++++- .../MauticClearbitBundle/Config/config.php | 15 ++++ .../MauticFullContactBundle/Config/config.php | 15 ++++ plugins/MauticGmailBundle/Config/config.php | 15 ++++ plugins/MauticOutlookBundle/Config/config.php | 15 ++++ 7 files changed, 146 insertions(+), 30 deletions(-) diff --git a/app/bundles/NotificationBundle/Config/config.php b/app/bundles/NotificationBundle/Config/config.php index 06ec4ca71b6..4f99252e07f 100644 --- a/app/bundles/NotificationBundle/Config/config.php +++ b/app/bundles/NotificationBundle/Config/config.php @@ -152,7 +152,24 @@ ], 'integrations' => [ 'mautic.integration.onesignal' => [ - 'class' => \Mautic\NotificationBundle\Integration\OneSignalIntegration::class, + 'class' => \Mautic\NotificationBundle\Integration\OneSignalIntegration::class, + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + ], ], ], ], diff --git a/app/bundles/PluginBundle/Integration/AbstractIntegration.php b/app/bundles/PluginBundle/Integration/AbstractIntegration.php index 4e7a40a2190..991008987be 100644 --- a/app/bundles/PluginBundle/Integration/AbstractIntegration.php +++ b/app/bundles/PluginBundle/Integration/AbstractIntegration.php @@ -38,6 +38,7 @@ use Mautic\PluginBundle\Helper\oAuthHelper; use Mautic\PluginBundle\Model\IntegrationEntityModel; use Mautic\PluginBundle\PluginEvents; +use Monolog\Logger; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\FormBuilder; @@ -47,6 +48,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Router; +use Symfony\Component\Translation\DataCollectorTranslator; use Symfony\Component\Translation\TranslatorInterface; /** @@ -203,34 +205,54 @@ abstract class AbstractIntegration protected $commandParameters = []; /** - * AbstractIntegration constructor. - */ - public function __construct(MauticFactory $factory = null) - { - /* - * @deprecated: 2.8.2 To be removed in 3.0 - * This keeps BC with 3rd party plugins that - * don't use the container for the - * integration pass to set all of these properties - */ - if ($factory) { - $this->factory = $factory; - $this->dispatcher = $factory->getDispatcher(); - $this->cache = $factory->getHelper('cache_storage')->getCache($this->getName()); - $this->em = $factory->getEntityManager(); - $this->session = (!defined('IN_MAUTIC_CONSOLE')) ? $factory->getSession() : null; - $this->request = $factory->getRequest(); - $this->router = $factory->getRouter(); - $this->translator = $factory->getTranslator(); - $this->logger = $factory->getLogger(); - $this->encryptionHelper = $factory->getHelper('encryption'); - $this->leadModel = $factory->getModel('lead'); - $this->companyModel = $factory->getModel('lead.company'); - $this->pathsHelper = $factory->getHelper('paths'); - $this->notificationModel = $factory->getModel('core.notification'); - $this->fieldModel = $factory->getModel('lead.field'); - $this->integrationEntityModel = $factory->getModel('plugin.integration_entity'); - } + * @param EventDispatcherInterface $eventDispatcher + * @param CacheStorageHelper $cacheStorageHelper + * @param EntityManager $entityManager + * @param Session $session + * @param RequestStack $requestStack + * @param Router $router + * @param DataCollectorTranslator $translator + * @param Logger $logger + * @param EncryptionHelper $encryptionHelper + * @param LeadModel $leadModel + * @param CompanyModel $companyModel + * @param PathsHelper $pathsHelper + * @param NotificationModel $notificationModel + * @param FieldModel $fieldModel + * @param IntegrationEntityModel $integrationEntityModel + */ + public function __construct( + EventDispatcherInterface $eventDispatcher, + CacheStorageHelper $cacheStorageHelper, + EntityManager $entityManager, + Session $session, + RequestStack $requestStack, + Router $router, + DataCollectorTranslator $translator, + Logger $logger, + EncryptionHelper $encryptionHelper, + LeadModel $leadModel, + CompanyModel $companyModel, + PathsHelper $pathsHelper, + NotificationModel $notificationModel, + FieldModel $fieldModel, + IntegrationEntityModel $integrationEntityModel + ) { + $this->dispatcher = $eventDispatcher; + $this->cache = $cacheStorageHelper->getCache($this->getName()); + $this->em = $entityManager; + $this->session = (!defined('IN_MAUTIC_CONSOLE')) ? $session : null; + $this->request = $requestStack->getCurrentRequest(); + $this->router = $router; + $this->translator = $translator; + $this->logger = $logger; + $this->encryptionHelper = $encryptionHelper; + $this->leadModel = $leadModel; + $this->companyModel = $companyModel; + $this->pathsHelper = $pathsHelper; + $this->notificationModel = $notificationModel; + $this->fieldModel = $fieldModel; + $this->integrationEntityModel = $integrationEntityModel; } /** diff --git a/app/bundles/SmsBundle/Config/config.php b/app/bundles/SmsBundle/Config/config.php index f4fff31b95d..5022d27a85e 100644 --- a/app/bundles/SmsBundle/Config/config.php +++ b/app/bundles/SmsBundle/Config/config.php @@ -141,7 +141,24 @@ ], 'integrations' => [ 'mautic.integration.twilio' => [ - 'class' => \Mautic\SmsBundle\Integration\TwilioIntegration::class, + 'class' => \Mautic\SmsBundle\Integration\TwilioIntegration::class, + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + ], ], ], 'repositories' => [ diff --git a/plugins/MauticClearbitBundle/Config/config.php b/plugins/MauticClearbitBundle/Config/config.php index 4b9a8d5b9a5..31b2437c600 100644 --- a/plugins/MauticClearbitBundle/Config/config.php +++ b/plugins/MauticClearbitBundle/Config/config.php @@ -71,6 +71,21 @@ 'mautic.integration.clearbit' => [ 'class' => \MauticPlugin\MauticClearbitBundle\Integration\ClearbitIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], diff --git a/plugins/MauticFullContactBundle/Config/config.php b/plugins/MauticFullContactBundle/Config/config.php index 21f28919b30..d9fecc80e0d 100644 --- a/plugins/MauticFullContactBundle/Config/config.php +++ b/plugins/MauticFullContactBundle/Config/config.php @@ -71,6 +71,21 @@ 'mautic.integration.fullcontact' => [ 'class' => \MauticPlugin\MauticFullContactBundle\Integration\FullContactIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], diff --git a/plugins/MauticGmailBundle/Config/config.php b/plugins/MauticGmailBundle/Config/config.php index 5169cab7e55..9b777e4d8fa 100644 --- a/plugins/MauticGmailBundle/Config/config.php +++ b/plugins/MauticGmailBundle/Config/config.php @@ -19,6 +19,21 @@ 'mautic.integration.gmail' => [ 'class' => \MauticPlugin\MauticGmailBundle\Integration\GmailIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], diff --git a/plugins/MauticOutlookBundle/Config/config.php b/plugins/MauticOutlookBundle/Config/config.php index a0b6481e308..8c65fd25cf2 100644 --- a/plugins/MauticOutlookBundle/Config/config.php +++ b/plugins/MauticOutlookBundle/Config/config.php @@ -19,6 +19,21 @@ 'mautic.integration.outlook' => [ 'class' => \MauticPlugin\MauticOutlookBundle\Integration\OutlookIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], From 117af72a02a06a0ee12e6e45528fb23e645c880a Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Thu, 14 Nov 2019 17:31:59 +0100 Subject: [PATCH 06/56] Fix DynamicsApiTest dependencies --- .../MauticCrmBundle/Tests/DynamicsApiTest.php | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php b/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php index 7ee230d1dd9..5733128b576 100644 --- a/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php +++ b/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php @@ -8,8 +8,23 @@ namespace MauticCrmBundle\Api; +use Doctrine\ORM\EntityManager; +use Mautic\CoreBundle\Helper\CacheStorageHelper; +use Mautic\CoreBundle\Helper\EncryptionHelper; +use Mautic\CoreBundle\Helper\PathsHelper; +use Mautic\CoreBundle\Model\NotificationModel; +use Mautic\LeadBundle\Model\CompanyModel; +use Mautic\LeadBundle\Model\FieldModel; +use Mautic\LeadBundle\Model\LeadModel; +use Mautic\PluginBundle\Model\IntegrationEntityModel; use MauticPlugin\MauticCrmBundle\Api\DynamicsApi; use MauticPlugin\MauticCrmBundle\Integration\DynamicsIntegration; +use Monolog\Logger; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\Routing\Router; +use Symfony\Component\Translation\DataCollectorTranslator; class DynamicsApiTest extends \PHPUnit_Framework_TestCase { @@ -19,11 +34,60 @@ class DynamicsApiTest extends \PHPUnit_Framework_TestCase /** @var DynamicsIntegration */ private $integration; + private $dispatcher; + private $cache; + private $em; + private $session; + private $request; + private $router; + private $translator; + private $logger; + private $encryptionHelper; + private $leadModel; + private $companyModel; + private $pathsHelper; + private $notificationModel; + private $fieldModel; + private $integrationEntityModel; + protected function setUp() { parent::setUp(); - $this->integration = new DynamicsIntegration(); + $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->cache = $this->createMock(CacheStorageHelper::class); + $this->em = $this->createMock(EntityManager::class); + $this->session = $this->createMock(Session::class); + $this->request = $this->createMock(RequestStack::class); + $this->router = $this->createMock(Router::class); + $this->translator = $this->createMock(DataCollectorTranslator::class); + $this->logger = $this->createMock(Logger::class); + $this->encryptionHelper = $this->createMock(EncryptionHelper::class); + $this->leadModel = $this->createMock(LeadModel::class); + $this->companyModel = $this->createMock(CompanyModel::class); + $this->pathsHelper = $this->createMock(PathsHelper::class); + $this->notificationModel = $this->createMock(NotificationModel::class); + $this->fieldModel = $this->createMock(FieldModel::class); + $this->integrationEntityModel = $this->createMock(IntegrationEntityModel::class); + + $this->integration = new DynamicsIntegration( + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $this->companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $this->integrationEntityModel + ); + $this->api = new DynamicsApi($this->integration); } From e384991885c2bbb76df86f26facc676e712297a0 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Thu, 14 Nov 2019 17:51:13 +0100 Subject: [PATCH 07/56] Fix ZohoIntegrationTest dependencies --- .../Tests/ZohoIntegrationTest.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php b/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php index 9ff2a37c5ff..b717a00c548 100644 --- a/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php @@ -10,12 +10,26 @@ namespace MauticPlugin\MauticCrmBundle\Integration; +use Doctrine\ORM\EntityManager; +use Mautic\CoreBundle\Helper\CacheStorageHelper; use Mautic\CoreBundle\Helper\EncryptionHelper; +use Mautic\CoreBundle\Helper\PathsHelper; +use Mautic\CoreBundle\Model\NotificationModel; use Mautic\LeadBundle\Entity\Lead; +use Mautic\LeadBundle\Model\CompanyModel; +use Mautic\LeadBundle\Model\FieldModel; +use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Entity\Integration; +use Mautic\PluginBundle\Model\IntegrationEntityModel; use MauticPlugin\MauticCrmBundle\Api\CrmApi; +use Monolog\Logger; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\Routing\Router; +use Symfony\Component\Translation\DataCollectorTranslator; use Symfony\Component\Translation\Translator; /** @@ -26,6 +40,22 @@ class ZohoIntegrationTest extends \PHPUnit_Framework_TestCase /** @var ZohoIntegration */ private $integration; + private $dispatcher; + private $cache; + private $em; + private $session; + private $request; + private $router; + private $translator; + private $logger; + private $encryptionHelper; + private $leadModel; + private $companyModel; + private $pathsHelper; + private $notificationModel; + private $fieldModel; + private $integrationEntityModel; + /** * Set up tests. */ @@ -33,6 +63,22 @@ protected function setUp() { parent::setUp(); + $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->cache = $this->createMock(CacheStorageHelper::class); + $this->em = $this->createMock(EntityManager::class); + $this->session = $this->createMock(Session::class); + $this->request = $this->createMock(RequestStack::class); + $this->router = $this->createMock(Router::class); + $this->translator = $this->createMock(DataCollectorTranslator::class); + $this->logger = $this->createMock(Logger::class); + $this->encryptionHelper = $this->createMock(EncryptionHelper::class); + $this->leadModel = $this->createMock(LeadModel::class); + $this->companyModel = $this->createMock(CompanyModel::class); + $this->pathsHelper = $this->createMock(PathsHelper::class); + $this->notificationModel = $this->createMock(NotificationModel::class); + $this->fieldModel = $this->createMock(FieldModel::class); + $this->integrationEntityModel = $this->createMock(IntegrationEntityModel::class); + $encryptionHelper = $this->getMockBuilder(EncryptionHelper::class) ->disableOriginalConstructor() ->setMethods(['decrypt']) @@ -49,6 +95,23 @@ protected function setUp() ->willReturnArgument(0); $this->integration = $this->getMockBuilder(ZohoIntegration::class) ->setMethods(['getApiHelper']) + ->setConstructorArgs([ + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $this->companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $this->integrationEntityModel, + ]) ->getMock(); $this->integration->setTranslator($translator); From b67a9629e43ad0bcd8d8a0193e2c47d6adb7491d Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 15 Nov 2019 10:49:44 +0100 Subject: [PATCH 08/56] Fix DynamicsIntegrationTest dependencies --- .../Tests/DynamicsIntegrationTest.php | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php b/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php index 51ed1911002..7b994a587e3 100644 --- a/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php @@ -8,18 +8,81 @@ namespace MauticCrmBundle\Integration; +use Doctrine\ORM\EntityManager; +use Mautic\CoreBundle\Helper\CacheStorageHelper; +use Mautic\CoreBundle\Helper\EncryptionHelper; +use Mautic\CoreBundle\Helper\PathsHelper; +use Mautic\CoreBundle\Model\NotificationModel; +use Mautic\LeadBundle\Model\CompanyModel; +use Mautic\LeadBundle\Model\FieldModel; +use Mautic\LeadBundle\Model\LeadModel; +use Mautic\PluginBundle\Model\IntegrationEntityModel; use MauticPlugin\MauticCrmBundle\Integration\DynamicsIntegration; +use Monolog\Logger; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\Routing\Router; +use Symfony\Component\Translation\DataCollectorTranslator; class DynamicsIntegrationTest extends \PHPUnit_Framework_TestCase { /** @var DynamicsIntegration */ private $integration; + private $dispatcher; + private $cache; + private $em; + private $session; + private $request; + private $router; + private $translator; + private $logger; + private $encryptionHelper; + private $leadModel; + private $companyModel; + private $pathsHelper; + private $notificationModel; + private $fieldModel; + private $integrationEntityModel; + protected function setUp() { parent::setUp(); - $this->integration = new DynamicsIntegration(); + $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->cache = $this->createMock(CacheStorageHelper::class); + $this->em = $this->createMock(EntityManager::class); + $this->session = $this->createMock(Session::class); + $this->request = $this->createMock(RequestStack::class); + $this->router = $this->createMock(Router::class); + $this->translator = $this->createMock(DataCollectorTranslator::class); + $this->logger = $this->createMock(Logger::class); + $this->encryptionHelper = $this->createMock(EncryptionHelper::class); + $this->leadModel = $this->createMock(LeadModel::class); + $this->companyModel = $this->createMock(CompanyModel::class); + $this->pathsHelper = $this->createMock(PathsHelper::class); + $this->notificationModel = $this->createMock(NotificationModel::class); + $this->fieldModel = $this->createMock(FieldModel::class); + $this->integrationEntityModel = $this->createMock(IntegrationEntityModel::class); + + $this->integration = new DynamicsIntegration( + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $this->companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $this->integrationEntityModel + ); } public function testIntegration() From a49c9de66e19f38a5a06e4703fa46ce347004809 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 15 Nov 2019 12:00:51 +0100 Subject: [PATCH 09/56] Refactor integration tests --- .../Integration/AbstractIntegrationTest.php | 2 +- .../AbstractIntegrationTestCase.php | 126 ++++++++++++++++++ .../MauticCrmBundle/Tests/DynamicsApiTest.php | 50 +------ .../Tests/DynamicsIntegrationTest.php | 50 +------ .../Tests/ZohoIntegrationTest.php | 49 +------ 5 files changed, 133 insertions(+), 144 deletions(-) create mode 100644 app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php diff --git a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTest.php b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTest.php index be57eaf0e86..a5501444d70 100644 --- a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTest.php +++ b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTest.php @@ -15,7 +15,7 @@ use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Integration\AbstractIntegration; -class AbstractIntegrationTest extends \PHPUnit_Framework_TestCase +class AbstractIntegrationTest extends AbstractIntegrationTestCase { public function testPopulatedLeadDataReturnsIntAndNotDncEntityForMauticContactIsContactableByEmail() { diff --git a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php new file mode 100644 index 00000000000..5c00905823c --- /dev/null +++ b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php @@ -0,0 +1,126 @@ +dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->cache = $this->createMock(CacheStorageHelper::class); + $this->em = $this->createMock(EntityManager::class); + $this->session = $this->createMock(Session::class); + $this->request = $this->createMock(RequestStack::class); + $this->router = $this->createMock(Router::class); + $this->translator = $this->createMock(DataCollectorTranslator::class); + $this->logger = $this->createMock(Logger::class); + $this->encryptionHelper = $this->createMock(EncryptionHelper::class); + $this->leadModel = $this->createMock(LeadModel::class); + $this->companyModel = $this->createMock(CompanyModel::class); + $this->pathsHelper = $this->createMock(PathsHelper::class); + $this->notificationModel = $this->createMock(NotificationModel::class); + $this->fieldModel = $this->createMock(FieldModel::class); + $this->integrationEntityModel = $this->createMock(IntegrationEntityModel::class); + } +} diff --git a/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php b/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php index 5733128b576..68382bca6e0 100644 --- a/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php +++ b/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php @@ -8,25 +8,11 @@ namespace MauticCrmBundle\Api; -use Doctrine\ORM\EntityManager; -use Mautic\CoreBundle\Helper\CacheStorageHelper; -use Mautic\CoreBundle\Helper\EncryptionHelper; -use Mautic\CoreBundle\Helper\PathsHelper; -use Mautic\CoreBundle\Model\NotificationModel; -use Mautic\LeadBundle\Model\CompanyModel; -use Mautic\LeadBundle\Model\FieldModel; -use Mautic\LeadBundle\Model\LeadModel; -use Mautic\PluginBundle\Model\IntegrationEntityModel; +use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Api\DynamicsApi; use MauticPlugin\MauticCrmBundle\Integration\DynamicsIntegration; -use Monolog\Logger; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpFoundation\Session\Session; -use Symfony\Component\Routing\Router; -use Symfony\Component\Translation\DataCollectorTranslator; -class DynamicsApiTest extends \PHPUnit_Framework_TestCase +class DynamicsApiTest extends AbstractIntegrationTestCase { /** @var DynamicsApi */ private $api; @@ -34,42 +20,10 @@ class DynamicsApiTest extends \PHPUnit_Framework_TestCase /** @var DynamicsIntegration */ private $integration; - private $dispatcher; - private $cache; - private $em; - private $session; - private $request; - private $router; - private $translator; - private $logger; - private $encryptionHelper; - private $leadModel; - private $companyModel; - private $pathsHelper; - private $notificationModel; - private $fieldModel; - private $integrationEntityModel; - protected function setUp() { parent::setUp(); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - $this->cache = $this->createMock(CacheStorageHelper::class); - $this->em = $this->createMock(EntityManager::class); - $this->session = $this->createMock(Session::class); - $this->request = $this->createMock(RequestStack::class); - $this->router = $this->createMock(Router::class); - $this->translator = $this->createMock(DataCollectorTranslator::class); - $this->logger = $this->createMock(Logger::class); - $this->encryptionHelper = $this->createMock(EncryptionHelper::class); - $this->leadModel = $this->createMock(LeadModel::class); - $this->companyModel = $this->createMock(CompanyModel::class); - $this->pathsHelper = $this->createMock(PathsHelper::class); - $this->notificationModel = $this->createMock(NotificationModel::class); - $this->fieldModel = $this->createMock(FieldModel::class); - $this->integrationEntityModel = $this->createMock(IntegrationEntityModel::class); - $this->integration = new DynamicsIntegration( $this->dispatcher, $this->cache, diff --git a/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php b/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php index 7b994a587e3..6afc41cf4da 100644 --- a/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php @@ -8,64 +8,18 @@ namespace MauticCrmBundle\Integration; -use Doctrine\ORM\EntityManager; -use Mautic\CoreBundle\Helper\CacheStorageHelper; -use Mautic\CoreBundle\Helper\EncryptionHelper; -use Mautic\CoreBundle\Helper\PathsHelper; -use Mautic\CoreBundle\Model\NotificationModel; -use Mautic\LeadBundle\Model\CompanyModel; -use Mautic\LeadBundle\Model\FieldModel; -use Mautic\LeadBundle\Model\LeadModel; -use Mautic\PluginBundle\Model\IntegrationEntityModel; +use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Integration\DynamicsIntegration; -use Monolog\Logger; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpFoundation\Session\Session; -use Symfony\Component\Routing\Router; -use Symfony\Component\Translation\DataCollectorTranslator; -class DynamicsIntegrationTest extends \PHPUnit_Framework_TestCase +class DynamicsIntegrationTest extends AbstractIntegrationTestCase { /** @var DynamicsIntegration */ private $integration; - private $dispatcher; - private $cache; - private $em; - private $session; - private $request; - private $router; - private $translator; - private $logger; - private $encryptionHelper; - private $leadModel; - private $companyModel; - private $pathsHelper; - private $notificationModel; - private $fieldModel; - private $integrationEntityModel; - protected function setUp() { parent::setUp(); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - $this->cache = $this->createMock(CacheStorageHelper::class); - $this->em = $this->createMock(EntityManager::class); - $this->session = $this->createMock(Session::class); - $this->request = $this->createMock(RequestStack::class); - $this->router = $this->createMock(Router::class); - $this->translator = $this->createMock(DataCollectorTranslator::class); - $this->logger = $this->createMock(Logger::class); - $this->encryptionHelper = $this->createMock(EncryptionHelper::class); - $this->leadModel = $this->createMock(LeadModel::class); - $this->companyModel = $this->createMock(CompanyModel::class); - $this->pathsHelper = $this->createMock(PathsHelper::class); - $this->notificationModel = $this->createMock(NotificationModel::class); - $this->fieldModel = $this->createMock(FieldModel::class); - $this->integrationEntityModel = $this->createMock(IntegrationEntityModel::class); - $this->integration = new DynamicsIntegration( $this->dispatcher, $this->cache, diff --git a/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php b/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php index b717a00c548..1f64b0cb4d1 100644 --- a/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php @@ -10,52 +10,23 @@ namespace MauticPlugin\MauticCrmBundle\Integration; -use Doctrine\ORM\EntityManager; -use Mautic\CoreBundle\Helper\CacheStorageHelper; use Mautic\CoreBundle\Helper\EncryptionHelper; -use Mautic\CoreBundle\Helper\PathsHelper; -use Mautic\CoreBundle\Model\NotificationModel; use Mautic\LeadBundle\Entity\Lead; -use Mautic\LeadBundle\Model\CompanyModel; -use Mautic\LeadBundle\Model\FieldModel; -use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Entity\Integration; -use Mautic\PluginBundle\Model\IntegrationEntityModel; +use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Api\CrmApi; -use Monolog\Logger; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventDispatcher; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpFoundation\Session\Session; -use Symfony\Component\Routing\Router; -use Symfony\Component\Translation\DataCollectorTranslator; use Symfony\Component\Translation\Translator; /** * Class ZohoIntegrationTest. */ -class ZohoIntegrationTest extends \PHPUnit_Framework_TestCase +class ZohoIntegrationTest extends AbstractIntegrationTestCase { /** @var ZohoIntegration */ private $integration; - private $dispatcher; - private $cache; - private $em; - private $session; - private $request; - private $router; - private $translator; - private $logger; - private $encryptionHelper; - private $leadModel; - private $companyModel; - private $pathsHelper; - private $notificationModel; - private $fieldModel; - private $integrationEntityModel; - /** * Set up tests. */ @@ -63,22 +34,6 @@ protected function setUp() { parent::setUp(); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - $this->cache = $this->createMock(CacheStorageHelper::class); - $this->em = $this->createMock(EntityManager::class); - $this->session = $this->createMock(Session::class); - $this->request = $this->createMock(RequestStack::class); - $this->router = $this->createMock(Router::class); - $this->translator = $this->createMock(DataCollectorTranslator::class); - $this->logger = $this->createMock(Logger::class); - $this->encryptionHelper = $this->createMock(EncryptionHelper::class); - $this->leadModel = $this->createMock(LeadModel::class); - $this->companyModel = $this->createMock(CompanyModel::class); - $this->pathsHelper = $this->createMock(PathsHelper::class); - $this->notificationModel = $this->createMock(NotificationModel::class); - $this->fieldModel = $this->createMock(FieldModel::class); - $this->integrationEntityModel = $this->createMock(IntegrationEntityModel::class); - $encryptionHelper = $this->getMockBuilder(EncryptionHelper::class) ->disableOriginalConstructor() ->setMethods(['decrypt']) From abcf2c7fc33bb86ba671f52b8fa4028856027c48 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 15 Nov 2019 12:42:30 +0100 Subject: [PATCH 10/56] Simplify mock object names --- .../Integration/SalesforceIntegrationTest.php | 99 ++++++++++--------- 1 file changed, 51 insertions(+), 48 deletions(-) diff --git a/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php b/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php index b6ac0cdad21..342e951ff2b 100644 --- a/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php @@ -30,6 +30,7 @@ use Mautic\PluginBundle\Event\PluginIntegrationKeyEvent; use Mautic\PluginBundle\Exception\ApiErrorException; use Mautic\PluginBundle\Model\IntegrationEntityModel; +use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Integration\SalesforceIntegration; use Monolog\Logger; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -38,7 +39,7 @@ /** * Class SalesforceIntegrationTest. */ -class SalesforceIntegrationTest extends \PHPUnit_Framework_TestCase +class SalesforceIntegrationTest extends AbstractIntegrationTestCase { const SC_MULTIPLE_SF_LEADS = 'multiple_sf_leads'; const SC_MULTIPLE_SF_CONTACTS = 'multiple_sf_contacts'; @@ -126,6 +127,8 @@ class SalesforceIntegrationTest extends \PHPUnit_Framework_TestCase public function setUp() { + parent::setUp(); + defined('MAUTIC_ENV') or define('MAUTIC_ENV', 'test'); } @@ -751,26 +754,26 @@ protected function getMaxInvocations($name) */ protected function getMockFactory() { - $mockFactory = $this->getMockBuilder(MauticFactory::class) + $mauticFactory = $this->getMockBuilder(MauticFactory::class) ->disableOriginalConstructor() ->getMock(); - $mockEntityManager = $this->getMockBuilder(EntityManager::class) + $entityManager = $this->getMockBuilder(EntityManager::class) ->disableOriginalConstructor() ->getMock(); - $mockIntegrationEntityRepository = $this->getMockBuilder(IntegrationEntityRepository::class) + $integrationEntityRepository = $this->getMockBuilder(IntegrationEntityRepository::class) ->disableOriginalConstructor() ->getMock(); // we need insight into the entities persisted - $mockIntegrationEntityRepository->method('saveEntities') + $integrationEntityRepository->method('saveEntities') ->willReturnCallback( function () { $this->persistedIntegrationEntities = array_merge($this->persistedIntegrationEntities, func_get_arg(0)); } ); - $mockIntegrationEntityRepository + $integrationEntityRepository ->expects($spy = $this->any()) ->method('getIntegrationsEntityId') ->willReturnCallback( @@ -783,11 +786,11 @@ function () use ($spy) { return $this->getLeadsToUpdate('Lead', 2, 2, 'Lead')['Lead']; } ); - $mockAuditLogRepo = $this->getMockBuilder(AuditLogRepository::class) + $auditLogRepo = $this->getMockBuilder(AuditLogRepository::class) ->disableOriginalConstructor() ->getMock(); - $mockAuditLogRepo + $auditLogRepo ->expects($this->any()) ->method('getAuditLogsForLeads') ->willReturn( @@ -817,17 +820,17 @@ function () use ($spy) { ] ); - $mockEntityManager->method('getRepository') + $entityManager->method('getRepository') ->will( $this->returnValueMap( [ - ['MauticPluginBundle:IntegrationEntity', $mockIntegrationEntityRepository], - ['MauticCoreBundle:AuditLog', $mockAuditLogRepo], + ['MauticPluginBundle:IntegrationEntity', $integrationEntityRepository], + ['MauticCoreBundle:AuditLog', $auditLogRepo], ] ) ); - $mockEntityManager->method('getReference') + $entityManager->method('getReference') ->willReturnCallback( function () { switch (func_get_arg(0)) { @@ -837,74 +840,74 @@ function () { } ); - $mockFactory->method('getEntityManager') - ->willReturn($mockEntityManager); + $mauticFactory->method('getEntityManager') + ->willReturn($entityManager); - $mockTranslator = $this->getMockBuilder(Translator::class) + $translator = $this->getMockBuilder(Translator::class) ->disableOriginalConstructor() ->getMock(); - $mockFactory->method('getTranslator') - ->willReturn($mockTranslator); + $mauticFactory->method('getTranslator') + ->willReturn($translator); - $mockRouter = $this->getMockBuilder(Router::class) + $router = $this->getMockBuilder(Router::class) ->disableOriginalConstructor() ->setMethods(['generate']) ->getMock(); - $mockRouter->method('generate') + $router->method('generate') ->willReturnArgument(0); - $mockFactory->method('getRouter') - ->willReturn($mockRouter); + $mauticFactory->method('getRouter') + ->willReturn($router); - $mockLeadModel = $this->getMockBuilder(LeadModel::class) + $leadModel = $this->getMockBuilder(LeadModel::class) ->disableOriginalConstructor() ->getMock(); - $mockLeadModel->method('getEntity') + $leadModel->method('getEntity') ->willReturn(new Lead()); - $mockCompanyModel = $this->getMockBuilder(CompanyModel::class) + $companyModel = $this->getMockBuilder(CompanyModel::class) ->disableOriginalConstructor() ->getMock(); - $mockCompanyModel->method('getEntity') + $companyModel->method('getEntity') ->willReturn(new Company()); - $mockCompanyModel->method('getEntities') + $companyModel->method('getEntities') ->willReturn([]); - $mockFieldModel = $this->getMockBuilder(FieldModel::class) + $fieldModel = $this->getMockBuilder(FieldModel::class) ->disableOriginalConstructor() ->getMock(); - $mockNotificationModel = $this->getMockBuilder(NotificationModel::class) + $notificationModel = $this->getMockBuilder(NotificationModel::class) ->disableOriginalConstructor() ->getMock(); - $mockFactory->method('getModel') + $mauticFactory->method('getModel') ->will( $this->returnValueMap( [ - ['lead', $mockLeadModel], - ['lead.company', $mockCompanyModel], - ['lead.field', $mockFieldModel], - ['core.notification', $mockNotificationModel], + ['lead', $leadModel], + ['lead.company', $companyModel], + ['lead.field', $fieldModel], + ['core.notification', $notificationModel], ] ) ); - $mockLogger = $this->getMockBuilder(Logger::class) + $logger = $this->getMockBuilder(Logger::class) ->disableOriginalConstructor() ->getMock(); - $mockFactory->method('getLogger') - ->willReturn($mockLogger); + $mauticFactory->method('getLogger') + ->willReturn($logger); - $mockDispatcher = $this->getMockBuilder(EventDispatcher::class) + $eventDispatcher = $this->getMockBuilder(EventDispatcher::class) ->disableOriginalConstructor() ->getMock(); - $mockFactory->method('getDispatcher') - ->willReturn($mockDispatcher); + $mauticFactory->method('getDispatcher') + ->willReturn($eventDispatcher); - $mockCacheHelper = $this->getMockBuilder(CacheStorageHelper::class) + $cacheHelper = $this->getMockBuilder(CacheStorageHelper::class) ->disableOriginalConstructor() ->getMock(); - $mockCacheHelper->method('getCache') - ->willReturn($mockCacheHelper); + $cacheHelper->method('getCache') + ->willReturn($cacheHelper); $leadFields = [ 'Id__Lead' => [ @@ -974,7 +977,7 @@ function () { ], ]; - $mockCacheHelper->method('get') + $cacheHelper->method('get') ->will( $this->returnValueMap( [ @@ -984,24 +987,24 @@ function () { ) ); - $mockEncryptionHelper = $this->getMockBuilder(EncryptionHelper::class) + $encryptionHelper = $this->getMockBuilder(EncryptionHelper::class) ->disableOriginalConstructor() ->getMock(); $mockPathsHelper = $this->getMockBuilder(PathsHelper::class) ->disableOriginalConstructor() ->getMock(); - $mockFactory->method('getHelper') + $mauticFactory->method('getHelper') ->will( $this->returnValueMap( [ - ['cache_storage', $mockCacheHelper], - ['encryption', $mockEncryptionHelper], + ['cache_storage', $cacheHelper], + ['encryption', $encryptionHelper], ['paths', $mockPathsHelper], ] ) ); - return $mockFactory; + return $mauticFactory; } /** From 4718870f5c0079063eb1e32a1070d4e5e7d65936 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 15 Nov 2019 13:44:30 +0100 Subject: [PATCH 11/56] Fix SalesforceIntegrationTest --- .../Integration/SalesforceIntegrationTest.php | 169 +++++------------- 1 file changed, 42 insertions(+), 127 deletions(-) diff --git a/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php b/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php index 342e951ff2b..624a5d08213 100644 --- a/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php @@ -11,19 +11,9 @@ namespace MauticPlugin\MauticCrmBundle\Tests\Integration; -use Doctrine\ORM\EntityManager; use Mautic\CoreBundle\Entity\AuditLogRepository; -use Mautic\CoreBundle\Factory\MauticFactory; -use Mautic\CoreBundle\Helper\CacheStorageHelper; -use Mautic\CoreBundle\Helper\EncryptionHelper; -use Mautic\CoreBundle\Helper\PathsHelper; -use Mautic\CoreBundle\Model\NotificationModel; -use Mautic\CoreBundle\Translation\Translator; use Mautic\LeadBundle\Entity\Company; use Mautic\LeadBundle\Entity\Lead; -use Mautic\LeadBundle\Model\CompanyModel; -use Mautic\LeadBundle\Model\FieldModel; -use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Entity\Integration; use Mautic\PluginBundle\Entity\IntegrationEntity; use Mautic\PluginBundle\Entity\IntegrationEntityRepository; @@ -32,9 +22,6 @@ use Mautic\PluginBundle\Model\IntegrationEntityModel; use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Integration\SalesforceIntegration; -use Monolog\Logger; -use Symfony\Component\EventDispatcher\EventDispatcher; -use Symfony\Component\Routing\Router; /** * Class SalesforceIntegrationTest. @@ -749,18 +736,8 @@ protected function getMaxInvocations($name) return 1; } - /** - * @return \PHPUnit_Framework_MockObject_MockObject - */ - protected function getMockFactory() + protected function setMocks() { - $mauticFactory = $this->getMockBuilder(MauticFactory::class) - ->disableOriginalConstructor() - ->getMock(); - - $entityManager = $this->getMockBuilder(EntityManager::class) - ->disableOriginalConstructor() - ->getMock(); $integrationEntityRepository = $this->getMockBuilder(IntegrationEntityRepository::class) ->disableOriginalConstructor() ->getMock(); @@ -820,17 +797,15 @@ function () use ($spy) { ] ); - $entityManager->method('getRepository') - ->will( - $this->returnValueMap( - [ - ['MauticPluginBundle:IntegrationEntity', $integrationEntityRepository], - ['MauticCoreBundle:AuditLog', $auditLogRepo], - ] - ) + $this->em->method('getRepository') + ->willReturnMap( + [ + ['MauticPluginBundle:IntegrationEntity', $integrationEntityRepository], + ['MauticCoreBundle:AuditLog', $auditLogRepo], + ] ); - $entityManager->method('getReference') + $this->em->method('getReference') ->willReturnCallback( function () { switch (func_get_arg(0)) { @@ -840,74 +815,16 @@ function () { } ); - $mauticFactory->method('getEntityManager') - ->willReturn($entityManager); - - $translator = $this->getMockBuilder(Translator::class) - ->disableOriginalConstructor() - ->getMock(); - $mauticFactory->method('getTranslator') - ->willReturn($translator); - - $router = $this->getMockBuilder(Router::class) - ->disableOriginalConstructor() - ->setMethods(['generate']) - ->getMock(); - - $router->method('generate') + $this->router->method('generate') ->willReturnArgument(0); - $mauticFactory->method('getRouter') - ->willReturn($router); - - $leadModel = $this->getMockBuilder(LeadModel::class) - ->disableOriginalConstructor() - ->getMock(); - $leadModel->method('getEntity') + $this->leadModel->method('getEntity') ->willReturn(new Lead()); - $companyModel = $this->getMockBuilder(CompanyModel::class) - ->disableOriginalConstructor() - ->getMock(); - $companyModel->method('getEntity') + + $this->companyModel->method('getEntity') ->willReturn(new Company()); - $companyModel->method('getEntities') + $this->companyModel->method('getEntities') ->willReturn([]); - $fieldModel = $this->getMockBuilder(FieldModel::class) - ->disableOriginalConstructor() - ->getMock(); - $notificationModel = $this->getMockBuilder(NotificationModel::class) - ->disableOriginalConstructor() - ->getMock(); - - $mauticFactory->method('getModel') - ->will( - $this->returnValueMap( - [ - ['lead', $leadModel], - ['lead.company', $companyModel], - ['lead.field', $fieldModel], - ['core.notification', $notificationModel], - ] - ) - ); - - $logger = $this->getMockBuilder(Logger::class) - ->disableOriginalConstructor() - ->getMock(); - $mauticFactory->method('getLogger') - ->willReturn($logger); - - $eventDispatcher = $this->getMockBuilder(EventDispatcher::class) - ->disableOriginalConstructor() - ->getMock(); - $mauticFactory->method('getDispatcher') - ->willReturn($eventDispatcher); - - $cacheHelper = $this->getMockBuilder(CacheStorageHelper::class) - ->disableOriginalConstructor() - ->getMock(); - $cacheHelper->method('getCache') - ->willReturn($cacheHelper); $leadFields = [ 'Id__Lead' => [ @@ -977,34 +894,17 @@ function () { ], ]; - $cacheHelper->method('get') - ->will( - $this->returnValueMap( - [ - ['leadFields.Lead', null, $leadFields], - ['leadFields.Contact', null, $contactFields], - ] - ) - ); - - $encryptionHelper = $this->getMockBuilder(EncryptionHelper::class) - ->disableOriginalConstructor() - ->getMock(); - $mockPathsHelper = $this->getMockBuilder(PathsHelper::class) - ->disableOriginalConstructor() - ->getMock(); - $mauticFactory->method('getHelper') - ->will( - $this->returnValueMap( - [ - ['cache_storage', $cacheHelper], - ['encryption', $encryptionHelper], - ['paths', $mockPathsHelper], - ] - ) + $this->cache + ->method('get') + ->willReturnMap( + [ + ['leadFields.Lead', null, $leadFields], + ['leadFields.Contact', null, $contactFields], + ] ); - return $mauticFactory; + $this->cache->method('getCache') + ->willReturn($this->cache); } /** @@ -1018,7 +918,7 @@ function () { */ protected function getSalesforceIntegration($maxUpdate = 100, $maxCreate = 200, $maxSfLeads = 25, $maxSfContacts = 25, $updateObject = null) { - $mockFactory = $this->getMockFactory(); + $this->setMocks(); $featureSettings = [ 'sandbox' => [ @@ -1073,7 +973,23 @@ protected function getSalesforceIntegration($maxUpdate = 100, $maxCreate = 200, ); $sf = $this->getMockBuilder(SalesforceIntegration::class) - ->setConstructorArgs([$mockFactory]) + ->setConstructorArgs([ + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $this->companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $this->integrationEntityModel, + ]) ->setMethods($this->sfMockMethods) ->getMock(); @@ -1132,9 +1048,8 @@ function () use ($maxSfContacts, $maxSfLeads, $updateObject) { ) ); - /** @var \PHPUnit_Framework_MockObject_MockObject $mockDispatcher */ - $mockDispatcher = $mockFactory->getDispatcher(); - $mockDispatcher->method('dispatch') + /* @var \PHPUnit_Framework_MockObject_MockObject $this->>dispatcher */ + $this->dispatcher->method('dispatch') ->will( $this->returnCallback( function () use ($sf, $integration) { From 89dae064bafb79ad1f5d39f59c8dc4b19493411d Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 15 Nov 2019 14:02:57 +0100 Subject: [PATCH 12/56] Replace deprecate setDefaultOptions in forms --- app/bundles/PluginBundle/Form/Type/DetailsType.php | 4 ++-- .../PluginBundle/Form/Type/IntegrationCampaignsType.php | 4 ++-- .../PluginBundle/Form/Type/IntegrationConfigType.php | 4 ++-- .../PluginBundle/Form/Type/IntegrationsListType.php | 6 +++--- app/bundles/PluginBundle/Form/Type/KeysType.php | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/bundles/PluginBundle/Form/Type/DetailsType.php b/app/bundles/PluginBundle/Form/Type/DetailsType.php index 540d3b5f3a0..e61a52f1cf6 100644 --- a/app/bundles/PluginBundle/Form/Type/DetailsType.php +++ b/app/bundles/PluginBundle/Form/Type/DetailsType.php @@ -15,7 +15,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * Class DetailsType. @@ -135,7 +135,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'data_class' => 'Mautic\PluginBundle\Entity\Integration', diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php b/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php index e5951cbc5ea..64c01f72643 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php @@ -13,7 +13,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * Class IntegrationCampaignsType. @@ -42,7 +42,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults( ['campaignContactStatus' => []]); diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php b/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php index a8e36a6d94e..8f08732e9cb 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php @@ -13,7 +13,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * Class IntegrationConfigType. @@ -48,7 +48,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setRequired(['integration']); $resolver->setDefaults([ diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php b/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php index 2f9f143501c..3d9217148a8 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php @@ -17,7 +17,7 @@ use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\NotBlank; /** @@ -154,9 +154,9 @@ function (FormEvent $event) use ($formModifier) { /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { - $resolver->setOptional(['supported_features']); + $resolver->setDefined(['supported_features']); $resolver->setDefaults( [ 'supported_features' => 'push_lead', diff --git a/app/bundles/PluginBundle/Form/Type/KeysType.php b/app/bundles/PluginBundle/Form/Type/KeysType.php index 2df37f04a10..e829be49aae 100644 --- a/app/bundles/PluginBundle/Form/Type/KeysType.php +++ b/app/bundles/PluginBundle/Form/Type/KeysType.php @@ -13,7 +13,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Context\ExecutionContextInterface; @@ -75,12 +75,12 @@ function ($validateMe, ExecutionContextInterface $context) use ($options) { } /** - * @param OptionsResolverInterface $resolver + * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setRequired(['integration_object', 'integration_keys']); - $resolver->setOptional(['secret_keys']); + $resolver->setDefined(['secret_keys']); $resolver->setDefaults(['secret_keys' => [], 'is_published' => true]); } From ea9eb36128223012c40bd90d32d672553a1716dc Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 15 Nov 2019 14:14:20 +0100 Subject: [PATCH 13/56] Use class constants in form types --- .../PluginBundle/Form/Type/DetailsType.php | 17 ++++++++++------- .../Form/Type/FeatureSettingsType.php | 5 +++-- .../Form/Type/IntegrationCampaignsType.php | 3 ++- .../Form/Type/IntegrationConfigType.php | 3 ++- .../Form/Type/IntegrationsListType.php | 7 ++++--- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/bundles/PluginBundle/Form/Type/DetailsType.php b/app/bundles/PluginBundle/Form/Type/DetailsType.php index e61a52f1cf6..bdda1d8d5f9 100644 --- a/app/bundles/PluginBundle/Form/Type/DetailsType.php +++ b/app/bundles/PluginBundle/Form/Type/DetailsType.php @@ -11,7 +11,10 @@ namespace Mautic\PluginBundle\Form\Type; +use Mautic\PluginBundle\Entity\Integration; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; @@ -39,7 +42,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } } - $builder->add('apiKeys', 'integration_keys', [ + $builder->add('apiKeys', KeysType::class, [ 'label' => false, 'integration_keys' => $keys, 'data' => $decryptedKeys, @@ -50,7 +53,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $data = $event->getData(); $form = $event->getForm(); - $form->add('apiKeys', 'integration_keys', [ + $form->add('apiKeys', KeysType::class, [ 'label' => false, 'integration_keys' => $keys, 'data' => $decryptedKeys, @@ -87,7 +90,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $choices[$f] = 'mautic.integration.form.feature.'.$f; } - $builder->add('supportedFeatures', 'choice', [ + $builder->add('supportedFeatures', ChoiceType::class, [ 'choices' => $choices, 'expanded' => true, 'label_attr' => ['class' => 'control-label'], @@ -108,7 +111,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]); } - $builder->add('featureSettings', 'integration_featuresettings', [ + $builder->add('featureSettings', FeatureSettingsType::class, [ 'label' => 'mautic.integration.form.feature.settings', 'required' => true, 'data' => $options['data']->getFeatureSettings(), @@ -119,9 +122,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'company_fields' => $options['company_fields'], ]); - $builder->add('name', 'hidden', ['data' => $options['integration']]); + $builder->add('name', HiddenType::class, ['data' => $options['integration']]); - $builder->add('in_auth', 'hidden', ['mapped' => false]); + $builder->add('in_auth', HiddenType::class, ['mapped' => false]); $builder->add('buttons', 'form_buttons'); @@ -138,7 +141,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ - 'data_class' => 'Mautic\PluginBundle\Entity\Integration', + 'data_class' => Integration::class, ]); $resolver->setRequired(['integration', 'integration_object', 'lead_fields', 'company_fields']); diff --git a/app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php b/app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php index 8211afb0321..799a3d42be2 100644 --- a/app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php +++ b/app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php @@ -47,6 +47,7 @@ class FeatureSettingsType extends AbstractType * * @param Session $session * @param CoreParametersHelper $coreParametersHelper + * @param LoggerInterface $logger */ public function __construct( Session $session, @@ -120,7 +121,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $form->add( 'leadFields', - 'integration_fields', + FieldsType::class, [ 'label' => 'mautic.integration.leadfield_matches', 'required' => true, @@ -140,7 +141,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) if (!empty($integrationCompanyFields)) { $form->add( 'companyFields', - 'integration_company_fields', + CompanyFieldsType::class, [ 'label' => 'mautic.integration.companyfield_matches', 'required' => true, diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php b/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php index 64c01f72643..ba4d1710edd 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php @@ -12,6 +12,7 @@ namespace Mautic\PluginBundle\Form\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -28,7 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add( 'campaign_member_status', - 'choice', + ChoiceType::class, [ 'choices' => $options['campaignContactStatus'], 'attr' => [ diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php b/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php index 8f08732e9cb..1015705bf33 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php @@ -12,6 +12,7 @@ namespace Mautic\PluginBundle\Form\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -32,7 +33,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) if (!empty($options['campaigns'])) { $builder->add( 'campaigns', - 'choice', + ChoiceType::class, [ 'choices' => $options['campaigns'], 'attr' => [ diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php b/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php index 3d9217148a8..b34367d1e9d 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php @@ -13,6 +13,7 @@ use Mautic\CoreBundle\Factory\MauticFactory; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; @@ -58,7 +59,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'integration', - 'choice', + ChoiceType::class, [ 'choices' => $integrations, 'expanded' => false, @@ -107,7 +108,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } $form->add( 'config', - 'integration_config', + IntegrationConfigType::class, [ 'label' => false, 'attr' => [ @@ -122,7 +123,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $hideClass = (isset($data['campaign_member_status']) && !empty($data['campaign_member_status']['campaign_member_status'])) ? '' : ' hide'; $form->add( 'campaign_member_status', - 'integration_campaign_status', + IntegrationCampaignsType::class, [ 'label' => false, 'attr' => [ From ff4e4465966c7eb8063ee440f5a5ea87e5ff901c Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 15 Nov 2019 15:04:12 +0100 Subject: [PATCH 14/56] Rename deprecated getName method in forms --- app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php | 2 +- app/bundles/PluginBundle/Form/Type/DetailsType.php | 2 +- app/bundles/PluginBundle/Form/Type/FieldsType.php | 2 +- app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php | 2 +- app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php | 2 +- app/bundles/PluginBundle/Form/Type/IntegrationsListType.php | 2 +- app/bundles/PluginBundle/Form/Type/KeysType.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php b/app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php index 876c7d75171..2ef671f30ed 100644 --- a/app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php +++ b/app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php @@ -55,7 +55,7 @@ public function configureOptions(OptionsResolver $resolver) /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'integration_company_fields'; } diff --git a/app/bundles/PluginBundle/Form/Type/DetailsType.php b/app/bundles/PluginBundle/Form/Type/DetailsType.php index bdda1d8d5f9..c1adacd506e 100644 --- a/app/bundles/PluginBundle/Form/Type/DetailsType.php +++ b/app/bundles/PluginBundle/Form/Type/DetailsType.php @@ -150,7 +150,7 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'integration_details'; } diff --git a/app/bundles/PluginBundle/Form/Type/FieldsType.php b/app/bundles/PluginBundle/Form/Type/FieldsType.php index db0e2bbcd53..90b871bb3fa 100644 --- a/app/bundles/PluginBundle/Form/Type/FieldsType.php +++ b/app/bundles/PluginBundle/Form/Type/FieldsType.php @@ -55,7 +55,7 @@ public function configureOptions(OptionsResolver $resolver) /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'integration_fields'; } diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php b/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php index ba4d1710edd..18ee8cc055b 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php @@ -52,7 +52,7 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'integration_campaign_status'; } diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php b/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php index 1015705bf33..50656cb5f11 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php @@ -61,7 +61,7 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'integration_config'; } diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php b/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php index b34367d1e9d..34eadcf1d9e 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php @@ -168,7 +168,7 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'integration_list'; } diff --git a/app/bundles/PluginBundle/Form/Type/KeysType.php b/app/bundles/PluginBundle/Form/Type/KeysType.php index e829be49aae..d373ccd3cc2 100644 --- a/app/bundles/PluginBundle/Form/Type/KeysType.php +++ b/app/bundles/PluginBundle/Form/Type/KeysType.php @@ -87,7 +87,7 @@ public function configureOptions(OptionsResolver $resolver) /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'integration_keys'; } From 443c2870f0c79ea4c0b7fc61ef3e8d5db9f2d1dd Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 26 Nov 2019 12:07:46 +0100 Subject: [PATCH 15/56] Fix DNC remove test Test is failing on staging and master too for me. When DNC is removed, the record in lead_donotcontact is removed too. --- .../Tests/Controller/Api/LeadApiControllerFunctionalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/bundles/LeadBundle/Tests/Controller/Api/LeadApiControllerFunctionalTest.php b/app/bundles/LeadBundle/Tests/Controller/Api/LeadApiControllerFunctionalTest.php index 18b30a21c7f..525e97edc69 100644 --- a/app/bundles/LeadBundle/Tests/Controller/Api/LeadApiControllerFunctionalTest.php +++ b/app/bundles/LeadBundle/Tests/Controller/Api/LeadApiControllerFunctionalTest.php @@ -198,7 +198,7 @@ public function testBachdDncAddAndRemove() $clientResponse = $this->client->getResponse(); $response = json_decode($clientResponse->getContent(), true); - $this->assertSame(null, $response['contacts'][0]['doNotContact'][0]['reason']); + $this->assertSame(false, isset($response['contacts'][0]['doNotContact'][0])); // Remove contact $this->client->request('DELETE', "/api/contacts/$contactId/delete"); From bf18e515184abb67fee2a7fd9264fbeaa74e12e3 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 26 Nov 2019 16:18:24 +0100 Subject: [PATCH 16/56] Fix method visibility --- .../Tests/Integration/AbstractIntegrationTestCase.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php index 5c00905823c..afce0622f7e 100644 --- a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php +++ b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php @@ -15,6 +15,7 @@ use Mautic\CoreBundle\Helper\EncryptionHelper; use Mautic\CoreBundle\Helper\PathsHelper; use Mautic\CoreBundle\Model\NotificationModel; +use Mautic\CoreBundle\Test\MauticMysqlTestCase; use Mautic\LeadBundle\Model\CompanyModel; use Mautic\LeadBundle\Model\FieldModel; use Mautic\LeadBundle\Model\LeadModel; @@ -26,7 +27,7 @@ use Symfony\Component\Routing\Router; use Symfony\Component\Translation\DataCollectorTranslator; -class AbstractIntegrationTestCase extends \PHPUnit_Framework_TestCase +class AbstractIntegrationTestCase extends MauticMysqlTestCase { /** * @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject @@ -103,7 +104,7 @@ class AbstractIntegrationTestCase extends \PHPUnit_Framework_TestCase */ protected $integrationEntityModel; - protected function setUp() + public function setUp() { parent::setUp(); From 25ae50959851699abcb7236551ea6797c0b84c92 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 29 Nov 2019 14:52:07 +0100 Subject: [PATCH 17/56] Fix \MauticCrmBundle\Api\DynamicsApiTest::setUp() method visibility --- plugins/MauticCrmBundle/Tests/DynamicsApiTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php b/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php index 68382bca6e0..7036a624f65 100644 --- a/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php +++ b/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php @@ -20,7 +20,7 @@ class DynamicsApiTest extends AbstractIntegrationTestCase /** @var DynamicsIntegration */ private $integration; - protected function setUp() + public function setUp() { parent::setUp(); From e06726773eabbf0cc03a3af16fbab38f45f73b30 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 29 Nov 2019 14:53:17 +0100 Subject: [PATCH 18/56] Fix DynamicsIntegrationTest::setUp() method visibility --- plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php b/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php index 6afc41cf4da..45cb735d4df 100644 --- a/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php @@ -16,7 +16,7 @@ class DynamicsIntegrationTest extends AbstractIntegrationTestCase /** @var DynamicsIntegration */ private $integration; - protected function setUp() + public function setUp() { parent::setUp(); From 2d6d8a812cbd9802fa91f97b3acfd7560ed5027c Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 29 Nov 2019 15:01:16 +0100 Subject: [PATCH 19/56] Fix PHPUnit setUp() method visibility in project --- .../CampaignBundle/Tests/Command/AbstractCampaignCommand.php | 2 +- .../Tests/Command/TriggerCampaignCommandTest.php | 2 +- .../CampaignBundle/Tests/Membership/Action/AdderTest.php | 2 +- app/bundles/CoreBundle/Test/AbstractMauticTestCase.php | 2 +- .../Test/EventListener/MaintenanceSubscriberTest.php | 2 +- app/bundles/CoreBundle/Test/MauticMysqlTestCase.php | 2 +- app/bundles/CoreBundle/Test/MauticSqliteTestCase.php | 2 +- app/bundles/CoreBundle/Test/MauticWebTestCase.php | 3 +-- .../CoreBundle/Tests/Unit/Helper/IpLookupHelperTest.php | 2 +- .../CoreBundle/Tests/Unit/IpLookup/MaxmindLookupTest.php | 2 +- app/bundles/EmailBundle/Tests/Helper/MailHelperTest.php | 2 +- .../EmailBundle/Tests/Transport/AmazonTransportTest.php | 2 +- .../EmailBundle/Tests/Transport/ElasticemailTransportTest.php | 2 +- .../FormBundle/Tests/EventListener/ReportSubscriberTest.php | 2 +- app/bundles/FormBundle/Tests/Helper/FormFieldHelperTest.php | 2 +- app/bundles/LeadBundle/Tests/Helper/TokenHelperTest.php | 2 +- app/bundles/LeadBundle/Tests/Model/CompanyReportDataTest.php | 2 +- app/bundles/LeadBundle/Tests/Model/LeadListModelTest.php | 2 +- .../LeadBundle/Tests/Segment/Decorator/BaseDecoratorTest.php | 2 +- .../Tests/Segment/Decorator/CustomMappedDecoratorTest.php | 2 +- .../Tests/Segment/Decorator/DecoratorFactoryTest.php | 2 +- app/bundles/LeadBundle/Tests/Tracker/ContactTrackerTest.php | 2 +- app/bundles/LeadBundle/Tests/Tracker/DeviceTrackerTest.php | 2 +- app/bundles/PageBundle/Tests/Controller/PageControllerTest.php | 2 +- .../PageBundle/Tests/EventListener/ReportSubscriberTest.php | 2 +- .../Tests/Integration/AbstractIntegrationTestCase.php | 2 +- app/bundles/SmsBundle/Tests/Sms/TransportChainTest.php | 2 +- plugins/MauticCrmBundle/Tests/DynamicsApiTest.php | 2 +- plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php | 2 +- .../Tests/Integration/SalesforceIntegrationTest.php | 2 +- plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php | 2 +- 31 files changed, 31 insertions(+), 32 deletions(-) diff --git a/app/bundles/CampaignBundle/Tests/Command/AbstractCampaignCommand.php b/app/bundles/CampaignBundle/Tests/Command/AbstractCampaignCommand.php index c712bda75bf..bf80e0082a5 100644 --- a/app/bundles/CampaignBundle/Tests/Command/AbstractCampaignCommand.php +++ b/app/bundles/CampaignBundle/Tests/Command/AbstractCampaignCommand.php @@ -39,7 +39,7 @@ class AbstractCampaignCommand extends MauticMysqlTestCase /** * @throws \Exception */ - public function setUp() + protected function setUp() { // Everything needs to happen anonymously $this->defaultClientServer = $this->clientServer; diff --git a/app/bundles/CampaignBundle/Tests/Command/TriggerCampaignCommandTest.php b/app/bundles/CampaignBundle/Tests/Command/TriggerCampaignCommandTest.php index 5fddb2c61e8..d4bcdd2ec4e 100644 --- a/app/bundles/CampaignBundle/Tests/Command/TriggerCampaignCommandTest.php +++ b/app/bundles/CampaignBundle/Tests/Command/TriggerCampaignCommandTest.php @@ -13,7 +13,7 @@ class TriggerCampaignCommandTest extends AbstractCampaignCommand { - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/app/bundles/CampaignBundle/Tests/Membership/Action/AdderTest.php b/app/bundles/CampaignBundle/Tests/Membership/Action/AdderTest.php index 3cea7953849..a007b4840f8 100644 --- a/app/bundles/CampaignBundle/Tests/Membership/Action/AdderTest.php +++ b/app/bundles/CampaignBundle/Tests/Membership/Action/AdderTest.php @@ -31,7 +31,7 @@ class AdderTest extends \PHPUnit_Framework_TestCase */ private $leadEventLogRepository; - public function setUp() + protected function setUp() { $this->leadRepository = $this->createMock(LeadRepository::class); $this->leadEventLogRepository = $this->createMock(LeadEventLogRepository::class); diff --git a/app/bundles/CoreBundle/Test/AbstractMauticTestCase.php b/app/bundles/CoreBundle/Test/AbstractMauticTestCase.php index c0682845c77..e9599413419 100644 --- a/app/bundles/CoreBundle/Test/AbstractMauticTestCase.php +++ b/app/bundles/CoreBundle/Test/AbstractMauticTestCase.php @@ -45,7 +45,7 @@ abstract class AbstractMauticTestCase extends WebTestCase 'PHP_AUTH_PW' => 'mautic', ]; - public function setUp() + protected function setUp() { \Mautic\CoreBundle\ErrorHandler\ErrorHandler::register('prod'); diff --git a/app/bundles/CoreBundle/Test/EventListener/MaintenanceSubscriberTest.php b/app/bundles/CoreBundle/Test/EventListener/MaintenanceSubscriberTest.php index 9d4c218f9b9..51650797057 100644 --- a/app/bundles/CoreBundle/Test/EventListener/MaintenanceSubscriberTest.php +++ b/app/bundles/CoreBundle/Test/EventListener/MaintenanceSubscriberTest.php @@ -27,7 +27,7 @@ class MaintenanceSubscriberTest extends \PHPUnit_Framework_TestCase */ private $subscriber; - public function setUp() + protected function setUp() { $connection = $this->createMock(Connection::class); $userTokenRepository = $this->createMock(UserTokenRepositoryInterface::class); diff --git a/app/bundles/CoreBundle/Test/MauticMysqlTestCase.php b/app/bundles/CoreBundle/Test/MauticMysqlTestCase.php index 22ad7fd8748..5341e72c7b2 100644 --- a/app/bundles/CoreBundle/Test/MauticMysqlTestCase.php +++ b/app/bundles/CoreBundle/Test/MauticMysqlTestCase.php @@ -12,7 +12,7 @@ abstract class MauticMysqlTestCase extends AbstractMauticTestCase /** * @throws \Exception */ - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/app/bundles/CoreBundle/Test/MauticSqliteTestCase.php b/app/bundles/CoreBundle/Test/MauticSqliteTestCase.php index 9c8b0a4c251..bd41147c735 100644 --- a/app/bundles/CoreBundle/Test/MauticSqliteTestCase.php +++ b/app/bundles/CoreBundle/Test/MauticSqliteTestCase.php @@ -8,7 +8,7 @@ abstract class MauticSqliteTestCase extends AbstractMauticTestCase { - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/app/bundles/CoreBundle/Test/MauticWebTestCase.php b/app/bundles/CoreBundle/Test/MauticWebTestCase.php index 014ec234329..e06e5fa5906 100644 --- a/app/bundles/CoreBundle/Test/MauticWebTestCase.php +++ b/app/bundles/CoreBundle/Test/MauticWebTestCase.php @@ -15,7 +15,6 @@ use Doctrine\Common\DataFixtures\ReferenceRepository; use Liip\FunctionalTestBundle\Test\WebTestCase; -use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Finder\Finder; use Symfony\Component\HttpFoundation\Request; @@ -202,7 +201,7 @@ protected function assertNoError($response, $crawler, $fullOutput = false) /** * {@inheritdoc} */ - public function setUp() + protected function setUp() { static::$kernel = static::createKernel(); static::$kernel->boot(); diff --git a/app/bundles/CoreBundle/Tests/Unit/Helper/IpLookupHelperTest.php b/app/bundles/CoreBundle/Tests/Unit/Helper/IpLookupHelperTest.php index 87803b6429c..aef0d5aef39 100644 --- a/app/bundles/CoreBundle/Tests/Unit/Helper/IpLookupHelperTest.php +++ b/app/bundles/CoreBundle/Tests/Unit/Helper/IpLookupHelperTest.php @@ -28,7 +28,7 @@ public function __construct($name = null, array $data = [], $dataName = '') parent::__construct($name, $data, $dataName); } - public function setUp() + protected function setUp() { defined('MAUTIC_ENV') or define('MAUTIC_ENV', 'test'); } diff --git a/app/bundles/CoreBundle/Tests/Unit/IpLookup/MaxmindLookupTest.php b/app/bundles/CoreBundle/Tests/Unit/IpLookup/MaxmindLookupTest.php index f0fa3db471f..5e334d05614 100644 --- a/app/bundles/CoreBundle/Tests/Unit/IpLookup/MaxmindLookupTest.php +++ b/app/bundles/CoreBundle/Tests/Unit/IpLookup/MaxmindLookupTest.php @@ -25,7 +25,7 @@ class MaxmindLookupTest extends \PHPUnit_Framework_TestCase { protected $mockHttp; - public function setUp() + protected function setUp() { // Mock http connector $this->mockHttp = $this->getMockBuilder('Joomla\Http\Http') diff --git a/app/bundles/EmailBundle/Tests/Helper/MailHelperTest.php b/app/bundles/EmailBundle/Tests/Helper/MailHelperTest.php index 80c24c9d9e9..9f06c79048a 100644 --- a/app/bundles/EmailBundle/Tests/Helper/MailHelperTest.php +++ b/app/bundles/EmailBundle/Tests/Helper/MailHelperTest.php @@ -56,7 +56,7 @@ class MailHelperTest extends \PHPUnit_Framework_TestCase ], ]; - public function setUp() + protected function setUp() { defined('MAUTIC_ENV') or define('MAUTIC_ENV', 'test'); } diff --git a/app/bundles/EmailBundle/Tests/Transport/AmazonTransportTest.php b/app/bundles/EmailBundle/Tests/Transport/AmazonTransportTest.php index ecebc22df15..231acec158f 100644 --- a/app/bundles/EmailBundle/Tests/Transport/AmazonTransportTest.php +++ b/app/bundles/EmailBundle/Tests/Transport/AmazonTransportTest.php @@ -32,7 +32,7 @@ class AmazonTransportTest extends \PHPUnit_Framework_TestCase */ private $translator; - public function setUp() + protected function setUp() { $this->logger = $this->getMockBuilder(Logger::class) ->disableOriginalConstructor() diff --git a/app/bundles/EmailBundle/Tests/Transport/ElasticemailTransportTest.php b/app/bundles/EmailBundle/Tests/Transport/ElasticemailTransportTest.php index dfcc1eef9be..12e3204b09f 100644 --- a/app/bundles/EmailBundle/Tests/Transport/ElasticemailTransportTest.php +++ b/app/bundles/EmailBundle/Tests/Transport/ElasticemailTransportTest.php @@ -24,7 +24,7 @@ class ElasticemailTransportTest extends \PHPUnit_Framework_TestCase private $transportCallback; private $logger; - public function setUp() + protected function setUp() { $this->translator = $this->getMockBuilder(Translator::class) ->disableOriginalConstructor() diff --git a/app/bundles/FormBundle/Tests/EventListener/ReportSubscriberTest.php b/app/bundles/FormBundle/Tests/EventListener/ReportSubscriberTest.php index 8e358df5774..a288a64c9da 100644 --- a/app/bundles/FormBundle/Tests/EventListener/ReportSubscriberTest.php +++ b/app/bundles/FormBundle/Tests/EventListener/ReportSubscriberTest.php @@ -25,7 +25,7 @@ class ReportSubscriberTest extends WebTestCase { - public function setUp() + protected function setUp() { parent::setUp(); defined('MAUTIC_TABLE_PREFIX') or define('MAUTIC_TABLE_PREFIX', ''); diff --git a/app/bundles/FormBundle/Tests/Helper/FormFieldHelperTest.php b/app/bundles/FormBundle/Tests/Helper/FormFieldHelperTest.php index 9990b5bb073..9051db946ef 100644 --- a/app/bundles/FormBundle/Tests/Helper/FormFieldHelperTest.php +++ b/app/bundles/FormBundle/Tests/Helper/FormFieldHelperTest.php @@ -14,7 +14,7 @@ class FormFieldHelperTest extends \PHPUnit_Framework_TestCase */ protected $fixture; - public function setUp() + protected function setUp() { $translatorMock = $this->getMockBuilder(TranslatorInterface::class) ->disableOriginalConstructor() diff --git a/app/bundles/LeadBundle/Tests/Helper/TokenHelperTest.php b/app/bundles/LeadBundle/Tests/Helper/TokenHelperTest.php index 11aa3fec134..5a927e355ac 100644 --- a/app/bundles/LeadBundle/Tests/Helper/TokenHelperTest.php +++ b/app/bundles/LeadBundle/Tests/Helper/TokenHelperTest.php @@ -28,7 +28,7 @@ class TokenHelperTest extends \PHPUnit_Framework_TestCase ], ]; - public function setUp() + protected function setUp() { $reflectionProperty = new ReflectionProperty(TokenHelper::class, 'parameters'); $reflectionProperty->setAccessible(true); diff --git a/app/bundles/LeadBundle/Tests/Model/CompanyReportDataTest.php b/app/bundles/LeadBundle/Tests/Model/CompanyReportDataTest.php index 116631295b2..7ab51d7c957 100644 --- a/app/bundles/LeadBundle/Tests/Model/CompanyReportDataTest.php +++ b/app/bundles/LeadBundle/Tests/Model/CompanyReportDataTest.php @@ -25,7 +25,7 @@ class CompanyReportDataTest extends \PHPUnit_Framework_TestCase */ private $translator; - public function setUp() + protected function setUp() { $this->translator = $this->getMockBuilder(Translator::class) ->disableOriginalConstructor() diff --git a/app/bundles/LeadBundle/Tests/Model/LeadListModelTest.php b/app/bundles/LeadBundle/Tests/Model/LeadListModelTest.php index d2fc0e582e4..8324de104de 100644 --- a/app/bundles/LeadBundle/Tests/Model/LeadListModelTest.php +++ b/app/bundles/LeadBundle/Tests/Model/LeadListModelTest.php @@ -10,7 +10,7 @@ class LeadListModelTest extends \PHPUnit_Framework_TestCase { protected $fixture; - public function setUp() + protected function setUp() { $mockListModel = $this->getMockBuilder(ListModel::class) ->disableOriginalConstructor() diff --git a/app/bundles/LeadBundle/Tests/Segment/Decorator/BaseDecoratorTest.php b/app/bundles/LeadBundle/Tests/Segment/Decorator/BaseDecoratorTest.php index ae5da5ddd10..89df6957068 100644 --- a/app/bundles/LeadBundle/Tests/Segment/Decorator/BaseDecoratorTest.php +++ b/app/bundles/LeadBundle/Tests/Segment/Decorator/BaseDecoratorTest.php @@ -17,7 +17,7 @@ class BaseDecoratorTest extends \PHPUnit_Framework_TestCase { - public function setUp() + protected function setUp() { parent::setUp(); defined('MAUTIC_TABLE_PREFIX') or define('MAUTIC_TABLE_PREFIX', ''); diff --git a/app/bundles/LeadBundle/Tests/Segment/Decorator/CustomMappedDecoratorTest.php b/app/bundles/LeadBundle/Tests/Segment/Decorator/CustomMappedDecoratorTest.php index e8d700bf206..c7b24a9a562 100644 --- a/app/bundles/LeadBundle/Tests/Segment/Decorator/CustomMappedDecoratorTest.php +++ b/app/bundles/LeadBundle/Tests/Segment/Decorator/CustomMappedDecoratorTest.php @@ -18,7 +18,7 @@ class CustomMappedDecoratorTest extends \PHPUnit_Framework_TestCase { - public function setUp() + protected function setUp() { parent::setUp(); defined('MAUTIC_TABLE_PREFIX') or define('MAUTIC_TABLE_PREFIX', ''); diff --git a/app/bundles/LeadBundle/Tests/Segment/Decorator/DecoratorFactoryTest.php b/app/bundles/LeadBundle/Tests/Segment/Decorator/DecoratorFactoryTest.php index a1a1ab28dee..a9306bae517 100644 --- a/app/bundles/LeadBundle/Tests/Segment/Decorator/DecoratorFactoryTest.php +++ b/app/bundles/LeadBundle/Tests/Segment/Decorator/DecoratorFactoryTest.php @@ -22,7 +22,7 @@ class DecoratorFactoryTest extends \PHPUnit_Framework_TestCase { - public function setUp() + protected function setUp() { parent::setUp(); defined('MAUTIC_TABLE_PREFIX') or define('MAUTIC_TABLE_PREFIX', ''); diff --git a/app/bundles/LeadBundle/Tests/Tracker/ContactTrackerTest.php b/app/bundles/LeadBundle/Tests/Tracker/ContactTrackerTest.php index 5bdc4e0c9ac..648836c8c02 100644 --- a/app/bundles/LeadBundle/Tests/Tracker/ContactTrackerTest.php +++ b/app/bundles/LeadBundle/Tests/Tracker/ContactTrackerTest.php @@ -80,7 +80,7 @@ class ContactTrackerTest extends \PHPUnit_Framework_TestCase */ private $leadFieldModelMock; - public function setUp() + protected function setUp() { $this->leadRepositoryMock = $this->getMockBuilder(LeadRepository::class) ->disableOriginalConstructor() diff --git a/app/bundles/LeadBundle/Tests/Tracker/DeviceTrackerTest.php b/app/bundles/LeadBundle/Tests/Tracker/DeviceTrackerTest.php index 76fd3aeda75..32169375c71 100644 --- a/app/bundles/LeadBundle/Tests/Tracker/DeviceTrackerTest.php +++ b/app/bundles/LeadBundle/Tests/Tracker/DeviceTrackerTest.php @@ -46,7 +46,7 @@ class DeviceTrackerTest extends \PHPUnit_Framework_TestCase */ private $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'; - public function setUp() + protected function setUp() { $this->deviceCreatorService = new DeviceCreatorService(); diff --git a/app/bundles/PageBundle/Tests/Controller/PageControllerTest.php b/app/bundles/PageBundle/Tests/Controller/PageControllerTest.php index 7fc528cba03..d0bfa930780 100644 --- a/app/bundles/PageBundle/Tests/Controller/PageControllerTest.php +++ b/app/bundles/PageBundle/Tests/Controller/PageControllerTest.php @@ -22,7 +22,7 @@ class PageControllerTest extends MauticMysqlTestCase /** * @throws \Exception */ - public function setUp() + protected function setUp() { parent::setUp(); $this->db = $this->container->get('doctrine.dbal.default_connection'); diff --git a/app/bundles/PageBundle/Tests/EventListener/ReportSubscriberTest.php b/app/bundles/PageBundle/Tests/EventListener/ReportSubscriberTest.php index 1e58f88af7a..af49ae42cf6 100644 --- a/app/bundles/PageBundle/Tests/EventListener/ReportSubscriberTest.php +++ b/app/bundles/PageBundle/Tests/EventListener/ReportSubscriberTest.php @@ -28,7 +28,7 @@ class ReportSubscriberTest extends WebTestCase { - public function setUp() + protected function setUp() { parent::setUp(); defined('MAUTIC_TABLE_PREFIX') or define('MAUTIC_TABLE_PREFIX', ''); diff --git a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php index afce0622f7e..6e35c829216 100644 --- a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php +++ b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php @@ -104,7 +104,7 @@ class AbstractIntegrationTestCase extends MauticMysqlTestCase */ protected $integrationEntityModel; - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/app/bundles/SmsBundle/Tests/Sms/TransportChainTest.php b/app/bundles/SmsBundle/Tests/Sms/TransportChainTest.php index 76ed0ea67e4..92f82d8768d 100644 --- a/app/bundles/SmsBundle/Tests/Sms/TransportChainTest.php +++ b/app/bundles/SmsBundle/Tests/Sms/TransportChainTest.php @@ -44,7 +44,7 @@ public function invokeMethod(&$object, $methodName, array $parameters = []) return $method->invokeArgs($object, $parameters); } - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php b/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php index 7036a624f65..68382bca6e0 100644 --- a/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php +++ b/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php @@ -20,7 +20,7 @@ class DynamicsApiTest extends AbstractIntegrationTestCase /** @var DynamicsIntegration */ private $integration; - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php b/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php index 45cb735d4df..6afc41cf4da 100644 --- a/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php @@ -16,7 +16,7 @@ class DynamicsIntegrationTest extends AbstractIntegrationTestCase /** @var DynamicsIntegration */ private $integration; - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php b/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php index 624a5d08213..03383998b38 100644 --- a/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php @@ -112,7 +112,7 @@ class SalesforceIntegrationTest extends AbstractIntegrationTestCase */ protected $leadsCreatedCounter = 0; - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php b/plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php index 9f58304fe11..fa59e5c999f 100644 --- a/plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php +++ b/plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php @@ -19,7 +19,7 @@ abstract class PipedriveTest extends MauticMysqlTestCase const WEBHOOK_USER = 'user'; const WEBHOOK_PASSWORD = 'pa$$word'; - public function setUp() + protected function setUp() { parent::setUp(); From 9923890db0437c4211aaf733956328ac1b5e32cb Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 29 Nov 2019 15:10:44 +0100 Subject: [PATCH 20/56] Fix DNC test again --- .../Tests/Controller/Api/LeadApiControllerFunctionalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/bundles/LeadBundle/Tests/Controller/Api/LeadApiControllerFunctionalTest.php b/app/bundles/LeadBundle/Tests/Controller/Api/LeadApiControllerFunctionalTest.php index 08ffc4c8578..a39f58df111 100644 --- a/app/bundles/LeadBundle/Tests/Controller/Api/LeadApiControllerFunctionalTest.php +++ b/app/bundles/LeadBundle/Tests/Controller/Api/LeadApiControllerFunctionalTest.php @@ -198,7 +198,7 @@ public function testBachdDncAddAndRemove() $clientResponse = $this->client->getResponse(); $response = json_decode($clientResponse->getContent(), true); - $this->assertEmpty($response['contacts'][0]['doNotContact'][0]['reason']); + $this->assertEmpty($response['contacts'][0]['doNotContact']); // Remove contact $this->client->request('DELETE', "/api/contacts/$contactId/delete"); From 32974d222fbc143504f654e97e125de8304e4955 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 29 Nov 2019 16:09:17 +0100 Subject: [PATCH 21/56] Replace form types --- .../PluginBundle/Form/Type/DetailsType.php | 47 +++++++++++-------- .../Form/Type/FieldsTypeTrait.php | 9 ++-- .../Form/Type/IntegrationCampaignsType.php | 5 +- .../Form/Type/IntegrationConfigType.php | 9 ++-- .../Form/Type/IntegrationsListType.php | 4 +- .../PluginBundle/Form/Type/KeysType.php | 4 +- 6 files changed, 46 insertions(+), 32 deletions(-) diff --git a/app/bundles/PluginBundle/Form/Type/DetailsType.php b/app/bundles/PluginBundle/Form/Type/DetailsType.php index 540d3b5f3a0..47147867e43 100644 --- a/app/bundles/PluginBundle/Form/Type/DetailsType.php +++ b/app/bundles/PluginBundle/Form/Type/DetailsType.php @@ -11,7 +11,13 @@ namespace Mautic\PluginBundle\Form\Type; +use Mautic\CoreBundle\Form\Type\FormButtonsType; +use Mautic\CoreBundle\Form\Type\StandAloneButtonType; +use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType; +use Mautic\PluginBundle\Entity\Integration; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; @@ -27,7 +33,7 @@ class DetailsType extends AbstractType */ public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('isPublished', 'yesno_button_group'); + $builder->add('isPublished', YesNoButtonGroupType::class); $keys = $options['integration_object']->getRequiredKeyFields(); $decryptedKeys = $options['integration_object']->decryptApiKeys($options['data']->getApiKeys()); @@ -39,7 +45,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } } - $builder->add('apiKeys', 'integration_keys', [ + $builder->add('apiKeys', KeysType::class, [ 'label' => false, 'integration_keys' => $keys, 'data' => $decryptedKeys, @@ -50,7 +56,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $data = $event->getData(); $form = $event->getForm(); - $form->add('apiKeys', 'integration_keys', [ + $form->add('apiKeys', KeysType::class, [ 'label' => false, 'integration_keys' => $keys, 'data' => $decryptedKeys, @@ -63,7 +69,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $disabled = false; $label = ($options['integration_object']->isAuthorized()) ? 'reauthorize' : 'authorize'; - $builder->add('authButton', 'standalone_button', [ + $builder->add('authButton', StandAloneButtonType::class, [ 'attr' => [ 'class' => 'btn btn-success btn-lg', 'onclick' => 'Mautic.initiateIntegrationAuthorization()', @@ -84,18 +90,19 @@ public function buildForm(FormBuilderInterface $builder, array $options) $choices = []; foreach ($features as $f) { - $choices[$f] = 'mautic.integration.form.feature.'.$f; + $choices['mautic.integration.form.feature.'.$f] = $f; } - $builder->add('supportedFeatures', 'choice', [ - 'choices' => $choices, - 'expanded' => true, - 'label_attr' => ['class' => 'control-label'], - 'multiple' => true, - 'label' => 'mautic.integration.form.features', - 'required' => false, - 'data' => $data, - 'choice_attr' => function ($val, $key, $index) use ($tooltips) { + $builder->add('supportedFeatures', ChoiceType::class, [ + 'choices' => $choices, + 'expanded' => true, + 'label_attr' => ['class' => 'control-label'], + 'multiple' => true, + 'label' => 'mautic.integration.form.features', + 'required' => false, + 'data' => $data, + 'choices_as_values' => true, + 'choice_attr' => function ($val, $key, $index) use ($tooltips) { if (array_key_exists($val, $tooltips)) { return [ 'data-toggle' => 'tooltip', @@ -108,7 +115,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]); } - $builder->add('featureSettings', 'integration_featuresettings', [ + $builder->add('featureSettings', FeatureSettingsType::class, [ 'label' => 'mautic.integration.form.feature.settings', 'required' => true, 'data' => $options['data']->getFeatureSettings(), @@ -119,11 +126,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'company_fields' => $options['company_fields'], ]); - $builder->add('name', 'hidden', ['data' => $options['integration']]); + $builder->add('name', HiddenType::class, ['data' => $options['integration']]); - $builder->add('in_auth', 'hidden', ['mapped' => false]); + $builder->add('in_auth', HiddenType::class, ['mapped' => false]); - $builder->add('buttons', 'form_buttons'); + $builder->add('buttons', FormButtonsType::class); if (!empty($options['action'])) { $builder->setAction($options['action']); @@ -138,7 +145,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults([ - 'data_class' => 'Mautic\PluginBundle\Entity\Integration', + 'data_class' => Integration::class, ]); $resolver->setRequired(['integration', 'integration_object', 'lead_fields', 'company_fields']); @@ -147,7 +154,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'integration_details'; } diff --git a/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php b/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php index aa44181cd3e..1d31b38720d 100644 --- a/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php +++ b/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php @@ -12,7 +12,9 @@ namespace Mautic\PluginBundle\Form\Type; use Mautic\CoreBundle\Form\Type\ButtonGroupType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; @@ -132,7 +134,7 @@ function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $f ++$index; $form->add( 'label_'.$index, - 'text', + TextType::class, [ 'label' => false, 'data' => $choices[$field], @@ -194,9 +196,9 @@ function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $f $form->add( 'm_'.$index, - 'choice', + ChoiceType::class, [ - 'choices' => $mauticFields, + 'choices' => array_flip($mauticFields), 'label' => false, 'data' => $matched && isset($fieldData[$fieldsName][$field]) ? $fieldData[$fieldsName][$field] : '', 'label_attr' => ['class' => 'control-label'], @@ -207,6 +209,7 @@ function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $f 'data-value' => $matched && isset($fieldData[$fieldsName][$field]) ? $fieldData[$fieldsName][$field] : '', 'data-choices' => $mauticFields, ], + 'choices_as_values' => true, ] ); $form->add( diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php b/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php index 18ee8cc055b..3fec573599a 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php @@ -31,8 +31,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'campaign_member_status', ChoiceType::class, [ - 'choices' => $options['campaignContactStatus'], - 'attr' => [ + 'choices' => array_flip($options['campaignContactStatus']), + 'choices_as_values' => true, + 'attr' => [ 'class' => 'form-control', ], 'label' => 'mautic.plugin.integration.campaigns.member.status', 'required' => false, diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php b/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php index 50656cb5f11..8cdfe143834 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php @@ -35,12 +35,13 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'campaigns', ChoiceType::class, [ - 'choices' => $options['campaigns'], + 'choices' => array_flip($options['campaigns']), 'attr' => [ 'class' => 'form-control', 'onchange' => 'Mautic.getIntegrationCampaignStatus(this);', ], - 'label' => 'mautic.plugin.integration.campaigns', - 'empty_value' => 'mautic.plugin.config.campaign.member.chooseone', - 'required' => false, + 'label' => 'mautic.plugin.integration.campaigns', + 'empty_value' => 'mautic.plugin.config.campaign.member.chooseone', + 'required' => false, + 'choices_as_values' => true, ] ); } diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php b/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php index 34eadcf1d9e..0f046623d87 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php @@ -53,7 +53,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) if (!isset($integrations[$settings->getPlugin()->getName()])) { $integrations[$settings->getPlugin()->getName()] = []; } - $integrations[$settings->getPlugin()->getName()][$object->getName()] = $object->getDisplayName(); + $integrations[$settings->getPlugin()->getName()][$object->getDisplayName()] = $object->getName(); } } @@ -77,6 +77,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ['message' => 'mautic.core.value.required'] ), ], + 'choices_as_values' => true, ] ); @@ -85,7 +86,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) $campaignChoices = []; if (isset($data['integration'])) { - $integration = $data['integration']; $integrationObject = $integrationHelper->getIntegrationObject($data['integration']); if (method_exists($integrationObject, 'getCampaigns')) { $campaigns = $integrationObject->getCampaigns(); diff --git a/app/bundles/PluginBundle/Form/Type/KeysType.php b/app/bundles/PluginBundle/Form/Type/KeysType.php index d373ccd3cc2..3c73b169e21 100644 --- a/app/bundles/PluginBundle/Form/Type/KeysType.php +++ b/app/bundles/PluginBundle/Form/Type/KeysType.php @@ -12,6 +12,8 @@ namespace Mautic\PluginBundle\Form\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\PasswordType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\Callback; @@ -52,7 +54,7 @@ function ($validateMe, ExecutionContextInterface $context) use ($options) { ), ] : []; - $type = ($isSecret) ? 'password' : 'text'; + $type = ($isSecret) ? PasswordType::class : TextType::class; $builder->add( $key, From de8a378c5b2fb2e2207dff91d88f06bf9a8a4964 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 29 Nov 2019 16:14:38 +0100 Subject: [PATCH 22/56] Replace getNameMethod in form --- app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php b/app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php index 799a3d42be2..63564ac8234 100644 --- a/app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php +++ b/app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php @@ -191,7 +191,7 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'integration_featuresettings'; } From fd2ff932cb90aa6b4d8715faa1af5c6e54f073ce Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 29 Nov 2019 16:21:48 +0100 Subject: [PATCH 23/56] Fix form configs --- app/bundles/PluginBundle/Config/config.php | 24 ++++++++-------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/app/bundles/PluginBundle/Config/config.php b/app/bundles/PluginBundle/Config/config.php index df93f1e4b5e..57bde343895 100644 --- a/app/bundles/PluginBundle/Config/config.php +++ b/app/bundles/PluginBundle/Config/config.php @@ -99,44 +99,36 @@ ], 'forms' => [ 'mautic.form.type.integration.details' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\DetailsType', - 'alias' => 'integration_details', + 'class' => \Mautic\PluginBundle\Form\Type\DetailsType::class, ], 'mautic.form.type.integration.settings' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\FeatureSettingsType', + 'class' => \Mautic\PluginBundle\Form\Type\FeatureSettingsType::class, 'arguments' => [ 'session', 'mautic.helper.core_parameters', 'monolog.logger.mautic', ], - 'alias' => 'integration_featuresettings', ], 'mautic.form.type.integration.fields' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\FieldsType', - 'alias' => 'integration_fields', + 'class' => \Mautic\PluginBundle\Form\Type\FieldsType::class, 'arguments' => 'translator', ], 'mautic.form.type.integration.company.fields' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\CompanyFieldsType', - 'alias' => 'integration_company_fields', + 'class' => \Mautic\PluginBundle\Form\Type\CompanyFieldsType::class, 'arguments' => 'translator', ], 'mautic.form.type.integration.keys' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\KeysType', - 'alias' => 'integration_keys', + 'class' => \Mautic\PluginBundle\Form\Type\KeysType::class, ], 'mautic.form.type.integration.list' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\IntegrationsListType', + 'class' => \Mautic\PluginBundle\Form\Type\IntegrationsListType::class, 'arguments' => 'mautic.factory', - 'alias' => 'integration_list', ], 'mautic.form.type.integration.config' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\IntegrationConfigType', - 'alias' => 'integration_config', + 'class' => \Mautic\PluginBundle\Form\Type\IntegrationConfigType::class, ], 'mautic.form.type.integration.campaign' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\IntegrationCampaignsType', - 'alias' => 'integration_campaign_status', + 'class' => \Mautic\PluginBundle\Form\Type\IntegrationCampaignsType::class, ], ], 'other' => [ From 7601e7a38aef1a53aaa5f254d176a1dbe134a6c2 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Mon, 2 Dec 2019 14:15:16 +0100 Subject: [PATCH 24/56] Add type describing comment --- plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php b/plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php index fa59e5c999f..d426711d7dc 100644 --- a/plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php +++ b/plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php @@ -9,6 +9,7 @@ use Mautic\PluginBundle\Entity\Integration; use Mautic\PluginBundle\Entity\IntegrationEntity; use Mautic\PluginBundle\Entity\Plugin; +use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\UserBundle\Entity\Role; use Mautic\UserBundle\Entity\User; use MauticPlugin\MauticCrmBundle\Entity\PipedriveOwner; @@ -220,6 +221,7 @@ protected function createCompanyIntegrationEntity($integrationEntityId, $interna protected function getIntegrationObject() { + /** @var IntegrationHelper $integrationHelper */ $integrationHelper = $this->container->get('mautic.helper.integration'); /** @var Integration $integration */ From bb716d70a79f0259ec058baa4a9dc3e6ae0c4075 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Mon, 2 Dec 2019 15:10:09 +0100 Subject: [PATCH 25/56] Fix integration dependencies --- plugins/MauticCrmBundle/Config/config.php | 105 ++++++++++++++++++ .../Integration/HubspotIntegration.php | 70 +++++++++++- .../Integration/SugarcrmIntegration.php | 71 +++++++++++- 3 files changed, 238 insertions(+), 8 deletions(-) diff --git a/plugins/MauticCrmBundle/Config/config.php b/plugins/MauticCrmBundle/Config/config.php index 3cf1521e4e0..c016e2ebf1c 100644 --- a/plugins/MauticCrmBundle/Config/config.php +++ b/plugins/MauticCrmBundle/Config/config.php @@ -65,38 +65,143 @@ 'mautic.integration.hubspot' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\HubspotIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', 'mautic.helper.user', ], ], 'mautic.integration.salesforce' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\SalesforceIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.sugarcrm' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\SugarcrmIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', 'mautic.lead.model.dnc', ], ], 'mautic.integration.vtiger' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\VtigerIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.zoho' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\ZohoIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.dynamics' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\DynamicsIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.connectwise' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\ConnectwiseIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], diff --git a/plugins/MauticCrmBundle/Integration/HubspotIntegration.php b/plugins/MauticCrmBundle/Integration/HubspotIntegration.php index 1ba0c4fe365..6f2eac0c47d 100644 --- a/plugins/MauticCrmBundle/Integration/HubspotIntegration.php +++ b/plugins/MauticCrmBundle/Integration/HubspotIntegration.php @@ -12,14 +12,29 @@ namespace MauticPlugin\MauticCrmBundle\Integration; +use Doctrine\ORM\EntityManager; +use Mautic\CoreBundle\Helper\CacheStorageHelper; +use Mautic\CoreBundle\Helper\EncryptionHelper; +use Mautic\CoreBundle\Helper\PathsHelper; use Mautic\CoreBundle\Helper\UserHelper; +use Mautic\CoreBundle\Model\NotificationModel; use Mautic\LeadBundle\DataObject\LeadManipulator; use Mautic\LeadBundle\Entity\Lead; use Mautic\LeadBundle\Entity\StagesChangeLog; +use Mautic\LeadBundle\Model\CompanyModel; +use Mautic\LeadBundle\Model\FieldModel; +use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Entity\IntegrationEntityRepository; +use Mautic\PluginBundle\Model\IntegrationEntityModel; use Mautic\StageBundle\Entity\Stage; use MauticPlugin\MauticCrmBundle\Api\HubspotApi; +use Monolog\Logger; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\Routing\Router; +use Symfony\Component\Translation\DataCollectorTranslator; /** * Class HubspotIntegration. @@ -36,13 +51,60 @@ class HubspotIntegration extends CrmAbstractIntegration /** * HubspotIntegration constructor. * - * @param UserHelper $userHelper + * @param EventDispatcherInterface $eventDispatcher + * @param CacheStorageHelper $cacheStorageHelper + * @param EntityManager $entityManager + * @param Session $session + * @param RequestStack $requestStack + * @param Router $router + * @param DataCollectorTranslator $translator + * @param Logger $logger + * @param EncryptionHelper $encryptionHelper + * @param LeadModel $leadModel + * @param CompanyModel $companyModel + * @param PathsHelper $pathsHelper + * @param NotificationModel $notificationModel + * @param FieldModel $fieldModel + * @param IntegrationEntityModel $integrationEntityModel + * @param UserHelper $userHelper */ - public function __construct(UserHelper $userHelper) - { + public function __construct( + EventDispatcherInterface $eventDispatcher, + CacheStorageHelper $cacheStorageHelper, + EntityManager $entityManager, + Session $session, + RequestStack $requestStack, + Router $router, + DataCollectorTranslator $translator, + Logger $logger, + EncryptionHelper $encryptionHelper, + LeadModel $leadModel, + CompanyModel $companyModel, + PathsHelper $pathsHelper, + NotificationModel $notificationModel, + FieldModel $fieldModel, + IntegrationEntityModel $integrationEntityModel, + UserHelper $userHelper + ) { $this->userHelper = $userHelper; - parent::__construct(); + parent::__construct( + $eventDispatcher, + $cacheStorageHelper, + $entityManager, + $session, + $requestStack, + $router, + $translator, + $logger, + $encryptionHelper, + $leadModel, + $companyModel, + $pathsHelper, + $notificationModel, + $fieldModel, + $integrationEntityModel + ); } /** diff --git a/plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php b/plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php index 4ad718b598f..a56a31b684c 100644 --- a/plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php +++ b/plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php @@ -11,16 +11,31 @@ namespace MauticPlugin\MauticCrmBundle\Integration; +use Doctrine\ORM\EntityManager; use Mautic\CoreBundle\Form\Type\ButtonGroupType; +use Mautic\CoreBundle\Helper\CacheStorageHelper; +use Mautic\CoreBundle\Helper\EncryptionHelper; +use Mautic\CoreBundle\Helper\PathsHelper; +use Mautic\CoreBundle\Model\NotificationModel; use Mautic\LeadBundle\Entity\Company; use Mautic\LeadBundle\Entity\Lead; +use Mautic\LeadBundle\Model\CompanyModel; use Mautic\LeadBundle\Model\DoNotContact; +use Mautic\LeadBundle\Model\FieldModel; +use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Entity\IntegrationEntity; use Mautic\PluginBundle\Entity\IntegrationEntityRepository; use Mautic\PluginBundle\Exception\ApiErrorException; +use Mautic\PluginBundle\Model\IntegrationEntityModel; +use Monolog\Logger; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilder; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Routing\Router; +use Symfony\Component\Translation\DataCollectorTranslator; use Symfony\Component\Validator\Constraints\NotBlank; /** @@ -45,12 +60,60 @@ class SugarcrmIntegration extends CrmAbstractIntegration /** * SugarcrmIntegration constructor. * - * @param DoNotContact $doNotContactModel + * @param EventDispatcherInterface $eventDispatcher + * @param CacheStorageHelper $cacheStorageHelper + * @param EntityManager $entityManager + * @param Session $session + * @param RequestStack $requestStack + * @param Router $router + * @param DataCollectorTranslator $translator + * @param Logger $logger + * @param EncryptionHelper $encryptionHelper + * @param LeadModel $leadModel + * @param CompanyModel $companyModel + * @param PathsHelper $pathsHelper + * @param NotificationModel $notificationModel + * @param FieldModel $fieldModel + * @param IntegrationEntityModel $integrationEntityModel + * @param DoNotContact $doNotContactModel */ - public function __construct(DoNotContact $doNotContactModel) - { + public function __construct( + EventDispatcherInterface $eventDispatcher, + CacheStorageHelper $cacheStorageHelper, + EntityManager $entityManager, + Session $session, + RequestStack $requestStack, + Router $router, + DataCollectorTranslator $translator, + Logger $logger, + EncryptionHelper $encryptionHelper, + LeadModel $leadModel, + CompanyModel $companyModel, + PathsHelper $pathsHelper, + NotificationModel $notificationModel, + FieldModel $fieldModel, + IntegrationEntityModel $integrationEntityModel, + DoNotContact $doNotContactModel + ) { $this->doNotContactModel = $doNotContactModel; - parent::__construct(); + + parent::__construct( + $eventDispatcher, + $cacheStorageHelper, + $entityManager, + $session, + $requestStack, + $router, + $translator, + $logger, + $encryptionHelper, + $leadModel, + $companyModel, + $pathsHelper, + $notificationModel, + $fieldModel, + $integrationEntityModel + ); } /** From a288c62cab1a8da698d5eb0ca08b594be618f6f2 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Mon, 2 Dec 2019 17:34:28 +0100 Subject: [PATCH 26/56] Fix integration dependencies --- plugins/MauticCitrixBundle/Config/config.php | 60 +++++++++++++ .../Config/config.php | 51 +++++++++++ .../Config/config.php | 45 ++++++++++ plugins/MauticSocialBundle/Config/config.php | 90 +++++++++++++++++++ 4 files changed, 246 insertions(+) diff --git a/plugins/MauticCitrixBundle/Config/config.php b/plugins/MauticCitrixBundle/Config/config.php index c1f9c25421d..539a588df6c 100644 --- a/plugins/MauticCitrixBundle/Config/config.php +++ b/plugins/MauticCitrixBundle/Config/config.php @@ -112,21 +112,81 @@ 'mautic.integration.gotoassist' => [ 'class' => \MauticPlugin\MauticCitrixBundle\Integration\GotoassistIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.gotomeeting' => [ 'class' => \MauticPlugin\MauticCitrixBundle\Integration\GotomeetingIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.gototraining' => [ 'class' => \MauticPlugin\MauticCitrixBundle\Integration\GototrainingIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.gotowebinar' => [ 'class' => \MauticPlugin\MauticCitrixBundle\Integration\GotowebinarIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], diff --git a/plugins/MauticCloudStorageBundle/Config/config.php b/plugins/MauticCloudStorageBundle/Config/config.php index f1422d80671..1e17a3d3c0e 100644 --- a/plugins/MauticCloudStorageBundle/Config/config.php +++ b/plugins/MauticCloudStorageBundle/Config/config.php @@ -32,12 +32,63 @@ 'integrations' => [ 'mautic.integration.amazons3' => [ 'class' => \MauticPlugin\MauticCloudStorageBundle\Integration\AmazonS3Integration::class, + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + ], ], 'mautic.integration.openstack' => [ 'class' => \MauticPlugin\MauticCloudStorageBundle\Integration\OpenStackIntegration::class, + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + ], ], 'mautic.integration.rackspace' => [ 'class' => \MauticPlugin\MauticCloudStorageBundle\Integration\RackspaceIntegration::class, + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + ], ], ], ], diff --git a/plugins/MauticEmailMarketingBundle/Config/config.php b/plugins/MauticEmailMarketingBundle/Config/config.php index e59f058f964..0a4e593acc6 100644 --- a/plugins/MauticEmailMarketingBundle/Config/config.php +++ b/plugins/MauticEmailMarketingBundle/Config/config.php @@ -34,16 +34,61 @@ 'mautic.integration.constantcontact' => [ 'class' => \MauticPlugin\MauticEmailMarketingBundle\Integration\ConstantContactIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.icontact' => [ 'class' => \MauticPlugin\MauticEmailMarketingBundle\Integration\IcontactIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.mailchimp' => [ 'class' => \MauticPlugin\MauticEmailMarketingBundle\Integration\MailchimpIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], diff --git a/plugins/MauticSocialBundle/Config/config.php b/plugins/MauticSocialBundle/Config/config.php index 6286f072c4d..ce226242ce7 100644 --- a/plugins/MauticSocialBundle/Config/config.php +++ b/plugins/MauticSocialBundle/Config/config.php @@ -178,31 +178,121 @@ 'mautic.integration.facebook' => [ 'class' => \MauticPlugin\MauticSocialBundle\Integration\FacebookIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.foursquare' => [ 'class' => \MauticPlugin\MauticSocialBundle\Integration\FoursquareIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.googleplus' => [ 'class' => \MauticPlugin\MauticSocialBundle\Integration\GooglePlusIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.instagram' => [ 'class' => \MauticPlugin\MauticSocialBundle\Integration\InstagramIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.linkedin' => [ 'class' => \MauticPlugin\MauticSocialBundle\Integration\LinkedInIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.twitter' => [ 'class' => \MauticPlugin\MauticSocialBundle\Integration\TwitterIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], From cea53f0a0768af70809b136e41841f06ede0c7b0 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Mon, 2 Dec 2019 17:41:10 +0100 Subject: [PATCH 27/56] Fix available services build in integration helper --- app/bundles/PluginBundle/Helper/IntegrationHelper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/bundles/PluginBundle/Helper/IntegrationHelper.php b/app/bundles/PluginBundle/Helper/IntegrationHelper.php index b6b78a52266..cdb564a0118 100644 --- a/app/bundles/PluginBundle/Helper/IntegrationHelper.php +++ b/app/bundles/PluginBundle/Helper/IntegrationHelper.php @@ -313,7 +313,9 @@ public function getIntegrationObjects($specificIntegrations = null, $withFeature } } - $returnServices[$integrationName] = $this->integrations[$integrationName]; + if (isset($this->integrations[$integrationName])) { + $returnServices[$integrationName] = $this->integrations[$integrationName]; + } } foreach ($returnServices as $key => $value) { From 3ff0bdd8748d67151c2e6125cd3863257da0a8b2 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Mon, 2 Dec 2019 17:48:38 +0100 Subject: [PATCH 28/56] Fix form type usage in integration settings --- app/bundles/PluginBundle/Controller/PluginController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/bundles/PluginBundle/Controller/PluginController.php b/app/bundles/PluginBundle/Controller/PluginController.php index 2c762649169..0235de0beeb 100644 --- a/app/bundles/PluginBundle/Controller/PluginController.php +++ b/app/bundles/PluginBundle/Controller/PluginController.php @@ -13,10 +13,9 @@ use Mautic\CoreBundle\Controller\FormController; use Mautic\CoreBundle\Helper\InputHelper; -use Mautic\PluginBundle\Entity\Integration; -use Mautic\PluginBundle\Entity\Plugin; use Mautic\PluginBundle\Event\PluginIntegrationAuthRedirectEvent; use Mautic\PluginBundle\Event\PluginIntegrationEvent; +use Mautic\PluginBundle\Form\Type\DetailsType; use Mautic\PluginBundle\Integration\AbstractIntegration; use Mautic\PluginBundle\Model\PluginModel; use Mautic\PluginBundle\PluginEvents; @@ -181,7 +180,7 @@ public function configAction($name, $activeTab = 'details-container', $page = 1) $entity = $integrationObject->getIntegrationSettings(); $form = $this->createForm( - 'integration_details', + DetailsType::class, $entity, [ 'integration' => $entity->getName(), From 3b853e4211c4454360d20c623de753061d3912cc Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Mon, 2 Dec 2019 18:19:07 +0100 Subject: [PATCH 29/56] Add Pipedrive integration config --- plugins/MauticCrmBundle/Config/config.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plugins/MauticCrmBundle/Config/config.php b/plugins/MauticCrmBundle/Config/config.php index c016e2ebf1c..69b68188525 100644 --- a/plugins/MauticCrmBundle/Config/config.php +++ b/plugins/MauticCrmBundle/Config/config.php @@ -204,6 +204,26 @@ 'mautic.plugin.model.integration_entity', ], ], + 'mautic.integration.pipedrive' => [ + 'class' => \MauticPlugin\MauticCrmBundle\Integration\PipedriveIntegration::class, + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + ], + ], ], 'other' => [ 'mautic_integration.pipedrive.guzzle.client' => [ From 4b92c6c547b2ec8fed16cda0679e0521e68a6c59 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 10:48:59 +0100 Subject: [PATCH 30/56] Use FQCN for form types in \Mautic\PluginBundle\Controller\AjaxController::getIntegrationFieldsAction() --- app/bundles/PluginBundle/Controller/AjaxController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/bundles/PluginBundle/Controller/AjaxController.php b/app/bundles/PluginBundle/Controller/AjaxController.php index 88ca5a30fdf..1e012c68bf9 100644 --- a/app/bundles/PluginBundle/Controller/AjaxController.php +++ b/app/bundles/PluginBundle/Controller/AjaxController.php @@ -13,6 +13,8 @@ use Mautic\CoreBundle\Controller\AjaxController as CommonAjaxController; use Mautic\CoreBundle\Helper\InputHelper; +use Mautic\PluginBundle\Form\Type\CompanyFieldsType; +use Mautic\PluginBundle\Form\Type\FieldsType; use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\HttpFoundation\Request; @@ -79,7 +81,7 @@ protected function getIntegrationFieldsAction(Request $request) $mauticFields = ($isLead) ? $pluginModel->getLeadFields() : $pluginModel->getCompanyFields(); $featureSettings = $integrationObject->getIntegrationSettings()->getFeatureSettings(); $enableDataPriority = $integrationObject->getDataPriority(); - $formType = $isLead ? 'integration_fields' : 'integration_company_fields'; + $formType = $isLead ? FieldsType::class : CompanyFieldsType::class; $form = $this->createForm( $formType, isset($featureSettings[$object.'Fields']) ? $featureSettings[$object.'Fields'] : [], From b16a76cff221597e9729425c20be848f290e2156 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 10:54:24 +0100 Subject: [PATCH 31/56] Use FQCN of \Mautic\PluginBundle\Form\Type\FieldsType in other types --- .../Form/Type/ConstantContactType.php | 3 ++- plugins/MauticEmailMarketingBundle/Form/Type/IcontactType.php | 3 ++- plugins/MauticEmailMarketingBundle/Form/Type/MailchimpType.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/MauticEmailMarketingBundle/Form/Type/ConstantContactType.php b/plugins/MauticEmailMarketingBundle/Form/Type/ConstantContactType.php index 39d6d2e2467..0f6afd6bc96 100644 --- a/plugins/MauticEmailMarketingBundle/Form/Type/ConstantContactType.php +++ b/plugins/MauticEmailMarketingBundle/Form/Type/ConstantContactType.php @@ -13,6 +13,7 @@ use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType; use Mautic\CoreBundle\Helper\CoreParametersHelper; +use Mautic\PluginBundle\Form\Type\FieldsType; use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\Form\AbstractType; @@ -120,7 +121,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $fields = $object->getFormLeadFields(); list($specialInstructions, $alertType) = $object->getFormNotes('leadfield_match'); - $builder->add('leadFields', 'integration_fields', [ + $builder->add('leadFields', FieldsType::class, [ 'label' => 'mautic.integration.leadfield_matches', 'required' => true, 'mautic_fields' => $leadFields, diff --git a/plugins/MauticEmailMarketingBundle/Form/Type/IcontactType.php b/plugins/MauticEmailMarketingBundle/Form/Type/IcontactType.php index 85b12960bd1..331176e51dd 100644 --- a/plugins/MauticEmailMarketingBundle/Form/Type/IcontactType.php +++ b/plugins/MauticEmailMarketingBundle/Form/Type/IcontactType.php @@ -12,6 +12,7 @@ namespace MauticPlugin\MauticEmailMarketingBundle\Form\Type; use Mautic\CoreBundle\Helper\CoreParametersHelper; +use Mautic\PluginBundle\Form\Type\FieldsType; use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\Form\AbstractType; @@ -114,7 +115,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $fields = $object->getFormLeadFields(); list($specialInstructions, $alertType) = $object->getFormNotes('leadfield_match'); - $builder->add('leadFields', 'integration_fields', [ + $builder->add('leadFields', FieldsType::class, [ 'label' => 'mautic.integration.leadfield_matches', 'required' => true, 'mautic_fields' => $leadFields, diff --git a/plugins/MauticEmailMarketingBundle/Form/Type/MailchimpType.php b/plugins/MauticEmailMarketingBundle/Form/Type/MailchimpType.php index 56f595e55c6..2b1a1e253f4 100644 --- a/plugins/MauticEmailMarketingBundle/Form/Type/MailchimpType.php +++ b/plugins/MauticEmailMarketingBundle/Form/Type/MailchimpType.php @@ -13,6 +13,7 @@ use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType; use Mautic\CoreBundle\Helper\CoreParametersHelper; +use Mautic\PluginBundle\Form\Type\FieldsType; use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\Form\AbstractType; @@ -146,7 +147,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } list($specialInstructions) = $mailchimp->getFormNotes('leadfield_match'); - $form->add('leadFields', 'integration_fields', [ + $form->add('leadFields', FieldsType::class, [ 'label' => 'mautic.integration.leadfield_matches', 'required' => true, 'mautic_fields' => $leadFields, From 5f6dd8524871ad714c1d1183ac75967ce8adc1ac Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 10:58:00 +0100 Subject: [PATCH 32/56] Use FQCN of IntegrationConfigType in \Mautic\PluginBundle\Controller\AjaxController::getIntegrationConfigAction() --- app/bundles/PluginBundle/Controller/AjaxController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/bundles/PluginBundle/Controller/AjaxController.php b/app/bundles/PluginBundle/Controller/AjaxController.php index 1e012c68bf9..b4afde2b29e 100644 --- a/app/bundles/PluginBundle/Controller/AjaxController.php +++ b/app/bundles/PluginBundle/Controller/AjaxController.php @@ -15,6 +15,7 @@ use Mautic\CoreBundle\Helper\InputHelper; use Mautic\PluginBundle\Form\Type\CompanyFieldsType; use Mautic\PluginBundle\Form\Type\FieldsType; +use Mautic\PluginBundle\Form\Type\IntegrationConfigType; use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\HttpFoundation\Request; @@ -163,7 +164,7 @@ protected function getIntegrationConfigAction(Request $request) } } } - $form = $this->createForm('integration_config', $defaults, [ + $form = $this->createForm(IntegrationConfigType::class, $defaults, [ 'integration' => $object, 'csrf_protection' => false, 'campaigns' => $data, From a05c8c253756d948bac190f2ee9a45029929e2c2 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 10:59:56 +0100 Subject: [PATCH 33/56] Use FQCN of IntegrationsListType in subscribers --- app/bundles/PluginBundle/EventListener/CampaignSubscriber.php | 3 ++- app/bundles/PluginBundle/EventListener/FormSubscriber.php | 3 ++- app/bundles/PluginBundle/EventListener/PointSubscriber.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/bundles/PluginBundle/EventListener/CampaignSubscriber.php b/app/bundles/PluginBundle/EventListener/CampaignSubscriber.php index 996b455f987..80a43b98cb0 100644 --- a/app/bundles/PluginBundle/EventListener/CampaignSubscriber.php +++ b/app/bundles/PluginBundle/EventListener/CampaignSubscriber.php @@ -15,6 +15,7 @@ use Mautic\CampaignBundle\Event\CampaignBuilderEvent; use Mautic\CampaignBundle\Event\CampaignExecutionEvent; use Mautic\CoreBundle\EventListener\CommonSubscriber; +use Mautic\PluginBundle\Form\Type\IntegrationsListType; use Mautic\PluginBundle\PluginEvents; /** @@ -43,7 +44,7 @@ public function onCampaignBuild(CampaignBuilderEvent $event) $action = [ 'label' => 'mautic.plugin.actions.push_lead', 'description' => 'mautic.plugin.actions.tooltip', - 'formType' => 'integration_list', + 'formType' => IntegrationsListType::class, 'formTheme' => 'MauticPluginBundle:FormTheme\Integration', 'eventName' => PluginEvents::ON_CAMPAIGN_TRIGGER_ACTION, ]; diff --git a/app/bundles/PluginBundle/EventListener/FormSubscriber.php b/app/bundles/PluginBundle/EventListener/FormSubscriber.php index f0c42686625..3bcf51db3a4 100644 --- a/app/bundles/PluginBundle/EventListener/FormSubscriber.php +++ b/app/bundles/PluginBundle/EventListener/FormSubscriber.php @@ -15,6 +15,7 @@ use Mautic\FormBundle\Event\FormBuilderEvent; use Mautic\FormBundle\Event\SubmissionEvent; use Mautic\FormBundle\FormEvents; +use Mautic\PluginBundle\Form\Type\IntegrationsListType; use Mautic\PluginBundle\PluginEvents; /** @@ -44,7 +45,7 @@ public function onFormBuild(FormBuilderEvent $event) 'group' => 'mautic.plugin.actions', 'description' => 'mautic.plugin.actions.tooltip', 'label' => 'mautic.plugin.actions.push_lead', - 'formType' => 'integration_list', + 'formType' => IntegrationsListType::class, 'formTheme' => 'MauticPluginBundle:FormTheme\Integration', 'eventName' => PluginEvents::ON_FORM_SUBMIT_ACTION_TRIGGERED, ]; diff --git a/app/bundles/PluginBundle/EventListener/PointSubscriber.php b/app/bundles/PluginBundle/EventListener/PointSubscriber.php index e566446fe17..bd32ec4efb5 100644 --- a/app/bundles/PluginBundle/EventListener/PointSubscriber.php +++ b/app/bundles/PluginBundle/EventListener/PointSubscriber.php @@ -12,6 +12,7 @@ namespace Mautic\PluginBundle\EventListener; use Mautic\CoreBundle\EventListener\CommonSubscriber; +use Mautic\PluginBundle\Form\Type\IntegrationsListType; use Mautic\PointBundle\Event\TriggerBuilderEvent; use Mautic\PointBundle\PointEvents; @@ -38,7 +39,7 @@ public function onTriggerBuild(TriggerBuilderEvent $event) $action = [ 'group' => 'mautic.plugin.point.action', 'label' => 'mautic.plugin.actions.push_lead', - 'formType' => 'integration_list', + 'formType' => IntegrationsListType::class, 'formTheme' => 'MauticPluginBundle:FormTheme\Integration', 'callback' => ['\\Mautic\\PluginBundle\\Helper\\EventHelper', 'pushLead'], ]; From 349ce80a2f139ec852407a27c4eb2641aaa36482 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 11:02:55 +0100 Subject: [PATCH 34/56] Use FQCN for callback in PointSubscriber --- app/bundles/PluginBundle/EventListener/PointSubscriber.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/bundles/PluginBundle/EventListener/PointSubscriber.php b/app/bundles/PluginBundle/EventListener/PointSubscriber.php index bd32ec4efb5..0d928d6abf3 100644 --- a/app/bundles/PluginBundle/EventListener/PointSubscriber.php +++ b/app/bundles/PluginBundle/EventListener/PointSubscriber.php @@ -13,6 +13,7 @@ use Mautic\CoreBundle\EventListener\CommonSubscriber; use Mautic\PluginBundle\Form\Type\IntegrationsListType; +use Mautic\PluginBundle\Helper\EventHelper; use Mautic\PointBundle\Event\TriggerBuilderEvent; use Mautic\PointBundle\PointEvents; @@ -41,7 +42,7 @@ public function onTriggerBuild(TriggerBuilderEvent $event) 'label' => 'mautic.plugin.actions.push_lead', 'formType' => IntegrationsListType::class, 'formTheme' => 'MauticPluginBundle:FormTheme\Integration', - 'callback' => ['\\Mautic\\PluginBundle\\Helper\\EventHelper', 'pushLead'], + 'callback' => [EventHelper::class, 'pushLead'], ]; $event->addEvent('plugin.leadpush', $action); From 8407036327f006963e15200849841d9738bfc571 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 11:15:29 +0100 Subject: [PATCH 35/56] Remove setDefaultOptions from \Mautic\PluginBundle\Form\Type\DetailsType --- app/bundles/PluginBundle/Form/Type/DetailsType.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/bundles/PluginBundle/Form/Type/DetailsType.php b/app/bundles/PluginBundle/Form/Type/DetailsType.php index 47147867e43..c156574d3f7 100644 --- a/app/bundles/PluginBundle/Form/Type/DetailsType.php +++ b/app/bundles/PluginBundle/Form/Type/DetailsType.php @@ -21,7 +21,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * Class DetailsType. @@ -142,7 +142,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'data_class' => Integration::class, From 9ba690b1d2051ba2690672567f1a09dc229e27fd Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 11:25:19 +0100 Subject: [PATCH 36/56] Use FQCN of IntegrationCampaignsType in \Mautic\PluginBundle\Controller\AjaxController::getIntegrationCampaignStatusAction --- app/bundles/PluginBundle/Controller/AjaxController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/bundles/PluginBundle/Controller/AjaxController.php b/app/bundles/PluginBundle/Controller/AjaxController.php index b4afde2b29e..5bc5e625f43 100644 --- a/app/bundles/PluginBundle/Controller/AjaxController.php +++ b/app/bundles/PluginBundle/Controller/AjaxController.php @@ -15,6 +15,7 @@ use Mautic\CoreBundle\Helper\InputHelper; use Mautic\PluginBundle\Form\Type\CompanyFieldsType; use Mautic\PluginBundle\Form\Type\FieldsType; +use Mautic\PluginBundle\Form\Type\IntegrationCampaignsType; use Mautic\PluginBundle\Form\Type\IntegrationConfigType; use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\HttpFoundation\Request; @@ -219,7 +220,7 @@ protected function getIntegrationCampaignStatusAction(Request $request) } } } - $form = $this->createForm('integration_campaign_status', $statusData, [ + $form = $this->createForm(IntegrationCampaignsType::class, $statusData, [ 'csrf_protection' => false, 'campaignContactStatus' => $statusData, ]); From a9ad8d25dc71e5ba92465673f4bf4c6f1a39beaf Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 12:53:09 +0100 Subject: [PATCH 37/56] Use repository FQCN in entity --- app/bundles/PluginBundle/Entity/IntegrationEntity.php | 2 +- app/bundles/PluginBundle/Entity/Plugin.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/bundles/PluginBundle/Entity/IntegrationEntity.php b/app/bundles/PluginBundle/Entity/IntegrationEntity.php index 48530352524..7e08c95b1d5 100644 --- a/app/bundles/PluginBundle/Entity/IntegrationEntity.php +++ b/app/bundles/PluginBundle/Entity/IntegrationEntity.php @@ -82,7 +82,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata) $builder = new ClassMetadataBuilder($metadata); $builder->setTable('integration_entity') - ->setCustomRepositoryClass('Mautic\PluginBundle\Entity\IntegrationEntityRepository') + ->setCustomRepositoryClass(IntegrationEntityRepository::class) ->addIndex(['integration', 'integration_entity', 'integration_entity_id'], 'integration_external_entity') ->addIndex(['integration', 'internal_entity', 'internal_entity_id'], 'integration_internal_entity') ->addIndex(['integration', 'internal_entity', 'integration_entity'], 'integration_entity_match') diff --git a/app/bundles/PluginBundle/Entity/Plugin.php b/app/bundles/PluginBundle/Entity/Plugin.php index 1d97c05c7ce..49bf244031b 100644 --- a/app/bundles/PluginBundle/Entity/Plugin.php +++ b/app/bundles/PluginBundle/Entity/Plugin.php @@ -86,7 +86,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata) $builder = new ClassMetadataBuilder($metadata); $builder->setTable('plugins') - ->setCustomRepositoryClass('Mautic\PluginBundle\Entity\PluginRepository') + ->setCustomRepositoryClass(PluginRepository::class) ->addUniqueConstraint(['bundle'], 'unique_bundle'); $builder->addIdColumns(); From 2b77687664f05f987cabe7054153f2d0e46a5ce1 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 13:30:19 +0100 Subject: [PATCH 38/56] Remove setters logic used in IntegrationPass and now used directly in constructors --- .../Compiler/IntegrationPass.php | 17 --- .../Integration/AbstractIntegration.php | 139 +----------------- 2 files changed, 1 insertion(+), 155 deletions(-) diff --git a/app/bundles/CoreBundle/DependencyInjection/Compiler/IntegrationPass.php b/app/bundles/CoreBundle/DependencyInjection/Compiler/IntegrationPass.php index 1a85c305d47..1d88ea66f29 100644 --- a/app/bundles/CoreBundle/DependencyInjection/Compiler/IntegrationPass.php +++ b/app/bundles/CoreBundle/DependencyInjection/Compiler/IntegrationPass.php @@ -32,23 +32,6 @@ public function process(ContainerBuilder $container) * @deprecated: To be removed in 3.0. Set dependencies on Integration constructor instead, * using the service container config.php to pass those dependencies in. */ - $definition->addMethodCall('setFactory', [new Reference('mautic.factory')]); - - $definition->addMethodCall('setDispatcher', [new Reference('event_dispatcher')]); - $definition->addMethodCall('setCache', [new Reference('mautic.helper.cache_storage')]); - $definition->addMethodCall('setEntityManager', [new Reference('doctrine.orm.entity_manager')]); - $definition->addMethodCall('setSession', [new Reference('session')]); - $definition->addMethodCall('setRequest', [new Reference('request_stack')]); - $definition->addMethodCall('setRouter', [new Reference('router')]); - $definition->addMethodCall('setTranslator', [new Reference('translator')]); - $definition->addMethodCall('setLogger', [new Reference('monolog.logger.mautic')]); - $definition->addMethodCall('setEncryptionHelper', [new Reference('mautic.helper.encryption')]); - $definition->addMethodCall('setLeadModel', [new Reference('mautic.lead.model.lead')]); - $definition->addMethodCall('setCompanyModel', [new Reference('mautic.lead.model.company')]); - $definition->addMethodCall('setPathsHelper', [new Reference('mautic.helper.paths')]); - $definition->addMethodCall('setNotificationModel', [new Reference('mautic.core.model.notification')]); - $definition->addMethodCall('setFieldModel', [new Reference('mautic.lead.model.field')]); - $definition->addMethodCall('setIntegrationEntityModel', [new Reference('mautic.plugin.model.integration_entity')]); $class = $definition->getClass(); $reflected = new \ReflectionClass($class); diff --git a/app/bundles/PluginBundle/Integration/AbstractIntegration.php b/app/bundles/PluginBundle/Integration/AbstractIntegration.php index 991008987be..791905ef930 100644 --- a/app/bundles/PluginBundle/Integration/AbstractIntegration.php +++ b/app/bundles/PluginBundle/Integration/AbstractIntegration.php @@ -14,7 +14,6 @@ use Doctrine\ORM\EntityManager; use Joomla\Http\HttpFactory; use Mautic\CoreBundle\Entity\FormEntity; -use Mautic\CoreBundle\Factory\MauticFactory; use Mautic\CoreBundle\Helper\CacheStorageHelper; use Mautic\CoreBundle\Helper\EncryptionHelper; use Mautic\CoreBundle\Helper\PathsHelper; @@ -72,11 +71,6 @@ abstract class AbstractIntegration */ protected $coreIntegration = false; - /** - * @var MauticFactory - */ - protected $factory; - /** * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ @@ -242,7 +236,7 @@ public function __construct( $this->cache = $cacheStorageHelper->getCache($this->getName()); $this->em = $entityManager; $this->session = (!defined('IN_MAUTIC_CONSOLE')) ? $session : null; - $this->request = $requestStack->getCurrentRequest(); + $this->request = (!defined('IN_MAUTIC_CONSOLE')) ? $requestStack->getCurrentRequest() : null; $this->router = $router; $this->translator = $translator; $this->logger = $logger; @@ -255,137 +249,6 @@ public function __construct( $this->integrationEntityModel = $integrationEntityModel; } - /** - * @param MauticFactory $factory - * - * @deprecated 2.8.2 To be removed in 3.0. Use constructor arguments - * to set dependencies instead - */ - public function setFactory(MauticFactory $factory) - { - $this->factory = $factory; - } - - /** - * @param FieldModel $fieldModel - */ - public function setFieldModel(FieldModel $fieldModel) - { - $this->fieldModel = $fieldModel; - } - - /** - * @param NotificationModel $notificationModel - */ - public function setNotificationModel(NotificationModel $notificationModel) - { - $this->notificationModel = $notificationModel; - } - - /** - * @param PathsHelper $pathsHelper - */ - public function setPathsHelper(PathsHelper $pathsHelper) - { - $this->pathsHelper = $pathsHelper; - } - - /** - * @param CompanyModel $companyModel - */ - public function setCompanyModel(CompanyModel $companyModel) - { - $this->companyModel = $companyModel; - } - - /** - * @param LeadModel $leadModel - */ - public function setLeadModel(LeadModel $leadModel) - { - $this->leadModel = $leadModel; - } - - /** - * @param EncryptionHelper $encryptionHelper - */ - public function setEncryptionHelper(EncryptionHelper $encryptionHelper) - { - $this->encryptionHelper = $encryptionHelper; - } - - /** - * @param LoggerInterface $logger - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * @param TranslatorInterface $translator - */ - public function setTranslator(TranslatorInterface $translator) - { - $this->translator = $translator; - } - - /** - * @param Router $router - */ - public function setRouter(Router $router) - { - $this->router = $router; - } - - /** - * @param RequestStack $requestStack - */ - public function setRequest(RequestStack $requestStack) - { - $this->request = !defined('IN_MAUTIC_CONSOLE') ? $requestStack->getCurrentRequest() : null; - } - - /** - * @param Session|null $session - */ - public function setSession(Session $session = null) - { - $this->session = !defined('IN_MAUTIC_CONSOLE') ? $session : null; - } - - /** - * @param EntityManager $em - */ - public function setEntityManager(EntityManager $em) - { - $this->em = $em; - } - - /** - * @param CacheStorageHelper $cacheStorageHelper - */ - public function setCache(CacheStorageHelper $cacheStorageHelper) - { - $this->cache = $cacheStorageHelper->getCache($this->getName()); - } - - /** - * @param EventDispatcherInterface $dispatcher - */ - public function setDispatcher(EventDispatcherInterface $dispatcher) - { - $this->dispatcher = $dispatcher; - } - - /** - * @param IntegrationEntityModel $integrationModel - */ - public function setIntegrationEntityModel(IntegrationEntityModel $integrationEntityModel) - { - $this->integrationEntityModel = $integrationEntityModel; - } - public function setCommandParameters(array $params) { $this->commandParameters = $params; From 6c7f7db6843db1d55c6cb4165029b7dbf6adb191 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 13:48:48 +0100 Subject: [PATCH 39/56] Remove IntegrationPass from CoreBundle as it is not needed to set dependencies to Integration classes via setters. DI config used --- .../Compiler/IntegrationPass.php | 44 ------------ app/bundles/CoreBundle/MauticCoreBundle.php | 1 - plugins/MauticSocialBundle/Config/config.php | 6 ++ .../Integration/SocialIntegration.php | 71 +++++++++++++++++-- 4 files changed, 73 insertions(+), 49 deletions(-) delete mode 100644 app/bundles/CoreBundle/DependencyInjection/Compiler/IntegrationPass.php diff --git a/app/bundles/CoreBundle/DependencyInjection/Compiler/IntegrationPass.php b/app/bundles/CoreBundle/DependencyInjection/Compiler/IntegrationPass.php deleted file mode 100644 index 1d88ea66f29..00000000000 --- a/app/bundles/CoreBundle/DependencyInjection/Compiler/IntegrationPass.php +++ /dev/null @@ -1,44 +0,0 @@ -findTaggedServiceIds('mautic.integration') as $id => $tags) { - $definition = $container->findDefinition($id); - - /* - * @deprecated: To be removed in 3.0. Set dependencies on Integration constructor instead, - * using the service container config.php to pass those dependencies in. - */ - - $class = $definition->getClass(); - $reflected = new \ReflectionClass($class); - - if ($reflected->hasMethod('setIntegrationHelper')) { - $definition->addMethodCall('setIntegrationHelper', [new Reference('mautic.helper.integration')]); - } - } - } -} diff --git a/app/bundles/CoreBundle/MauticCoreBundle.php b/app/bundles/CoreBundle/MauticCoreBundle.php index 0302ab48614..325d8ddc674 100644 --- a/app/bundles/CoreBundle/MauticCoreBundle.php +++ b/app/bundles/CoreBundle/MauticCoreBundle.php @@ -30,6 +30,5 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new Compiler\TranslationsPass()); $container->addCompilerPass(new Compiler\ModelPass()); $container->addCompilerPass(new Compiler\EventPass()); - $container->addCompilerPass(new Compiler\IntegrationPass()); } } diff --git a/plugins/MauticSocialBundle/Config/config.php b/plugins/MauticSocialBundle/Config/config.php index ce226242ce7..11fe0c71946 100644 --- a/plugins/MauticSocialBundle/Config/config.php +++ b/plugins/MauticSocialBundle/Config/config.php @@ -193,6 +193,7 @@ 'mautic.core.model.notification', 'mautic.lead.model.field', 'mautic.plugin.model.integration_entity', + 'mautic.helper.integration', ], ], 'mautic.integration.foursquare' => [ @@ -213,6 +214,7 @@ 'mautic.core.model.notification', 'mautic.lead.model.field', 'mautic.plugin.model.integration_entity', + 'mautic.helper.integration', ], ], 'mautic.integration.googleplus' => [ @@ -233,6 +235,7 @@ 'mautic.core.model.notification', 'mautic.lead.model.field', 'mautic.plugin.model.integration_entity', + 'mautic.helper.integration', ], ], 'mautic.integration.instagram' => [ @@ -253,6 +256,7 @@ 'mautic.core.model.notification', 'mautic.lead.model.field', 'mautic.plugin.model.integration_entity', + 'mautic.helper.integration', ], ], 'mautic.integration.linkedin' => [ @@ -273,6 +277,7 @@ 'mautic.core.model.notification', 'mautic.lead.model.field', 'mautic.plugin.model.integration_entity', + 'mautic.helper.integration', ], ], 'mautic.integration.twitter' => [ @@ -293,6 +298,7 @@ 'mautic.core.model.notification', 'mautic.lead.model.field', 'mautic.plugin.model.integration_entity', + 'mautic.helper.integration', ], ], ], diff --git a/plugins/MauticSocialBundle/Integration/SocialIntegration.php b/plugins/MauticSocialBundle/Integration/SocialIntegration.php index 0f90b8fada3..9c14b41fb78 100644 --- a/plugins/MauticSocialBundle/Integration/SocialIntegration.php +++ b/plugins/MauticSocialBundle/Integration/SocialIntegration.php @@ -11,10 +11,24 @@ namespace MauticPlugin\MauticSocialBundle\Integration; +use Doctrine\ORM\EntityManager; +use Mautic\CoreBundle\Helper\CacheStorageHelper; +use Mautic\CoreBundle\Helper\EncryptionHelper; +use Mautic\CoreBundle\Helper\PathsHelper; +use Mautic\CoreBundle\Model\NotificationModel; +use Mautic\LeadBundle\Model\CompanyModel; +use Mautic\LeadBundle\Model\FieldModel; +use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\PluginBundle\Integration\AbstractIntegration; -use Symfony\Component\Form\Form; +use Mautic\PluginBundle\Model\IntegrationEntityModel; +use Monolog\Logger; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\FormBuilder; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\Routing\Router; +use Symfony\Component\Translation\DataCollectorTranslator; abstract class SocialIntegration extends AbstractIntegration { @@ -26,11 +40,60 @@ abstract class SocialIntegration extends AbstractIntegration protected $integrationHelper; /** - * @param IntegrationHelper $integrationHelper + * @param EventDispatcherInterface $eventDispatcher + * @param CacheStorageHelper $cacheStorageHelper + * @param EntityManager $entityManager + * @param Session $session + * @param RequestStack $requestStack + * @param Router $router + * @param DataCollectorTranslator $translator + * @param Logger $logger + * @param EncryptionHelper $encryptionHelper + * @param LeadModel $leadModel + * @param CompanyModel $companyModel + * @param PathsHelper $pathsHelper + * @param NotificationModel $notificationModel + * @param FieldModel $fieldModel + * @param IntegrationEntityModel $integrationEntityModel + * @param IntegrationHelper $integrationHelper */ - public function setIntegrationHelper(IntegrationHelper $integrationHelper) - { + public function __construct( + EventDispatcherInterface $eventDispatcher, + CacheStorageHelper $cacheStorageHelper, + EntityManager $entityManager, + Session $session, + RequestStack $requestStack, + Router $router, + DataCollectorTranslator $translator, + Logger $logger, + EncryptionHelper $encryptionHelper, + LeadModel $leadModel, + CompanyModel $companyModel, + PathsHelper $pathsHelper, + NotificationModel $notificationModel, + FieldModel $fieldModel, + IntegrationEntityModel $integrationEntityModel, + IntegrationHelper $integrationHelper + ) { $this->integrationHelper = $integrationHelper; + + parent::__construct( + $eventDispatcher, + $cacheStorageHelper, + $entityManager, + $session, + $requestStack, + $router, + $translator, + $logger, + $encryptionHelper, + $leadModel, + $companyModel, + $pathsHelper, + $notificationModel, + $fieldModel, + $integrationEntityModel + ); } /** From 3bbf717b5f4305ddd30ecf9939561571f60cc34d Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 13:54:21 +0100 Subject: [PATCH 40/56] Revert back ChoiceType field settings for mautic fields --- app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php b/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php index 1d31b38720d..2f06e50c6cf 100644 --- a/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php +++ b/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php @@ -198,7 +198,7 @@ function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $f 'm_'.$index, ChoiceType::class, [ - 'choices' => array_flip($mauticFields), + 'choices' => $mauticFields, 'label' => false, 'data' => $matched && isset($fieldData[$fieldsName][$field]) ? $fieldData[$fieldsName][$field] : '', 'label_attr' => ['class' => 'control-label'], From 829d59624db36d7a70b80450f3825a8509e3fd66 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 14:51:09 +0100 Subject: [PATCH 41/56] Fix custom Pipedrive integration deps --- plugins/MauticCrmBundle/Config/config.php | 2 + .../Integration/PipedriveIntegration.php | 98 +++++++++++++++++-- 2 files changed, 90 insertions(+), 10 deletions(-) diff --git a/plugins/MauticCrmBundle/Config/config.php b/plugins/MauticCrmBundle/Config/config.php index 69b68188525..dafa9629adf 100644 --- a/plugins/MauticCrmBundle/Config/config.php +++ b/plugins/MauticCrmBundle/Config/config.php @@ -222,6 +222,8 @@ 'mautic.core.model.notification', 'mautic.lead.model.field', 'mautic.plugin.model.integration_entity', + 'mautic_integration.service.transport', + 'mautic_integration.pipedrive.export.lead', ], ], ], diff --git a/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php b/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php index a5f2ef447f7..df86cc1aa19 100644 --- a/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php +++ b/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php @@ -3,9 +3,24 @@ namespace MauticPlugin\MauticCrmBundle\Integration; use Doctrine\ORM\EntityManager; +use Mautic\CoreBundle\Helper\CacheStorageHelper; +use Mautic\CoreBundle\Helper\EncryptionHelper; +use Mautic\CoreBundle\Helper\PathsHelper; +use Mautic\CoreBundle\Model\NotificationModel; +use Mautic\LeadBundle\Model\CompanyModel; +use Mautic\LeadBundle\Model\FieldModel; +use Mautic\LeadBundle\Model\LeadModel; +use Mautic\PluginBundle\Model\IntegrationEntityModel; use MauticPlugin\MauticCrmBundle\Integration\Pipedrive\Export\LeadExport; +use MauticPlugin\MauticCrmBundle\Services\Transport; +use Monolog\Logger; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Routing\Router; +use Symfony\Component\Translation\DataCollectorTranslator; class PipedriveIntegration extends CrmAbstractIntegration { @@ -21,6 +36,74 @@ class PipedriveIntegration extends CrmAbstractIntegration 'person' => ['firstname', 'lastname', 'email'], 'organization' => ['name'], ]; + /** + * @var Transport + */ + private $transport; + /** + * @var LeadExport + */ + private $leadExport; + + /** + * @param EventDispatcherInterface $eventDispatcher + * @param CacheStorageHelper $cacheStorageHelper + * @param EntityManager $entityManager + * @param Session $session + * @param RequestStack $requestStack + * @param Router $router + * @param DataCollectorTranslator $translator + * @param Logger $logger + * @param EncryptionHelper $encryptionHelper + * @param LeadModel $leadModel + * @param CompanyModel $companyModel + * @param PathsHelper $pathsHelper + * @param NotificationModel $notificationModel + * @param FieldModel $fieldModel + * @param IntegrationEntityModel $integrationEntityModel + * @param Transport $transport + * @param LeadExport $leadExport + */ + public function __construct( + EventDispatcherInterface $eventDispatcher, + CacheStorageHelper $cacheStorageHelper, + EntityManager $entityManager, + Session $session, + RequestStack $requestStack, + Router $router, + DataCollectorTranslator $translator, + Logger $logger, + EncryptionHelper $encryptionHelper, + LeadModel $leadModel, + CompanyModel $companyModel, + PathsHelper $pathsHelper, + NotificationModel $notificationModel, + FieldModel $fieldModel, + IntegrationEntityModel $integrationEntityModel, + Transport $transport, + LeadExport $leadExport + ) { + parent::__construct( + $eventDispatcher, + $cacheStorageHelper, + $entityManager, + $session, + $requestStack, + $router, + $translator, + $logger, + $encryptionHelper, + $leadModel, + $companyModel, + $pathsHelper, + $notificationModel, + $fieldModel, + $integrationEntityModel + ); + + $this->transport = $transport; + $this->leadExport = $leadExport; + } /** * @return string @@ -203,9 +286,8 @@ public function getAvailableLeadFields($object = null) public function getApiHelper() { if (empty($this->apiHelper)) { - $client = $this->factory->get('mautic_integration.service.transport'); $class = '\\MauticPlugin\\MauticCrmBundle\\Api\\'.$this->getName().'Api'; //TODO replace with service - $this->apiHelper = new $class($this, $client); + $this->apiHelper = new $class($this, $this->transport); } return $this->apiHelper; @@ -263,11 +345,9 @@ public function appendToForm(&$builder, $data, $formArea) */ public function pushLead($lead, $config = []) { - /** @var LeadExport $leadExport */ - $leadExport = $this->factory->get('mautic_integration.pipedrive.export.lead'); - $leadExport->setIntegration($this); + $this->leadExport->setIntegration($this); - return $leadExport->create($lead); + return $this->leadExport->create($lead); } /** @@ -279,7 +359,7 @@ public function pushLead($lead, $config = []) */ public function getFormNotes($section) { - $router = $this->factory->get('router'); + $router = $this->router; $translator = $this->getTranslator(); if ($section == 'authorization') { @@ -323,9 +403,7 @@ public function shouldImportDataToPipedrive() */ public function removeIntegrationEntities() { - /** @var EntityManager $em */ - $em = $this->factory->get('doctrine.orm.entity_manager'); - $qb = $em->getConnection()->createQueryBuilder(); + $qb = $this->em->getConnection()->createQueryBuilder(); return $qb->delete(MAUTIC_TABLE_PREFIX.'integration_entity') ->where( From a94dae3934ab0a5d0be932a3535193a755677f08 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 15:09:56 +0100 Subject: [PATCH 42/56] Fix tests --- .../Integration/AbstractIntegration.php | 5 ++-- .../PluginBundle/Tests/ConfigFormTest.php | 8 +---- .../Integration/AbstractIntegrationTest.php | 30 +++++++++++-------- .../AbstractIntegrationTestCase.php | 6 ++-- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/app/bundles/PluginBundle/Integration/AbstractIntegration.php b/app/bundles/PluginBundle/Integration/AbstractIntegration.php index 791905ef930..ddb37ef7cfb 100644 --- a/app/bundles/PluginBundle/Integration/AbstractIntegration.php +++ b/app/bundles/PluginBundle/Integration/AbstractIntegration.php @@ -47,7 +47,6 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Router; -use Symfony\Component\Translation\DataCollectorTranslator; use Symfony\Component\Translation\TranslatorInterface; /** @@ -205,7 +204,7 @@ abstract class AbstractIntegration * @param Session $session * @param RequestStack $requestStack * @param Router $router - * @param DataCollectorTranslator $translator + * @param TranslatorInterface $translator * @param Logger $logger * @param EncryptionHelper $encryptionHelper * @param LeadModel $leadModel @@ -222,7 +221,7 @@ public function __construct( Session $session, RequestStack $requestStack, Router $router, - DataCollectorTranslator $translator, + TranslatorInterface $translator, Logger $logger, EncryptionHelper $encryptionHelper, LeadModel $leadModel, diff --git a/app/bundles/PluginBundle/Tests/ConfigFormTest.php b/app/bundles/PluginBundle/Tests/ConfigFormTest.php index eec9c530632..ff82cf387f9 100644 --- a/app/bundles/PluginBundle/Tests/ConfigFormTest.php +++ b/app/bundles/PluginBundle/Tests/ConfigFormTest.php @@ -16,7 +16,6 @@ use Mautic\CoreBundle\Helper\CoreParametersHelper; use Mautic\CoreBundle\Helper\PathsHelper; use Mautic\CoreBundle\Helper\TemplatingHelper; -use Mautic\CoreBundle\Translation\Translator; use Mautic\PluginBundle\Entity\IntegrationEntityRepository; use Mautic\PluginBundle\Entity\IntegrationRepository; use Mautic\PluginBundle\Entity\PluginRepository; @@ -36,14 +35,9 @@ protected function setUp() public function testConfigForm() { - $plugins = $this->getIntegrationObject()->getIntegrationObjects(); - $mockTranslator = $this->getMockBuilder(Translator::class) - ->disableOriginalConstructor() - ->getMock(); + $plugins = $this->getIntegrationObject()->getIntegrationObjects(); foreach ($plugins as $name => $s) { - $s->setTranslator($mockTranslator); - $featureSettings = $s->getFormSettings(); $this->assertArrayHasKey('requires_callback', $featureSettings); diff --git a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTest.php b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTest.php index a5501444d70..d80284ee558 100644 --- a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTest.php +++ b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTest.php @@ -11,8 +11,6 @@ namespace Mautic\PluginBundle\Tests\Integration; -use Mautic\CoreBundle\Translation\Translator; -use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Integration\AbstractIntegration; class AbstractIntegrationTest extends AbstractIntegrationTestCase @@ -20,20 +18,26 @@ class AbstractIntegrationTest extends AbstractIntegrationTestCase public function testPopulatedLeadDataReturnsIntAndNotDncEntityForMauticContactIsContactableByEmail() { $integration = $this->getMockBuilder(AbstractIntegration::class) - ->disableOriginalConstructor() + ->setConstructorArgs([ + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $this->companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $this->integrationEntityModel, + ]) ->setMethodsExcept(['convertLeadFieldKey', 'getLeadDoNotContact', 'populateLeadData', 'setTranslator', 'setLeadModel']) ->getMock(); - $translator = $this->getMockBuilder(Translator::class) - ->disableOriginalConstructor() - ->getMock(); - $integration->setTranslator($translator); - - $leadModel = $this->getMockBuilder(LeadModel::class) - ->disableOriginalConstructor() - ->getMock(); - $integration->setLeadModel($leadModel); - $config = [ 'leadFields' => [ 'dnc' => 'mauticContactIsContactableByEmail', diff --git a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php index 6e35c829216..e19affd6fe4 100644 --- a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php +++ b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php @@ -25,7 +25,7 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\Routing\Router; -use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Component\Translation\TranslatorInterface; class AbstractIntegrationTestCase extends MauticMysqlTestCase { @@ -60,7 +60,7 @@ class AbstractIntegrationTestCase extends MauticMysqlTestCase protected $router; /** - * @var DataCollectorTranslator|\PHPUnit_Framework_MockObject_MockObject + * @var TranslatorInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $translator; @@ -114,7 +114,7 @@ protected function setUp() $this->session = $this->createMock(Session::class); $this->request = $this->createMock(RequestStack::class); $this->router = $this->createMock(Router::class); - $this->translator = $this->createMock(DataCollectorTranslator::class); + $this->translator = $this->createMock(TranslatorInterface::class); $this->logger = $this->createMock(Logger::class); $this->encryptionHelper = $this->createMock(EncryptionHelper::class); $this->leadModel = $this->createMock(LeadModel::class); From 76ed75a3ca9238a57d6d56ea833de8e8157ff2ab Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 15:55:07 +0100 Subject: [PATCH 43/56] Fix tests --- .../Tests/CrmAbstractIntegrationTest.php | 48 ++++++++------- .../ConnectwiseIntegrationTest.php | 30 ++++++--- .../Integration/SalesforceIntegrationTest.php | 18 +++--- .../Tests/ZohoIntegrationTest.php | 61 +++++++++---------- 4 files changed, 88 insertions(+), 69 deletions(-) diff --git a/plugins/MauticCrmBundle/Tests/CrmAbstractIntegrationTest.php b/plugins/MauticCrmBundle/Tests/CrmAbstractIntegrationTest.php index 91b9657e2ac..9feacd18ca7 100644 --- a/plugins/MauticCrmBundle/Tests/CrmAbstractIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/CrmAbstractIntegrationTest.php @@ -13,11 +13,10 @@ use Mautic\EmailBundle\Helper\EmailValidator; use Mautic\LeadBundle\Model\CompanyModel; -use Mautic\LeadBundle\Model\FieldModel; +use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Tests\Stubs\StubIntegration; -use Symfony\Component\HttpFoundation\Session\Session; -class CrmAbstractIntegrationTest extends \PHPUnit_Framework_TestCase +class CrmAbstractIntegrationTest extends AbstractIntegrationTestCase { public function testFieldMatchingPriority() { @@ -63,33 +62,18 @@ public function testFieldMatchingPriority() public function testCompanyDataIsMappedForNewCompanies() { - $integration = $this->getMockBuilder(StubIntegration::class) - ->disableOriginalConstructor() - ->setMethodsExcept(['getMauticCompany', 'setCompanyModel', 'setFieldModel', 'hydrateCompanyName']) - ->getMock(); - $data = [ 'custom_company_name' => 'Some Business', 'some_custom_field' => 'some value', ]; - $integration->expects($this->once()) - ->method('populateMauticLeadData') - ->willReturn($data); - - $fieldModel = $this->getMockBuilder(FieldModel::class) - ->disableOriginalConstructor() - ->getMock(); - $session = $this->getMockBuilder(Session::class) - ->disableOriginalConstructor() - ->getMock(); $emailValidator = $this->getMockBuilder(EmailValidator::class) ->disableOriginalConstructor() ->getMock(); $companyModel = $this->getMockBuilder(CompanyModel::class) ->setMethodsExcept(['setFieldValues']) - ->setConstructorArgs([$fieldModel, $session, $emailValidator]) + ->setConstructorArgs([$this->fieldModel, $this->session, $emailValidator]) ->getMock(); $companyModel->expects($this->once()) ->method('organizeFieldsByGroup') @@ -109,9 +93,31 @@ public function testCompanyDataIsMappedForNewCompanies() ], ], ]); - $integration->setCompanyModel($companyModel); - $integration->setFieldModel($fieldModel); + $integration = $this->getMockBuilder(StubIntegration::class) + ->setConstructorArgs([ + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $this->integrationEntityModel, + ]) + ->setMethodsExcept(['getMauticCompany', 'setCompanyModel', 'setFieldModel', 'hydrateCompanyName']) + ->getMock(); + + $integration->expects($this->once()) + ->method('populateMauticLeadData') + ->willReturn($data); $company = $integration->getMauticCompany($data); diff --git a/plugins/MauticCrmBundle/Tests/Integration/ConnectwiseIntegrationTest.php b/plugins/MauticCrmBundle/Tests/Integration/ConnectwiseIntegrationTest.php index eafac0d85cc..0aae44b81c3 100644 --- a/plugins/MauticCrmBundle/Tests/Integration/ConnectwiseIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/Integration/ConnectwiseIntegrationTest.php @@ -12,10 +12,11 @@ namespace MauticPlugin\MauticCrmBundle\Tests\Integration; use Mautic\PluginBundle\Model\IntegrationEntityModel; +use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Api\ConnectwiseApi; use MauticPlugin\MauticCrmBundle\Integration\ConnectwiseIntegration; -class ConnectwiseIntegrationTest extends \PHPUnit_Framework_TestCase +class ConnectwiseIntegrationTest extends AbstractIntegrationTestCase { use DataGeneratorTrait; @@ -75,8 +76,28 @@ function () { } ); - $integration = $this->getMockBuilder(ConnectwiseIntegration::class) + $integrationEntityModel = $this->getMockBuilder(IntegrationEntityModel::class) ->disableOriginalConstructor() + ->getMock(); + + $integration = $this->getMockBuilder(ConnectwiseIntegration::class) + ->setConstructorArgs([ + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $this->companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $integrationEntityModel, + ]) ->setMethodsExcept(['getCampaignMembers', 'getRecordList', 'setIntegrationEntityModel']) ->getMock(); @@ -88,11 +109,6 @@ function () { ->method('getApiHelper') ->willReturn($apiHelper); - $integrationEntityModel = $this->getMockBuilder(IntegrationEntityModel::class) - ->disableOriginalConstructor() - ->getMock(); - $integration->setIntegrationEntityModel($integrationEntityModel); - $integration->getCampaignMembers(1); } } diff --git a/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php b/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php index 03383998b38..17ed848b35b 100644 --- a/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php @@ -972,6 +972,13 @@ protected function getSalesforceIntegration($maxUpdate = 100, $maxCreate = 200, ] ); + $integrationEntityModelMock = $this->getMockBuilder(IntegrationEntityModel::class) + ->disableOriginalConstructor() + ->getMock(); + + $integrationEntityModelMock->method('getEntityByIdAndSetSyncDate') + ->willReturn(new IntegrationEntity()); + $sf = $this->getMockBuilder(SalesforceIntegration::class) ->setConstructorArgs([ $this->dispatcher, @@ -988,20 +995,11 @@ protected function getSalesforceIntegration($maxUpdate = 100, $maxCreate = 200, $this->pathsHelper, $this->notificationModel, $this->fieldModel, - $this->integrationEntityModel, + $integrationEntityModelMock, ]) ->setMethods($this->sfMockMethods) ->getMock(); - $integrationEntityModelMock = $this->getMockBuilder(IntegrationEntityModel::class) - ->disableOriginalConstructor() - ->getMock(); - - $integrationEntityModelMock->method('getEntityByIdAndSetSyncDate') - ->willReturn(new IntegrationEntity()); - - $sf->setIntegrationEntityModel($integrationEntityModelMock); - $sf->method('makeRequest') ->will( $this->returnCallback( diff --git a/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php b/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php index 1f64b0cb4d1..74c9552e318 100644 --- a/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php @@ -48,18 +48,42 @@ protected function setUp() $translator->expects($this->any()) ->method('trans') ->willReturnArgument(0); + + $eventMock = $this->getMockBuilder(Event::class) + ->disableOriginalConstructor() + ->setMethods(['getKeys']) + ->getMock(); + $apiKeys = [ + 'EMAIL_ID' => 'test', + 'PASSWORD' => 'test', + 'updateBlanks' => '', + 'datacenter' => 'zoho.com', + 'AUTHTOKEN' => 'test', + 'RESULT' => 'test', + ]; + $eventMock->expects($this->any()) + ->method('getKeys') + ->willReturn($apiKeys); + $dispatcherMock = $this->getMockBuilder(EventDispatcher::class) + ->disableOriginalConstructor() + ->setMethods(['dispatch']) + ->getMock(); + $dispatcherMock + ->method('dispatch') + ->willReturn($eventMock); + $this->integration = $this->getMockBuilder(ZohoIntegration::class) ->setMethods(['getApiHelper']) ->setConstructorArgs([ - $this->dispatcher, + $dispatcherMock, $this->cache, $this->em, $this->session, $this->request, $this->router, - $this->translator, + $translator, $this->logger, - $this->encryptionHelper, + $encryptionHelper, $this->leadModel, $this->companyModel, $this->pathsHelper, @@ -69,31 +93,6 @@ protected function setUp() ]) ->getMock(); - $this->integration->setTranslator($translator); - $this->integration->setEncryptionHelper($encryptionHelper); - $eventMock = $this->getMockBuilder(Event::class) - ->disableOriginalConstructor() - ->setMethods(['getKeys']) - ->getMock(); - $apiKeys = [ - 'EMAIL_ID' => 'test', - 'PASSWORD' => 'test', - 'updateBlanks' => '', - 'datacenter' => 'zoho.com', - 'AUTHTOKEN' => 'test', - 'RESULT' => 'test', - ]; - $eventMock->expects($this->any()) - ->method('getKeys') - ->willReturn($apiKeys); - $dispatcherMock = $this->getMockBuilder(EventDispatcher::class) - ->disableOriginalConstructor() - ->setMethods(['dispatch']) - ->getMock(); - $dispatcherMock->expects($this->any()) - ->method('dispatch') - ->willReturn($eventMock); - $this->integration->setDispatcher($dispatcherMock); $settings = new Integration(); $featureSettings = [ 'update_mautic' => [ @@ -141,9 +140,9 @@ protected function setUp() ->disableOriginalConstructor() ->setMethods(['getLeadFields']) ->getMock(); - $apiHelper->expects($this->any()) - ->method('getLeadFields') - ->willReturn($leadFields); + $apiHelper + ->method('getLeadFields') + ->willReturn($leadFields); $this->integration->method('getApiHelper') ->willReturn($apiHelper); $this->integration->setIntegrationSettings($settings); From a6fa4f87403aa4a5309953d3e3d5da4e62758113 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 16:49:00 +0100 Subject: [PATCH 44/56] Remove MauticFactory from dependencies --- app/bundles/PluginBundle/Config/config.php | 4 +++- .../Form/Type/IntegrationsListType.php | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/bundles/PluginBundle/Config/config.php b/app/bundles/PluginBundle/Config/config.php index 57bde343895..c1bcd44b779 100644 --- a/app/bundles/PluginBundle/Config/config.php +++ b/app/bundles/PluginBundle/Config/config.php @@ -122,7 +122,9 @@ ], 'mautic.form.type.integration.list' => [ 'class' => \Mautic\PluginBundle\Form\Type\IntegrationsListType::class, - 'arguments' => 'mautic.factory', + 'arguments' => [ + 'mautic.helper.integration', + ], ], 'mautic.form.type.integration.config' => [ 'class' => \Mautic\PluginBundle\Form\Type\IntegrationConfigType::class, diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php b/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php index 0f046623d87..db6a7f5068f 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php @@ -11,7 +11,7 @@ namespace Mautic\PluginBundle\Form\Type; -use Mautic\CoreBundle\Factory\MauticFactory; +use Mautic\PluginBundle\Helper\IntegrationHelper; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -27,13 +27,16 @@ class IntegrationsListType extends AbstractType { /** - * @var MauticFactory + * @var IntegrationHelper */ - private $factory; + private $integrationHelper; - public function __construct(MauticFactory $factory) + /** + * @param IntegrationHelper $integrationHelper + */ + public function __construct(IntegrationHelper $integrationHelper) { - $this->factory = $factory; + $this->integrationHelper = $integrationHelper; } /** @@ -41,9 +44,7 @@ public function __construct(MauticFactory $factory) */ public function buildForm(FormBuilderInterface $builder, array $options) { - /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */ - $integrationHelper = $this->factory->getHelper('integration'); - $integrationObjects = $integrationHelper->getIntegrationObjects(null, $options['supported_features'], true); + $integrationObjects = $this->integrationHelper->getIntegrationObjects(null, $options['supported_features'], true); $integrations = ['' => '']; foreach ($integrationObjects as $name => $object) { @@ -86,7 +87,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $campaignChoices = []; if (isset($data['integration'])) { - $integrationObject = $integrationHelper->getIntegrationObject($data['integration']); + $integrationObject = $this->integrationHelper->getIntegrationObject($data['integration']); if (method_exists($integrationObject, 'getCampaigns')) { $campaigns = $integrationObject->getCampaigns(); From b102df3473bc416d77d533ef45206a8d2cc4d2f9 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 3 Dec 2019 17:00:26 +0100 Subject: [PATCH 45/56] Fix attributes in PipedriveIntegration --- .../Integration/PipedriveIntegration.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php b/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php index df86cc1aa19..5a30b681f07 100644 --- a/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php +++ b/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php @@ -11,6 +11,7 @@ use Mautic\LeadBundle\Model\FieldModel; use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Model\IntegrationEntityModel; +use MauticPlugin\MauticCrmBundle\Api\CrmApi; use MauticPlugin\MauticCrmBundle\Integration\Pipedrive\Export\LeadExport; use MauticPlugin\MauticCrmBundle\Services\Transport; use Monolog\Logger; @@ -30,21 +31,26 @@ class PipedriveIntegration extends CrmAbstractIntegration const ORGANIZATION_ENTITY_TYPE = 'organization'; const COMPANY_ENTITY_TYPE = 'company'; - private $apiHelper; - - private $requiredFields = [ - 'person' => ['firstname', 'lastname', 'email'], - 'organization' => ['name'], - ]; /** * @var Transport */ private $transport; + /** * @var LeadExport */ private $leadExport; + /** + * @var CrmApi + */ + private $apiHelper; + + private $requiredFields = [ + 'person' => ['firstname', 'lastname', 'email'], + 'organization' => ['name'], + ]; + /** * @param EventDispatcherInterface $eventDispatcher * @param CacheStorageHelper $cacheStorageHelper From d8d5f61d2caca76d2436952c7b99562612461c66 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Wed, 4 Dec 2019 12:40:18 +0100 Subject: [PATCH 46/56] Remove MauticFactory from EventHelper --- .../PluginBundle/Helper/EventHelper.php | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/bundles/PluginBundle/Helper/EventHelper.php b/app/bundles/PluginBundle/Helper/EventHelper.php index e239ab07452..d6d70128475 100644 --- a/app/bundles/PluginBundle/Helper/EventHelper.php +++ b/app/bundles/PluginBundle/Helper/EventHelper.php @@ -11,7 +11,7 @@ namespace Mautic\PluginBundle\Helper; -use Mautic\CoreBundle\Factory\MauticFactory; +use Doctrine\ORM\EntityManager; use Mautic\PluginBundle\EventListener\PushToIntegrationTrait; /** @@ -22,20 +22,21 @@ class EventHelper use PushToIntegrationTrait; /** - * @param $lead - * @param MauticFactory $factory + * @param $config + * @param $lead + * @param EntityManager $em + * @param IntegrationHelper $integrationHelper + * + * @return bool */ - public static function pushLead($config, $lead, MauticFactory $factory) + public static function pushLead($config, $lead, EntityManager $em, IntegrationHelper $integrationHelper) { - $contact = $factory->getEntityManager()->getRepository('MauticLeadBundle:Lead')->getEntityWithPrimaryCompany($lead); - - /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */ - $integrationHelper = $factory->getHelper('integration'); + $contact = $em->getRepository('MauticLeadBundle:Lead')->getEntityWithPrimaryCompany($lead); static::setStaticIntegrationHelper($integrationHelper); + $errors = []; - $success = static::pushIt($config, $contact, $errors); - return $success; + return static::pushIt($config, $contact, $errors); } } From 73a02ed3b5659302efaa682a749daf6d05ec1471 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Wed, 4 Dec 2019 12:45:51 +0100 Subject: [PATCH 47/56] Remove MauticFactory from IntegrationHelper and fix docblocks --- .../PluginBundle/Helper/IntegrationHelper.php | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/app/bundles/PluginBundle/Helper/IntegrationHelper.php b/app/bundles/PluginBundle/Helper/IntegrationHelper.php index cdb564a0118..16b46201e60 100644 --- a/app/bundles/PluginBundle/Helper/IntegrationHelper.php +++ b/app/bundles/PluginBundle/Helper/IntegrationHelper.php @@ -12,7 +12,7 @@ namespace Mautic\PluginBundle\Helper; use Doctrine\ORM\EntityManager; -use Mautic\CoreBundle\Factory\MauticFactory; +use Exception; use Mautic\CoreBundle\Helper\BundleHelper; use Mautic\CoreBundle\Helper\CoreParametersHelper; use Mautic\CoreBundle\Helper\DateTimeHelper; @@ -66,13 +66,6 @@ class IntegrationHelper */ protected $pluginModel; - /** - * @deprecated 2.8.2 To be removed in 3.0 - * - * @var MauticFactory - */ - protected $factory; - private $integrations = []; private $available = []; @@ -82,8 +75,6 @@ class IntegrationHelper private $byPlugin = []; /** - * IntegrationHelper constructor. - * * @param Kernel $kernel * @param EntityManager $em * @param PathsHelper $pathsHelper @@ -91,9 +82,18 @@ class IntegrationHelper * @param CoreParametersHelper $coreParametersHelper * @param TemplatingHelper $templatingHelper * @param PluginModel $pluginModel + * + * @throws Exception */ - public function __construct(Kernel $kernel, EntityManager $em, PathsHelper $pathsHelper, BundleHelper $bundleHelper, CoreParametersHelper $coreParametersHelper, TemplatingHelper $templatingHelper, PluginModel $pluginModel) - { + public function __construct( + Kernel $kernel, + EntityManager $em, + PathsHelper $pathsHelper, + BundleHelper $bundleHelper, + CoreParametersHelper $coreParametersHelper, + TemplatingHelper $templatingHelper, + PluginModel $pluginModel + ) { $this->container = $kernel->getContainer(); $this->em = $em; $this->pathsHelper = $pathsHelper; @@ -101,7 +101,6 @@ public function __construct(Kernel $kernel, EntityManager $em, PathsHelper $path $this->pluginModel = $pluginModel; $this->coreParametersHelper = $coreParametersHelper; $this->templatingHelper = $templatingHelper; - $this->factory = $this->container->get('mautic.factory'); } /** @@ -114,6 +113,8 @@ public function __construct(Kernel $kernel, EntityManager $em, PathsHelper $path * @param bool|false $publishedOnly * * @return mixed + * + * @throws \Doctrine\ORM\ORMException */ public function getIntegrationObjects($specificIntegrations = null, $withFeatures = null, $alphabetical = false, $pluginFilter = null, $publishedOnly = false) { From 9ec701128674ba2f7c6f77b2c6cb598c29889ed9 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Wed, 4 Dec 2019 12:50:41 +0100 Subject: [PATCH 48/56] Remove MauticFactory from PushLeadActivityCommand --- .../PluginBundle/Command/PushLeadActivityCommand.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/bundles/PluginBundle/Command/PushLeadActivityCommand.php b/app/bundles/PluginBundle/Command/PushLeadActivityCommand.php index 6528e91f8fc..6b9208ee84d 100644 --- a/app/bundles/PluginBundle/Command/PushLeadActivityCommand.php +++ b/app/bundles/PluginBundle/Command/PushLeadActivityCommand.php @@ -11,6 +11,7 @@ namespace Mautic\PluginBundle\Command; +use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\PluginBundle\Integration\AbstractIntegration; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; @@ -67,10 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); - /** @var \Mautic\CoreBundle\Factory\MauticFactory $factory */ - $factory = $container->get('mautic.factory'); - - $translator = $factory->getTranslator(); + $translator = $container->get('translator'); $integration = $input->getOption('integration'); $startDate = $input->getOption('start-date'); $endDate = $input->getOption('end-date'); @@ -88,8 +86,8 @@ protected function execute(InputInterface $input, OutputInterface $output) } if ($integration && $startDate && $endDate) { - /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */ - $integrationHelper = $factory->getHelper('integration'); + /** @var IntegrationHelper $integrationHelper */ + $integrationHelper = $container->get('mautic.helper.integration'); /** @var AbstractIntegration $integrationObject */ $integrationObject = $integrationHelper->getIntegrationObject($integration); From 9d73f3d0f7fd4566fbe6e5b6d4f20240d65344f6 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Wed, 4 Dec 2019 13:10:23 +0100 Subject: [PATCH 49/56] Revert "Remove MauticFactory from EventHelper" This reverts commit d8d5f61d2caca76d2436952c7b99562612461c66. --- .../PluginBundle/Helper/EventHelper.php | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/bundles/PluginBundle/Helper/EventHelper.php b/app/bundles/PluginBundle/Helper/EventHelper.php index d6d70128475..e239ab07452 100644 --- a/app/bundles/PluginBundle/Helper/EventHelper.php +++ b/app/bundles/PluginBundle/Helper/EventHelper.php @@ -11,7 +11,7 @@ namespace Mautic\PluginBundle\Helper; -use Doctrine\ORM\EntityManager; +use Mautic\CoreBundle\Factory\MauticFactory; use Mautic\PluginBundle\EventListener\PushToIntegrationTrait; /** @@ -22,21 +22,20 @@ class EventHelper use PushToIntegrationTrait; /** - * @param $config - * @param $lead - * @param EntityManager $em - * @param IntegrationHelper $integrationHelper - * - * @return bool + * @param $lead + * @param MauticFactory $factory */ - public static function pushLead($config, $lead, EntityManager $em, IntegrationHelper $integrationHelper) + public static function pushLead($config, $lead, MauticFactory $factory) { - $contact = $em->getRepository('MauticLeadBundle:Lead')->getEntityWithPrimaryCompany($lead); + $contact = $factory->getEntityManager()->getRepository('MauticLeadBundle:Lead')->getEntityWithPrimaryCompany($lead); - static::setStaticIntegrationHelper($integrationHelper); + /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */ + $integrationHelper = $factory->getHelper('integration'); + static::setStaticIntegrationHelper($integrationHelper); $errors = []; + $success = static::pushIt($config, $contact, $errors); - return static::pushIt($config, $contact, $errors); + return $success; } } From ae18bb1d481787317c3f5c097c8d4ee93f175343 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Wed, 4 Dec 2019 14:47:29 +0100 Subject: [PATCH 50/56] Flip $mauticFields in FieldsTypeTrait --- app/bundles/PluginBundle/Config/config.php | 2 -- .../Form/Type/CompanyFieldsType.php | 13 +---------- .../PluginBundle/Form/Type/FieldsType.php | 13 +---------- .../Form/Type/FieldsTypeTrait.php | 23 ++++++++++++------- 4 files changed, 17 insertions(+), 34 deletions(-) diff --git a/app/bundles/PluginBundle/Config/config.php b/app/bundles/PluginBundle/Config/config.php index c1bcd44b779..6f721d4b048 100644 --- a/app/bundles/PluginBundle/Config/config.php +++ b/app/bundles/PluginBundle/Config/config.php @@ -111,11 +111,9 @@ ], 'mautic.form.type.integration.fields' => [ 'class' => \Mautic\PluginBundle\Form\Type\FieldsType::class, - 'arguments' => 'translator', ], 'mautic.form.type.integration.company.fields' => [ 'class' => \Mautic\PluginBundle\Form\Type\CompanyFieldsType::class, - 'arguments' => 'translator', ], 'mautic.form.type.integration.keys' => [ 'class' => \Mautic\PluginBundle\Form\Type\KeysType::class, diff --git a/app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php b/app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php index 2ef671f30ed..95b12c758f6 100644 --- a/app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php +++ b/app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php @@ -16,7 +16,6 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\Translation\TranslatorInterface; /** * Class SocialMediaServiceType. @@ -25,23 +24,13 @@ class CompanyFieldsType extends AbstractType { use FieldsTypeTrait; - private $translator; - - /** - * @param TranslatorInterface $translator - */ - public function __construct(TranslatorInterface $translator) - { - $this->translator = $translator; - } - /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { - $this->buildFormFields($builder, $options, $options['integration_fields'], $options['mautic_fields'], 'company', $options['limit'], $options['start'], $this->translator); + $this->buildFormFields($builder, $options, $options['integration_fields'], $options['mautic_fields'], 'company', $options['limit'], $options['start']); } /** diff --git a/app/bundles/PluginBundle/Form/Type/FieldsType.php b/app/bundles/PluginBundle/Form/Type/FieldsType.php index 90b871bb3fa..32b516d10fd 100644 --- a/app/bundles/PluginBundle/Form/Type/FieldsType.php +++ b/app/bundles/PluginBundle/Form/Type/FieldsType.php @@ -16,7 +16,6 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\Translation\TranslatorInterface; /** * Class FieldsType. @@ -25,23 +24,13 @@ class FieldsType extends AbstractType { use FieldsTypeTrait; - private $translator; - - /** - * @param TranslatorInterface $translator - */ - public function __construct(TranslatorInterface $translator) - { - $this->translator = $translator; - } - /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { - $this->buildFormFields($builder, $options, $options['integration_fields'], $options['mautic_fields'], '', $options['limit'], $options['start'], $this->translator); + $this->buildFormFields($builder, $options, $options['integration_fields'], $options['mautic_fields'], '', $options['limit'], $options['start']); } /** diff --git a/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php b/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php index 2f06e50c6cf..15063f6035e 100644 --- a/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php +++ b/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php @@ -21,7 +21,6 @@ use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\Translation\TranslatorInterface; trait FieldsTypeTrait { @@ -31,6 +30,8 @@ trait FieldsTypeTrait * @param array $integrationFields * @param array $mauticFields * @param string $fieldObject + * @param $limit + * @param $start */ protected function buildFormFields( FormBuilderInterface $builder, @@ -39,12 +40,11 @@ protected function buildFormFields( array $mauticFields, $fieldObject, $limit, - $start, - TranslatorInterface $translator + $start ) { $builder->addEventListener( FormEvents::PRE_SET_DATA, - function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $fieldObject, $limit, $start, $translator) { + function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $fieldObject, $limit, $start) { $form = $event->getForm(); $index = 0; $choices = []; @@ -52,6 +52,13 @@ function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $f $optionalFields = []; $group = []; $fieldData = $event->getData(); + + foreach ($mauticFields as $key => $value) { + if (is_array($mauticFields)) { + $mauticFields[$key] = array_flip($value); + } + } + // First loop to build options foreach ($integrationFields as $field => $details) { $groupName = '0default'; @@ -187,11 +194,11 @@ function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $f ] ); } + if (!$fieldObject) { - $contactId['mauticContactId'] = $this->translator->trans('mautic.lead.report.contact_id'); - $contactLink['mauticContactTimelineLink'] = $this->translator->trans('mautic.plugin.integration.contact.timeline.link'); - $isContactable['mauticContactIsContactableByEmail'] = $this->translator->trans('mautic.plugin.integration.contact.donotcontact.email'); - $mauticFields = array_merge($mauticFields, $contactLink, $isContactable, $contactId); + $mauticFields['mautic.lead.report.contact_id'] = 'mauticContactId'; + $mauticFields['mautic.plugin.integration.contact.timeline.link'] = 'mauticContactTimelineLink'; + $mauticFields['mautic.plugin.integration.contact.donotcontact.email'] = 'mauticContactIsContactableByEmail'; } $form->add( From 2ddb00c23e7399ad3612c9a7a7ed63390626cefc Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 6 Dec 2019 14:23:46 +0100 Subject: [PATCH 51/56] Remove unused methods from AjaxController --- .../Controller/AjaxController.php | 221 +----------------- 1 file changed, 1 insertion(+), 220 deletions(-) diff --git a/app/bundles/PluginBundle/Controller/AjaxController.php b/app/bundles/PluginBundle/Controller/AjaxController.php index 5bc5e625f43..6c59c29b972 100644 --- a/app/bundles/PluginBundle/Controller/AjaxController.php +++ b/app/bundles/PluginBundle/Controller/AjaxController.php @@ -13,11 +13,6 @@ use Mautic\CoreBundle\Controller\AjaxController as CommonAjaxController; use Mautic\CoreBundle\Helper\InputHelper; -use Mautic\PluginBundle\Form\Type\CompanyFieldsType; -use Mautic\PluginBundle\Form\Type\FieldsType; -use Mautic\PluginBundle\Form\Type\IntegrationCampaignsType; -use Mautic\PluginBundle\Form\Type\IntegrationConfigType; -use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\HttpFoundation\Request; /** @@ -40,225 +35,11 @@ protected function setIntegrationFilterAction(Request $request) } /** - * Get the HTML for list of fields. - * * @param Request $request * * @return \Symfony\Component\HttpFoundation\JsonResponse - */ - protected function getIntegrationFieldsAction(Request $request) - { - $integration = $request->request->get('integration'); - $settings = $request->request->get('settings'); - $page = $request->request->get('page'); - - $dataArray = ['success' => 0]; - - if (!empty($integration) && !empty($settings)) { - /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $helper */ - $helper = $this->get('mautic.helper.integration'); - /** @var \Mautic\PluginBundle\Integration\AbstractIntegration $integrationObject */ - $integrationObject = $helper->getIntegrationObject($integration); - - if ($integrationObject) { - if (!$object = $request->attributes->get('object')) { - $object = (isset($settings['object'])) ? $settings['object'] : 'lead'; - } - - $isLead = ('lead' === $object); - $integrationFields = ($isLead) - ? $integrationObject->getFormLeadFields($settings) - : $integrationObject->getFormCompanyFields( - $settings - ); - - if (!empty($integrationFields)) { - $session = $this->get('session'); - $session->set('mautic.plugin.'.$integration.'.'.$object.'.page', $page); - - /** @var PluginModel $pluginModel */ - $pluginModel = $this->getModel('plugin'); - - // Get a list of custom form fields - $mauticFields = ($isLead) ? $pluginModel->getLeadFields() : $pluginModel->getCompanyFields(); - $featureSettings = $integrationObject->getIntegrationSettings()->getFeatureSettings(); - $enableDataPriority = $integrationObject->getDataPriority(); - $formType = $isLead ? FieldsType::class : CompanyFieldsType::class; - $form = $this->createForm( - $formType, - isset($featureSettings[$object.'Fields']) ? $featureSettings[$object.'Fields'] : [], - [ - 'mautic_fields' => $mauticFields, - 'data' => $featureSettings, - 'integration_fields' => $integrationFields, - 'csrf_protection' => false, - 'integration_object' => $integrationObject, - 'enable_data_priority' => $enableDataPriority, - 'integration' => $integration, - 'page' => $page, - 'limit' => $this->get('mautic.helper.core_parameters')->getParameter('default_pagelimit'), - ] - ); - - $html = $this->render( - 'MauticCoreBundle:Helper:blank_form.html.php', - [ - 'form' => $this->setFormTheme( - $form, - 'MauticCoreBundle:Helper:blank_form.html.php', - 'MauticPluginBundle:FormTheme\Integration' - ), - 'function' => 'row', - ] - )->getContent(); - - if (!isset($settings['prefix'])) { - $prefix = 'integration_details[featureSettings]['.$object.'Fields]'; - } else { - $prefix = $settings['prefix']; - } - - $idPrefix = str_replace(['][', '[', ']'], '_', $prefix); - if (substr($idPrefix, -1) == '_') { - $idPrefix = substr($idPrefix, 0, -1); - } - - $html = preg_replace('/'.$formType.'\[(.*?)\]/', $prefix.'[$1]', $html); - $html = str_replace($formType, $idPrefix, $html); - $dataArray['success'] = 1; - $dataArray['html'] = $html; - } - } - } - - return $this->sendJsonResponse($dataArray); - } - - /** - * Get the HTML for integration properties. - * - * @param Request $request - * - * @return \Symfony\Component\HttpFoundation\JsonResponse - */ - protected function getIntegrationConfigAction(Request $request) - { - $integration = $request->request->get('integration'); - $settings = $request->request->get('settings'); - $dataArray = ['success' => 0]; - - if (!empty($integration) && !empty($settings)) { - /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $helper */ - $helper = $this->factory->getHelper('integration'); - /** @var \Mautic\PluginBundle\Integration\AbstractIntegration $object */ - $object = $helper->getIntegrationObject($integration); - - if ($object) { - $data = $statusData = []; - $objectSettings = $object->getIntegrationSettings(); - $defaults = $objectSettings->getFeatureSettings(); - if (method_exists($object, 'getCampaigns')) { - $campaigns = $object->getCampaigns(); - if (isset($campaigns['records']) && !empty($campaigns['records'])) { - foreach ($campaigns['records'] as $campaign) { - $data[$campaign['Id']] = $campaign['Name']; - } - } - } - $form = $this->createForm(IntegrationConfigType::class, $defaults, [ - 'integration' => $object, - 'csrf_protection' => false, - 'campaigns' => $data, - ]); - - $form = $this->setFormTheme($form, 'MauticCoreBundle:Helper:blank_form.html.php', 'MauticPluginBundle:FormTheme\Integration'); - - $html = $this->render('MauticCoreBundle:Helper:blank_form.html.php', [ - 'form' => $form, - 'function' => 'widget', - 'variables' => [ - 'integration' => $object, - ], - ])->getContent(); - - $prefix = str_replace('[integration]', '[config]', $settings['name']); - $idPrefix = str_replace(['][', '[', ']'], '_', $prefix); - if (substr($idPrefix, -1) == '_') { - $idPrefix = substr($idPrefix, 0, -1); - } - - $html = preg_replace('/integration_config\[(.*?)\]/', $prefix.'[$1]', $html); - $html = str_replace('integration_config', $idPrefix, $html); - - $dataArray['success'] = 1; - $dataArray['html'] = $html; - } - } - - return $this->sendJsonResponse($dataArray); - } - - protected function getIntegrationCampaignStatusAction(Request $request) - { - $integration = $request->request->get('integration'); - $campaign = $request->request->get('campaign'); - $settings = $request->request->get('settings'); - $dataArray = ['success' => 0]; - $statusData = []; - if (!empty($integration) && !empty($campaign)) { - /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $helper */ - $helper = $this->factory->getHelper('integration'); - /** @var \Mautic\PluginBundle\Integration\AbstractIntegration $object */ - $object = $helper->getIntegrationObject($integration); - - if ($object) { - if (method_exists($object, 'getCampaignMemberStatus')) { - $campaignMemberStatus = $object->getCampaignMemberStatus($campaign); - if (isset($campaignMemberStatus['records']) && !empty($campaignMemberStatus['records'])) { - foreach ($campaignMemberStatus['records'] as $status) { - $statusData[$status['Label']] = $status['Label']; - } - } - } - $form = $this->createForm(IntegrationCampaignsType::class, $statusData, [ - 'csrf_protection' => false, - 'campaignContactStatus' => $statusData, - ]); - - $form = $this->setFormTheme($form, 'MauticCoreBundle:Helper:blank_form.html.php', 'MauticPluginBundle:FormTheme\Integration'); - - $html = $this->render('MauticCoreBundle:Helper:blank_form.html.php', [ - 'form' => $form, - 'function' => 'widget', - 'variables' => [ - 'integration' => $object, - ], - ])->getContent(); - - $prefix = str_replace('[integration]', '[campaign_member_status][campaign_member_status]', $settings['name']); - - $idPrefix = str_replace(['][', '[', ']'], '_', $prefix); - - if (substr($idPrefix, -1) == '_') { - $idPrefix = substr($idPrefix, 0, -1); - } - - $html = preg_replace('/integration_campaign_status_campaign_member_status\[(.*?)\]/', $prefix.'[$1]', $html); - $html = str_replace('integration_campaign_status_campaign_member_status', $idPrefix, $html); - $html = str_replace('integration_campaign_status[campaign_member_status]', $prefix, $html); - - $dataArray['success'] = 1; - $dataArray['html'] = $html; - } - } - - return $this->sendJsonResponse($dataArray); - } - - /** - * @param Request $request * - * @return \Symfony\Component\HttpFoundation\JsonResponse + * @throws \Exception */ protected function getIntegrationCampaignsAction(Request $request) { From e5055aacd3eaf21383a978b3ef1ed95618f85021 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Fri, 6 Dec 2019 14:42:45 +0100 Subject: [PATCH 52/56] Revert "Remove unused methods from AjaxController" This reverts commit 2ddb00c23e7399ad3612c9a7a7ed63390626cefc. --- .../Controller/AjaxController.php | 221 +++++++++++++++++- 1 file changed, 220 insertions(+), 1 deletion(-) diff --git a/app/bundles/PluginBundle/Controller/AjaxController.php b/app/bundles/PluginBundle/Controller/AjaxController.php index 6c59c29b972..5bc5e625f43 100644 --- a/app/bundles/PluginBundle/Controller/AjaxController.php +++ b/app/bundles/PluginBundle/Controller/AjaxController.php @@ -13,6 +13,11 @@ use Mautic\CoreBundle\Controller\AjaxController as CommonAjaxController; use Mautic\CoreBundle\Helper\InputHelper; +use Mautic\PluginBundle\Form\Type\CompanyFieldsType; +use Mautic\PluginBundle\Form\Type\FieldsType; +use Mautic\PluginBundle\Form\Type\IntegrationCampaignsType; +use Mautic\PluginBundle\Form\Type\IntegrationConfigType; +use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\HttpFoundation\Request; /** @@ -35,11 +40,225 @@ protected function setIntegrationFilterAction(Request $request) } /** + * Get the HTML for list of fields. + * * @param Request $request * * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + protected function getIntegrationFieldsAction(Request $request) + { + $integration = $request->request->get('integration'); + $settings = $request->request->get('settings'); + $page = $request->request->get('page'); + + $dataArray = ['success' => 0]; + + if (!empty($integration) && !empty($settings)) { + /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $helper */ + $helper = $this->get('mautic.helper.integration'); + /** @var \Mautic\PluginBundle\Integration\AbstractIntegration $integrationObject */ + $integrationObject = $helper->getIntegrationObject($integration); + + if ($integrationObject) { + if (!$object = $request->attributes->get('object')) { + $object = (isset($settings['object'])) ? $settings['object'] : 'lead'; + } + + $isLead = ('lead' === $object); + $integrationFields = ($isLead) + ? $integrationObject->getFormLeadFields($settings) + : $integrationObject->getFormCompanyFields( + $settings + ); + + if (!empty($integrationFields)) { + $session = $this->get('session'); + $session->set('mautic.plugin.'.$integration.'.'.$object.'.page', $page); + + /** @var PluginModel $pluginModel */ + $pluginModel = $this->getModel('plugin'); + + // Get a list of custom form fields + $mauticFields = ($isLead) ? $pluginModel->getLeadFields() : $pluginModel->getCompanyFields(); + $featureSettings = $integrationObject->getIntegrationSettings()->getFeatureSettings(); + $enableDataPriority = $integrationObject->getDataPriority(); + $formType = $isLead ? FieldsType::class : CompanyFieldsType::class; + $form = $this->createForm( + $formType, + isset($featureSettings[$object.'Fields']) ? $featureSettings[$object.'Fields'] : [], + [ + 'mautic_fields' => $mauticFields, + 'data' => $featureSettings, + 'integration_fields' => $integrationFields, + 'csrf_protection' => false, + 'integration_object' => $integrationObject, + 'enable_data_priority' => $enableDataPriority, + 'integration' => $integration, + 'page' => $page, + 'limit' => $this->get('mautic.helper.core_parameters')->getParameter('default_pagelimit'), + ] + ); + + $html = $this->render( + 'MauticCoreBundle:Helper:blank_form.html.php', + [ + 'form' => $this->setFormTheme( + $form, + 'MauticCoreBundle:Helper:blank_form.html.php', + 'MauticPluginBundle:FormTheme\Integration' + ), + 'function' => 'row', + ] + )->getContent(); + + if (!isset($settings['prefix'])) { + $prefix = 'integration_details[featureSettings]['.$object.'Fields]'; + } else { + $prefix = $settings['prefix']; + } + + $idPrefix = str_replace(['][', '[', ']'], '_', $prefix); + if (substr($idPrefix, -1) == '_') { + $idPrefix = substr($idPrefix, 0, -1); + } + + $html = preg_replace('/'.$formType.'\[(.*?)\]/', $prefix.'[$1]', $html); + $html = str_replace($formType, $idPrefix, $html); + $dataArray['success'] = 1; + $dataArray['html'] = $html; + } + } + } + + return $this->sendJsonResponse($dataArray); + } + + /** + * Get the HTML for integration properties. + * + * @param Request $request + * + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + protected function getIntegrationConfigAction(Request $request) + { + $integration = $request->request->get('integration'); + $settings = $request->request->get('settings'); + $dataArray = ['success' => 0]; + + if (!empty($integration) && !empty($settings)) { + /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $helper */ + $helper = $this->factory->getHelper('integration'); + /** @var \Mautic\PluginBundle\Integration\AbstractIntegration $object */ + $object = $helper->getIntegrationObject($integration); + + if ($object) { + $data = $statusData = []; + $objectSettings = $object->getIntegrationSettings(); + $defaults = $objectSettings->getFeatureSettings(); + if (method_exists($object, 'getCampaigns')) { + $campaigns = $object->getCampaigns(); + if (isset($campaigns['records']) && !empty($campaigns['records'])) { + foreach ($campaigns['records'] as $campaign) { + $data[$campaign['Id']] = $campaign['Name']; + } + } + } + $form = $this->createForm(IntegrationConfigType::class, $defaults, [ + 'integration' => $object, + 'csrf_protection' => false, + 'campaigns' => $data, + ]); + + $form = $this->setFormTheme($form, 'MauticCoreBundle:Helper:blank_form.html.php', 'MauticPluginBundle:FormTheme\Integration'); + + $html = $this->render('MauticCoreBundle:Helper:blank_form.html.php', [ + 'form' => $form, + 'function' => 'widget', + 'variables' => [ + 'integration' => $object, + ], + ])->getContent(); + + $prefix = str_replace('[integration]', '[config]', $settings['name']); + $idPrefix = str_replace(['][', '[', ']'], '_', $prefix); + if (substr($idPrefix, -1) == '_') { + $idPrefix = substr($idPrefix, 0, -1); + } + + $html = preg_replace('/integration_config\[(.*?)\]/', $prefix.'[$1]', $html); + $html = str_replace('integration_config', $idPrefix, $html); + + $dataArray['success'] = 1; + $dataArray['html'] = $html; + } + } + + return $this->sendJsonResponse($dataArray); + } + + protected function getIntegrationCampaignStatusAction(Request $request) + { + $integration = $request->request->get('integration'); + $campaign = $request->request->get('campaign'); + $settings = $request->request->get('settings'); + $dataArray = ['success' => 0]; + $statusData = []; + if (!empty($integration) && !empty($campaign)) { + /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $helper */ + $helper = $this->factory->getHelper('integration'); + /** @var \Mautic\PluginBundle\Integration\AbstractIntegration $object */ + $object = $helper->getIntegrationObject($integration); + + if ($object) { + if (method_exists($object, 'getCampaignMemberStatus')) { + $campaignMemberStatus = $object->getCampaignMemberStatus($campaign); + if (isset($campaignMemberStatus['records']) && !empty($campaignMemberStatus['records'])) { + foreach ($campaignMemberStatus['records'] as $status) { + $statusData[$status['Label']] = $status['Label']; + } + } + } + $form = $this->createForm(IntegrationCampaignsType::class, $statusData, [ + 'csrf_protection' => false, + 'campaignContactStatus' => $statusData, + ]); + + $form = $this->setFormTheme($form, 'MauticCoreBundle:Helper:blank_form.html.php', 'MauticPluginBundle:FormTheme\Integration'); + + $html = $this->render('MauticCoreBundle:Helper:blank_form.html.php', [ + 'form' => $form, + 'function' => 'widget', + 'variables' => [ + 'integration' => $object, + ], + ])->getContent(); + + $prefix = str_replace('[integration]', '[campaign_member_status][campaign_member_status]', $settings['name']); + + $idPrefix = str_replace(['][', '[', ']'], '_', $prefix); + + if (substr($idPrefix, -1) == '_') { + $idPrefix = substr($idPrefix, 0, -1); + } + + $html = preg_replace('/integration_campaign_status_campaign_member_status\[(.*?)\]/', $prefix.'[$1]', $html); + $html = str_replace('integration_campaign_status_campaign_member_status', $idPrefix, $html); + $html = str_replace('integration_campaign_status[campaign_member_status]', $prefix, $html); + + $dataArray['success'] = 1; + $dataArray['html'] = $html; + } + } + + return $this->sendJsonResponse($dataArray); + } + + /** + * @param Request $request * - * @throws \Exception + * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function getIntegrationCampaignsAction(Request $request) { From 096322ee7569de7a110b27162c1f6849528ed1f0 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Mon, 9 Dec 2019 16:59:52 +0100 Subject: [PATCH 53/56] Fix class import and docblock --- app/bundles/PluginBundle/Helper/IntegrationHelper.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/bundles/PluginBundle/Helper/IntegrationHelper.php b/app/bundles/PluginBundle/Helper/IntegrationHelper.php index 16b46201e60..42c6d62e8b5 100644 --- a/app/bundles/PluginBundle/Helper/IntegrationHelper.php +++ b/app/bundles/PluginBundle/Helper/IntegrationHelper.php @@ -12,7 +12,6 @@ namespace Mautic\PluginBundle\Helper; use Doctrine\ORM\EntityManager; -use Exception; use Mautic\CoreBundle\Helper\BundleHelper; use Mautic\CoreBundle\Helper\CoreParametersHelper; use Mautic\CoreBundle\Helper\DateTimeHelper; @@ -83,7 +82,7 @@ class IntegrationHelper * @param TemplatingHelper $templatingHelper * @param PluginModel $pluginModel * - * @throws Exception + * @throws \Exception */ public function __construct( Kernel $kernel, From a07e240c2a1d9d98d9899b0599fa53499e40f8a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Drah=C3=BD?= Date: Tue, 10 Dec 2019 12:07:16 +0100 Subject: [PATCH 54/56] Update plugins/MauticSocialBundle/Integration/SocialIntegration.php Co-Authored-By: John Linhart --- plugins/MauticSocialBundle/Integration/SocialIntegration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/MauticSocialBundle/Integration/SocialIntegration.php b/plugins/MauticSocialBundle/Integration/SocialIntegration.php index 9c14b41fb78..3dee03c1552 100644 --- a/plugins/MauticSocialBundle/Integration/SocialIntegration.php +++ b/plugins/MauticSocialBundle/Integration/SocialIntegration.php @@ -64,7 +64,7 @@ public function __construct( Session $session, RequestStack $requestStack, Router $router, - DataCollectorTranslator $translator, + TranslatorInterface $translator, Logger $logger, EncryptionHelper $encryptionHelper, LeadModel $leadModel, From bee11c554e6406386bd1127dcaa43a59bdf9bfea Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 10 Dec 2019 12:08:37 +0100 Subject: [PATCH 55/56] Fix interface requirements in constructor --- plugins/MauticSocialBundle/Integration/SocialIntegration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/MauticSocialBundle/Integration/SocialIntegration.php b/plugins/MauticSocialBundle/Integration/SocialIntegration.php index 3dee03c1552..3152b61d0b0 100644 --- a/plugins/MauticSocialBundle/Integration/SocialIntegration.php +++ b/plugins/MauticSocialBundle/Integration/SocialIntegration.php @@ -28,7 +28,7 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\Routing\Router; -use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Component\Translation\TranslatorInterface; abstract class SocialIntegration extends AbstractIntegration { @@ -46,7 +46,7 @@ abstract class SocialIntegration extends AbstractIntegration * @param Session $session * @param RequestStack $requestStack * @param Router $router - * @param DataCollectorTranslator $translator + * @param TranslatorInterface $translator * @param Logger $logger * @param EncryptionHelper $encryptionHelper * @param LeadModel $leadModel From 8cee6eaeeea64de868a1f17b8cb3d6ce9af64652 Mon Sep 17 00:00:00 2001 From: Lukas Drahy Date: Tue, 10 Dec 2019 13:13:14 +0100 Subject: [PATCH 56/56] Fix interface requirements in constructor --- plugins/MauticCrmBundle/Integration/HubspotIntegration.php | 6 +++--- .../MauticCrmBundle/Integration/PipedriveIntegration.php | 6 +++--- plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/MauticCrmBundle/Integration/HubspotIntegration.php b/plugins/MauticCrmBundle/Integration/HubspotIntegration.php index 6f2eac0c47d..85d2aee94d5 100644 --- a/plugins/MauticCrmBundle/Integration/HubspotIntegration.php +++ b/plugins/MauticCrmBundle/Integration/HubspotIntegration.php @@ -34,7 +34,7 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\Routing\Router; -use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Component\Translation\TranslatorInterface; /** * Class HubspotIntegration. @@ -57,7 +57,7 @@ class HubspotIntegration extends CrmAbstractIntegration * @param Session $session * @param RequestStack $requestStack * @param Router $router - * @param DataCollectorTranslator $translator + * @param TranslatorInterface $translator * @param Logger $logger * @param EncryptionHelper $encryptionHelper * @param LeadModel $leadModel @@ -75,7 +75,7 @@ public function __construct( Session $session, RequestStack $requestStack, Router $router, - DataCollectorTranslator $translator, + TranslatorInterface $translator, Logger $logger, EncryptionHelper $encryptionHelper, LeadModel $leadModel, diff --git a/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php b/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php index 5a30b681f07..e620824e5dc 100644 --- a/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php +++ b/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php @@ -21,7 +21,7 @@ use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Router; -use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Component\Translation\TranslatorInterface; class PipedriveIntegration extends CrmAbstractIntegration { @@ -58,7 +58,7 @@ class PipedriveIntegration extends CrmAbstractIntegration * @param Session $session * @param RequestStack $requestStack * @param Router $router - * @param DataCollectorTranslator $translator + * @param TranslatorInterface $translator * @param Logger $logger * @param EncryptionHelper $encryptionHelper * @param LeadModel $leadModel @@ -77,7 +77,7 @@ public function __construct( Session $session, RequestStack $requestStack, Router $router, - DataCollectorTranslator $translator, + TranslatorInterface $translator, Logger $logger, EncryptionHelper $encryptionHelper, LeadModel $leadModel, diff --git a/plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php b/plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php index a56a31b684c..2b193078bd4 100644 --- a/plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php +++ b/plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php @@ -35,7 +35,7 @@ use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Router; -use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Validator\Constraints\NotBlank; /** @@ -66,7 +66,7 @@ class SugarcrmIntegration extends CrmAbstractIntegration * @param Session $session * @param RequestStack $requestStack * @param Router $router - * @param DataCollectorTranslator $translator + * @param TranslatorInterface $translator * @param Logger $logger * @param EncryptionHelper $encryptionHelper * @param LeadModel $leadModel @@ -84,7 +84,7 @@ public function __construct( Session $session, RequestStack $requestStack, Router $router, - DataCollectorTranslator $translator, + TranslatorInterface $translator, Logger $logger, EncryptionHelper $encryptionHelper, LeadModel $leadModel,