From 728bdd296ec4b93f4fa1844994b6f11d0113f84d Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 23 Jul 2019 18:43:23 +0200 Subject: [PATCH 01/17] Fix code review feedback. --- plugins/MauticCitrixBundle/Controller/PublicController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/MauticCitrixBundle/Controller/PublicController.php b/plugins/MauticCitrixBundle/Controller/PublicController.php index 7e8c260a662..9b925d3480e 100644 --- a/plugins/MauticCitrixBundle/Controller/PublicController.php +++ b/plugins/MauticCitrixBundle/Controller/PublicController.php @@ -44,7 +44,7 @@ public function proxyAction(Request $request) } $ch = curl_init($url); - if ('post' === strtolower($request->server->get('REQUEST_METHOD', ''))) { + if (Request::METHOD_POST === $request->getMethod()) { $headers = [ 'Content-type: application/json', 'Accept: application/json', @@ -71,8 +71,7 @@ public function proxyAction(Request $request) $response = new Response($json, $status['http_code']); // Generate appropriate content-type header. - $is_xhr = 'xmlhttprequest' === strtolower($request->server->get('HTTP_X_REQUESTED_WITH', null)); - $response->headers->set('Content-type', 'application/'.($is_xhr ? 'json' : 'x-javascript')); + $response->headers->set('Content-type', 'application/'.($request->isXmlHttpRequest() ? 'json' : 'x-javascript')); // Allow CORS requests only from dev machines $allowedIps = $this->coreParametersHelper->get('dev_hosts') ?: []; From 74e4216dc351f09f2dddf0fb0acfee4138c66e99 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 23 Jul 2019 18:45:00 +0200 Subject: [PATCH 02/17] There is no need to specify empty arguments. --- plugins/MauticCitrixBundle/Config/config.php | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/MauticCitrixBundle/Config/config.php b/plugins/MauticCitrixBundle/Config/config.php index e10e571cd4d..7094da187af 100644 --- a/plugins/MauticCitrixBundle/Config/config.php +++ b/plugins/MauticCitrixBundle/Config/config.php @@ -78,7 +78,6 @@ ], 'mautic.citrix.integration.request' => [ 'class' => \MauticPlugin\MauticCitrixBundle\EventListener\IntegrationRequestSubscriber::class, - 'arguments' => [], ], ], 'forms' => [ From e2e1f5fe64fb3c0082d12fa8976f0ac5731b1917 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 23 Jul 2019 21:01:26 +0200 Subject: [PATCH 03/17] Commit WIP. --- .../IntegrationRequestSubscriberTest.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php diff --git a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php new file mode 100644 index 00000000000..1e21840d737 --- /dev/null +++ b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php @@ -0,0 +1,54 @@ +assertSame(IntegrationRequestSubscriber::getSubscribedEvents(), [ + PluginEvents::PLUGIN_ON_INTEGRATION_REQUEST => [ + 'getParameters', + 0, + ], + ]); + } + + public function testGetParametersMethod() + { + $event = $this->getMockBuilder(PluginIntegrationRequestEvent::class) + ->disableOriginalConstructor() + ->setMethodsExcept(['setHeaders']) + ->getMock(); + + $event + ->method('getUrl') + ->willReturn('\'oauth/v2/token\''); + + $event + ->method('getParameters') + ->will($this->onConsecutiveCalls([], [], [], [])); + + $subscriber = $this->getMockBuilder(IntegrationRequestSubscriber::class) + ->disableOriginalConstructor() + ->setMethodsExcept(['getParameters', 'getAuthorization']) + ->getMock(); + } +} From cc5348ac8a33806a20b5a17487b51f58a46fc1b3 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 24 Jul 2019 13:25:10 +0200 Subject: [PATCH 04/17] Refactoring: there no need to use both isset and empty. Empty is more than enough in this particular case. 2. Remove weird exception codes. --- .../EventListener/IntegrationRequestSubscriber.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/MauticCitrixBundle/EventListener/IntegrationRequestSubscriber.php b/plugins/MauticCitrixBundle/EventListener/IntegrationRequestSubscriber.php index cc4ec91004f..79380e596ea 100644 --- a/plugins/MauticCitrixBundle/EventListener/IntegrationRequestSubscriber.php +++ b/plugins/MauticCitrixBundle/EventListener/IntegrationRequestSubscriber.php @@ -51,12 +51,12 @@ public function getParameters(PluginIntegrationRequestEvent $requestEvent) */ private function getAuthorization(array $parameters) { - if (!isset($parameters['client_id']) || empty($parameters['client_id'])) { - throw new \Exception('No client ID given.', 1554211764); + if (empty($parameters['client_id'])) { + throw new \Exception('No client ID given.'); } - if (!isset($parameters['client_secret']) || empty($parameters['client_secret'])) { - throw new \Exception('No client secret given.', 1554211808); + if (empty($parameters['client_secret'])) { + throw new \Exception('No client secret given.'); } return sprintf('%s:%s', $parameters['client_id'], $parameters['client_secret']); From 42320a8b105f9752d059d7124a402baa2ea0bf24 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 24 Jul 2019 13:26:07 +0200 Subject: [PATCH 05/17] Implement test for IntegrationRequestSubscriber. --- .../IntegrationRequestSubscriberTest.php | 91 ++++++++++++++++--- 1 file changed, 76 insertions(+), 15 deletions(-) diff --git a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php index 1e21840d737..bb591d07333 100644 --- a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php +++ b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php @@ -12,12 +12,35 @@ namespace MauticPlugin\MauticCitrixBundle\Tests\EventListener; use Mautic\PluginBundle\Event\PluginIntegrationRequestEvent; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; use Mautic\PluginBundle\PluginEvents; use MauticPlugin\MauticCitrixBundle\EventListener\IntegrationRequestSubscriber; use PHPUnit_Framework_TestCase; class IntegrationRequestSubscriberTest extends PHPUnit_Framework_TestCase { + + /** @var PluginIntegrationRequestEvent */ + protected $event; + + /** @var IntegrationRequestSubscriber */ + protected $subscriber; + + protected function setUp() + { + $this->subscriber = $this->getMockBuilder(IntegrationRequestSubscriber::class) + ->disableOriginalConstructor() + ->setMethodsExcept(['getParameters', 'getAuthorization']) + ->getMock(); + + $integration = $this->getMockBuilder(UnifiedIntegrationInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->event = new PluginIntegrationRequestEvent($integration, '\'oauth/v2/token\'', null, null, null, null, null); + } + + /** * Tests getSubscribedEvents method. */ @@ -31,24 +54,62 @@ public function testGetSubscribedEventsMethod() ]); } - public function testGetParametersMethod() + public function testExceptionOnEmptyClientId() { - $event = $this->getMockBuilder(PluginIntegrationRequestEvent::class) - ->disableOriginalConstructor() - ->setMethodsExcept(['setHeaders']) - ->getMock(); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No client ID given.'); - $event - ->method('getUrl') - ->willReturn('\'oauth/v2/token\''); + $this->event->setParameters([ + 'client_secret' => 'abc', + ]); - $event - ->method('getParameters') - ->will($this->onConsecutiveCalls([], [], [], [])); + $this->subscriber->getParameters($this->event); + } - $subscriber = $this->getMockBuilder(IntegrationRequestSubscriber::class) - ->disableOriginalConstructor() - ->setMethodsExcept(['getParameters', 'getAuthorization']) - ->getMock(); + public function testExceptionOnEmptyClientSecret() + { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No client secret given.'); + + $this->event->setParameters([ + 'client_id' => 'abc', + ]); + + $this->subscriber->getParameters($this->event); + } + + public function testExceptionOnEmptyParameters() + { + $this->expectException(\Exception::class); + + $this->event->setParameters([]); + + $this->subscriber->getParameters($this->event); + } + + public function testNoExceptionOnCorrectParameters() + { + $this->event->setParameters([ + 'client_id' => 'abc', + 'client_secret' => 'def', + ]); + + $this->subscriber->getParameters($this->event); + $this->addToAssertionCount(1); + } + + public function testHeaders() + { + $this->event->setParameters([ + 'client_id' => 'abc', + 'client_secret' => 'def', + ]); + + $this->subscriber->getParameters($this->event); + + $this->assertSame($this->event->getHeaders(), array( + 'Authorization' => 'Basic YWJjOmRlZg==', + 'Content-Type' => 'application/x-www-form-urlencoded', + )); } } From a7aa7fd08b8d7247523fb09cce7d70e53d43f4d8 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 24 Jul 2019 13:26:40 +0200 Subject: [PATCH 06/17] Fix code style. --- .../IntegrationRequestSubscriberTest.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php index bb591d07333..01c75f1c079 100644 --- a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php +++ b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php @@ -19,7 +19,6 @@ class IntegrationRequestSubscriberTest extends PHPUnit_Framework_TestCase { - /** @var PluginIntegrationRequestEvent */ protected $event; @@ -40,7 +39,6 @@ protected function setUp() $this->event = new PluginIntegrationRequestEvent($integration, '\'oauth/v2/token\'', null, null, null, null, null); } - /** * Tests getSubscribedEvents method. */ @@ -90,7 +88,7 @@ public function testExceptionOnEmptyParameters() public function testNoExceptionOnCorrectParameters() { $this->event->setParameters([ - 'client_id' => 'abc', + 'client_id' => 'abc', 'client_secret' => 'def', ]); @@ -101,15 +99,15 @@ public function testNoExceptionOnCorrectParameters() public function testHeaders() { $this->event->setParameters([ - 'client_id' => 'abc', + 'client_id' => 'abc', 'client_secret' => 'def', ]); $this->subscriber->getParameters($this->event); - $this->assertSame($this->event->getHeaders(), array( + $this->assertSame($this->event->getHeaders(), [ 'Authorization' => 'Basic YWJjOmRlZg==', - 'Content-Type' => 'application/x-www-form-urlencoded', - )); + 'Content-Type' => 'application/x-www-form-urlencoded', + ]); } } From a421ccdda01606baa8c3a58ecd2903590b8efa65 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 24 Jul 2019 13:32:38 +0200 Subject: [PATCH 07/17] Remove PHPDoc block --- .../Tests/EventListener/IntegrationRequestSubscriberTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php index 01c75f1c079..f36bb55dd1c 100644 --- a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php +++ b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php @@ -39,9 +39,6 @@ protected function setUp() $this->event = new PluginIntegrationRequestEvent($integration, '\'oauth/v2/token\'', null, null, null, null, null); } - /** - * Tests getSubscribedEvents method. - */ public function testGetSubscribedEventsMethod() { $this->assertSame(IntegrationRequestSubscriber::getSubscribedEvents(), [ From 3df54abd38b10a2a2d6fc4e43377081d40b758bd Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Thu, 25 Jul 2019 11:45:31 +0200 Subject: [PATCH 08/17] Fix mb_strpos. We have to use mb_string library. --- .../Form/Type/CitrixCampaignActionType.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/MauticCitrixBundle/Form/Type/CitrixCampaignActionType.php b/plugins/MauticCitrixBundle/Form/Type/CitrixCampaignActionType.php index 433b5bb654e..1d2d258c698 100644 --- a/plugins/MauticCitrixBundle/Form/Type/CitrixCampaignActionType.php +++ b/plugins/MauticCitrixBundle/Form/Type/CitrixCampaignActionType.php @@ -65,8 +65,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) $newChoices = []; foreach ($choices as $k => $c) { - if (0 === strpos($k, $product)) { - $newChoices[$c] = $k; + if (0 === mb_strpos($k, $product)) { + $newChoices[$k] = $c; } } @@ -74,9 +74,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'event-criteria-'.$product, ChoiceType::class, [ - 'label' => $this->translator->trans('plugin.citrix.action.criteria'), - 'choices' => $newChoices, - ] + 'label' => $this->translator->trans('plugin.citrix.action.criteria'), + 'choices' => $newChoices, + ] ); if (CitrixProducts::GOTOASSIST !== $product) { @@ -84,9 +84,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) $product.'-list', ChoiceType::class, [ - 'label' => $this->translator->trans('plugin.citrix.decision.'.$product.'.list'), - 'choices' => array_flip(CitrixHelper::getCitrixChoices($product)), - 'multiple' => true, + 'label' => $this->translator->trans('plugin.citrix.decision.'.$product.'.list'), + 'choices' => array_flip(CitrixHelper::getCitrixChoices($product)), + 'multiple' => true, ] ); } @@ -102,8 +102,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'class' => 'form-control', 'tooltip' => 'plugin.citrix.emailtemplate_descr', ], - 'required' => true, - 'multiple' => false, + 'required' => true, + 'multiple' => false, ]; if (array_key_exists('list_options', $options)) { From 7900fbab1c9a7e7efb32c26802e46fb2aa882655 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 13 Aug 2019 17:57:43 +0200 Subject: [PATCH 09/17] Use AbstractIntegration instead of non existing UnifiedIntegrationInterface class for test. --- .../Tests/EventListener/IntegrationRequestSubscriberTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php index f36bb55dd1c..b89543747b1 100644 --- a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php +++ b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php @@ -12,7 +12,7 @@ namespace MauticPlugin\MauticCitrixBundle\Tests\EventListener; use Mautic\PluginBundle\Event\PluginIntegrationRequestEvent; -use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; +use Mautic\PluginBundle\Integration\AbstractIntegration; use Mautic\PluginBundle\PluginEvents; use MauticPlugin\MauticCitrixBundle\EventListener\IntegrationRequestSubscriber; use PHPUnit_Framework_TestCase; @@ -32,7 +32,7 @@ protected function setUp() ->setMethodsExcept(['getParameters', 'getAuthorization']) ->getMock(); - $integration = $this->getMockBuilder(UnifiedIntegrationInterface::class) + $integration = $this->getMockBuilder(AbstractIntegration::class) ->disableOriginalConstructor() ->getMock(); From ddffda59c71623d9d38e79e34f5f662bb18d1597 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Aug 2019 15:24:59 +0200 Subject: [PATCH 10/17] Merge UnifiedIntegrationInterface from Mautic Cloud. --- .../Tests/EventListener/IntegrationRequestSubscriberTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php index b89543747b1..f36bb55dd1c 100644 --- a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php +++ b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php @@ -12,7 +12,7 @@ namespace MauticPlugin\MauticCitrixBundle\Tests\EventListener; use Mautic\PluginBundle\Event\PluginIntegrationRequestEvent; -use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; use Mautic\PluginBundle\PluginEvents; use MauticPlugin\MauticCitrixBundle\EventListener\IntegrationRequestSubscriber; use PHPUnit_Framework_TestCase; @@ -32,7 +32,7 @@ protected function setUp() ->setMethodsExcept(['getParameters', 'getAuthorization']) ->getMock(); - $integration = $this->getMockBuilder(AbstractIntegration::class) + $integration = $this->getMockBuilder(UnifiedIntegrationInterface::class) ->disableOriginalConstructor() ->getMock(); From 73b1e80229eda6bb77abcf3978d11ded408dc985 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Wed, 14 Aug 2019 15:42:06 +0200 Subject: [PATCH 11/17] Merge UnifiedIntegrationInterface from Mautic. --- .../AssetBundle/Controller/AjaxController.php | 2 ++ .../AssetBundle/Event/RemoteAssetBrowseEvent.php | 3 ++- .../PluginBundle/Command/FetchLeadsCommand.php | 11 ++++++----- .../PluginIntegrationAuthCallbackUrlEvent.php | 9 ++------- .../Event/PluginIntegrationAuthRedirectEvent.php | 9 ++------- .../PluginBundle/Event/PluginIntegrationEvent.php | 7 ++----- .../Event/PluginIntegrationFormBuildEvent.php | 4 ++-- .../Event/PluginIntegrationFormDisplayEvent.php | 9 ++------- .../Event/PluginIntegrationKeyEvent.php | 7 ++----- .../Event/PluginIntegrationRequestEvent.php | 14 ++------------ app/bundles/PluginBundle/Helper/oAuthHelper.php | 11 +++++++++-- .../Integration/AbstractIntegration.php | 2 +- .../Api/EmailMarketingApi.php | 4 ++-- 13 files changed, 36 insertions(+), 56 deletions(-) diff --git a/app/bundles/AssetBundle/Controller/AjaxController.php b/app/bundles/AssetBundle/Controller/AjaxController.php index 3ef2325128e..6dd2da6ab92 100644 --- a/app/bundles/AssetBundle/Controller/AjaxController.php +++ b/app/bundles/AssetBundle/Controller/AjaxController.php @@ -43,6 +43,8 @@ protected function categoryListAction(Request $request) /** * @return \Symfony\Component\HttpFoundation\JsonResponse + * + * @throws \Exception */ protected function fetchRemoteFilesAction(Request $request) { diff --git a/app/bundles/AssetBundle/Event/RemoteAssetBrowseEvent.php b/app/bundles/AssetBundle/Event/RemoteAssetBrowseEvent.php index 4ed3b270b00..8f28ffb4313 100644 --- a/app/bundles/AssetBundle/Event/RemoteAssetBrowseEvent.php +++ b/app/bundles/AssetBundle/Event/RemoteAssetBrowseEvent.php @@ -14,6 +14,7 @@ use Gaufrette\Adapter; use Mautic\CoreBundle\Event\CommonEvent; use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; /** * Class RemoteAssetBrowseEvent. @@ -30,7 +31,7 @@ class RemoteAssetBrowseEvent extends CommonEvent */ private $integration; - public function __construct(AbstractIntegration $integration) + public function __construct(UnifiedIntegrationInterface $integration) { $this->integration = $integration; } diff --git a/app/bundles/PluginBundle/Command/FetchLeadsCommand.php b/app/bundles/PluginBundle/Command/FetchLeadsCommand.php index 25b6d94f7c6..a154ad06811 100644 --- a/app/bundles/PluginBundle/Command/FetchLeadsCommand.php +++ b/app/bundles/PluginBundle/Command/FetchLeadsCommand.php @@ -11,7 +11,7 @@ namespace Mautic\PluginBundle\Command; -use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -97,10 +97,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $integrationHelper = $container->get('mautic.helper.integration'); $integrationObject = $integrationHelper->getIntegrationObject($integration); - if (!$integrationObject instanceof AbstractIntegration) { - $availableIntegrations = array_filter($integrationHelper->getIntegrationObjects(), function (AbstractIntegration $availableIntegration) { - return $availableIntegration->isConfigured(); - }); + if (!$integrationObject instanceof UnifiedIntegrationInterface) { + $availableIntegrations = array_filter($integrationHelper->getIntegrationObjects(), + function (UnifiedIntegrationInterface $availableIntegration) { + return $availableIntegration->isConfigured(); + }); throw new \RuntimeException(sprintf('The Integration "%s" is not one of the available integrations (%s)', $integration, implode(', ', array_keys($availableIntegrations)))); } diff --git a/app/bundles/PluginBundle/Event/PluginIntegrationAuthCallbackUrlEvent.php b/app/bundles/PluginBundle/Event/PluginIntegrationAuthCallbackUrlEvent.php index a587020e2ac..025f954e5d9 100644 --- a/app/bundles/PluginBundle/Event/PluginIntegrationAuthCallbackUrlEvent.php +++ b/app/bundles/PluginBundle/Event/PluginIntegrationAuthCallbackUrlEvent.php @@ -11,7 +11,7 @@ namespace Mautic\PluginBundle\Event; -use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; /** * Class PluginIntegrationAuthCallbackUrlEvent. @@ -23,12 +23,7 @@ class PluginIntegrationAuthCallbackUrlEvent extends AbstractPluginIntegrationEve */ private $callbackUrl; - /** - * PluginIntegrationAuthCallbackUrlEvent constructor. - * - * @param $callbackUrl - */ - public function __construct(AbstractIntegration $integration, $callbackUrl) + public function __construct(UnifiedIntegrationInterface $integration, $callbackUrl) { $this->integration = $integration; $this->callbackUrl = $callbackUrl; diff --git a/app/bundles/PluginBundle/Event/PluginIntegrationAuthRedirectEvent.php b/app/bundles/PluginBundle/Event/PluginIntegrationAuthRedirectEvent.php index 4923f335687..cf847499761 100644 --- a/app/bundles/PluginBundle/Event/PluginIntegrationAuthRedirectEvent.php +++ b/app/bundles/PluginBundle/Event/PluginIntegrationAuthRedirectEvent.php @@ -11,7 +11,7 @@ namespace Mautic\PluginBundle\Event; -use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; /** * Class PluginIntegrationAuthRedirectEvent. @@ -23,12 +23,7 @@ class PluginIntegrationAuthRedirectEvent extends AbstractPluginIntegrationEvent */ private $authUrl; - /** - * PluginIntegrationAuthRedirectEvent constructor. - * - * @param $authUrl - */ - public function __construct(AbstractIntegration $integration, $authUrl) + public function __construct(UnifiedIntegrationInterface $integration, $authUrl) { $this->integration = $integration; $this->authUrl = $authUrl; diff --git a/app/bundles/PluginBundle/Event/PluginIntegrationEvent.php b/app/bundles/PluginBundle/Event/PluginIntegrationEvent.php index 23c7f3e92cd..cdcba4fe84c 100644 --- a/app/bundles/PluginBundle/Event/PluginIntegrationEvent.php +++ b/app/bundles/PluginBundle/Event/PluginIntegrationEvent.php @@ -12,17 +12,14 @@ namespace Mautic\PluginBundle\Event; use Mautic\PluginBundle\Entity\Integration; -use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; /** * Class PluginIntegrationEvent. */ class PluginIntegrationEvent extends AbstractPluginIntegrationEvent { - /** - * PluginIntegrationEvent constructor. - */ - public function __construct(AbstractIntegration $integration) + public function __construct(UnifiedIntegrationInterface $integration) { $this->integration = $integration; } diff --git a/app/bundles/PluginBundle/Event/PluginIntegrationFormBuildEvent.php b/app/bundles/PluginBundle/Event/PluginIntegrationFormBuildEvent.php index 5b44a907c0e..bf6504cd34d 100644 --- a/app/bundles/PluginBundle/Event/PluginIntegrationFormBuildEvent.php +++ b/app/bundles/PluginBundle/Event/PluginIntegrationFormBuildEvent.php @@ -11,7 +11,7 @@ namespace Mautic\PluginBundle\Event; -use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; use Symfony\Component\Form\FormBuilder; class PluginIntegrationFormBuildEvent extends AbstractPluginIntegrationEvent @@ -26,7 +26,7 @@ class PluginIntegrationFormBuildEvent extends AbstractPluginIntegrationEvent */ private $builder; - public function __construct(AbstractIntegration $integration, FormBuilder $builder, array $options) + public function __construct(UnifiedIntegrationInterface $integration, FormBuilder $builder, array $options) { $this->integration = $integration; $this->builder = $builder; diff --git a/app/bundles/PluginBundle/Event/PluginIntegrationFormDisplayEvent.php b/app/bundles/PluginBundle/Event/PluginIntegrationFormDisplayEvent.php index 81dca753d1c..20555d40b0d 100644 --- a/app/bundles/PluginBundle/Event/PluginIntegrationFormDisplayEvent.php +++ b/app/bundles/PluginBundle/Event/PluginIntegrationFormDisplayEvent.php @@ -11,7 +11,7 @@ namespace Mautic\PluginBundle\Event; -use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; /** * Class PluginIntegrationFormDisplayEvent. @@ -23,12 +23,7 @@ class PluginIntegrationFormDisplayEvent extends AbstractPluginIntegrationEvent */ private $settings = []; - /** - * PluginIntegrationAuthCallbackUrlEvent constructor. - * - * @param $settings - */ - public function __construct(AbstractIntegration $integration, array $settings) + public function __construct(UnifiedIntegrationInterface $integration, array $settings) { $this->integration = $integration; $this->settings = $settings; diff --git a/app/bundles/PluginBundle/Event/PluginIntegrationKeyEvent.php b/app/bundles/PluginBundle/Event/PluginIntegrationKeyEvent.php index 72a4c1a33e0..52860101191 100644 --- a/app/bundles/PluginBundle/Event/PluginIntegrationKeyEvent.php +++ b/app/bundles/PluginBundle/Event/PluginIntegrationKeyEvent.php @@ -11,7 +11,7 @@ namespace Mautic\PluginBundle\Event; -use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; /** * Class PluginIntegrationKeyEvent. @@ -23,10 +23,7 @@ class PluginIntegrationKeyEvent extends AbstractPluginIntegrationEvent */ private $keys; - /** - * PluginIntegrationKeyEvent constructor. - */ - public function __construct(AbstractIntegration $integration, array $keys = null) + public function __construct(UnifiedIntegrationInterface $integration, array $keys = null) { $this->integration = $integration; $this->keys = $keys; diff --git a/app/bundles/PluginBundle/Event/PluginIntegrationRequestEvent.php b/app/bundles/PluginBundle/Event/PluginIntegrationRequestEvent.php index cfc1e3c7f00..664b9f38291 100644 --- a/app/bundles/PluginBundle/Event/PluginIntegrationRequestEvent.php +++ b/app/bundles/PluginBundle/Event/PluginIntegrationRequestEvent.php @@ -11,7 +11,7 @@ namespace Mautic\PluginBundle\Event; -use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; /** * Class PluginIntegrationRequestEvent. @@ -53,17 +53,7 @@ class PluginIntegrationRequestEvent extends AbstractPluginIntegrationEvent */ private $response; - /** - * PluginIntegrationRequestEvent constructor. - * - * @param $url - * @param $parameters - * @param $headers - * @param $method - * @param $settings - * @param $authType - */ - public function __construct(AbstractIntegration $integration, $url, $parameters, $headers, $method, $settings, $authType) + public function __construct(UnifiedIntegrationInterface $integration, $url, $parameters, $headers, $method, $settings, $authType) { $this->integration = $integration; $this->url = $url; diff --git a/app/bundles/PluginBundle/Helper/oAuthHelper.php b/app/bundles/PluginBundle/Helper/oAuthHelper.php index 4c1b90dcced..6c0954e7cd6 100644 --- a/app/bundles/PluginBundle/Helper/oAuthHelper.php +++ b/app/bundles/PluginBundle/Helper/oAuthHelper.php @@ -11,7 +11,7 @@ namespace Mautic\PluginBundle\Helper; -use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -35,7 +35,14 @@ class oAuthHelper private $request; - public function __construct(AbstractIntegration $integration, Request $request = null, $settings = []) + /** + * oAuthHelper constructor. + * + * @param UnifiedIntegrationInterface $integration + * @param Request|null $request + * @param array $settings + */ + public function __construct(UnifiedIntegrationInterface $integration, Request $request = null, $settings = []) { $clientId = $integration->getClientIdKey(); $clientSecret = $integration->getClientSecretKey(); diff --git a/app/bundles/PluginBundle/Integration/AbstractIntegration.php b/app/bundles/PluginBundle/Integration/AbstractIntegration.php index 1400d8eafbe..2620445ffd0 100644 --- a/app/bundles/PluginBundle/Integration/AbstractIntegration.php +++ b/app/bundles/PluginBundle/Integration/AbstractIntegration.php @@ -57,7 +57,7 @@ * @method getLeads(array $params, string $query, &$executed, array $result = [], $object = 'Lead') * @method getCompanies(array $params) */ -abstract class AbstractIntegration +abstract class AbstractIntegration implements UnifiedIntegrationInterface { const FIELD_TYPE_STRING = 'string'; const FIELD_TYPE_BOOL = 'boolean'; diff --git a/plugins/MauticEmailMarketingBundle/Api/EmailMarketingApi.php b/plugins/MauticEmailMarketingBundle/Api/EmailMarketingApi.php index 28f5a5644a9..e96ae084243 100644 --- a/plugins/MauticEmailMarketingBundle/Api/EmailMarketingApi.php +++ b/plugins/MauticEmailMarketingBundle/Api/EmailMarketingApi.php @@ -11,14 +11,14 @@ namespace MauticPlugin\MauticEmailMarketingBundle\Api; -use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; class EmailMarketingApi { protected $integration; protected $keys; - public function __construct(AbstractIntegration $integration) + public function __construct(UnifiedIntegrationInterface $integration) { $this->integration = $integration; $this->keys = $integration->getKeys(); From 595bd98f532b2aebd7aaa664da2d412ac37e1ae9 Mon Sep 17 00:00:00 2001 From: Alan Hartless Date: Thu, 24 Oct 2019 11:21:10 -0500 Subject: [PATCH 12/17] Fixes issue where Citrix did not renew the access token from a refresh token --- .../Integration/CitrixAbstractIntegration.php | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/plugins/MauticCitrixBundle/Integration/CitrixAbstractIntegration.php b/plugins/MauticCitrixBundle/Integration/CitrixAbstractIntegration.php index 9ba3a10370c..3c704ac9bb4 100644 --- a/plugins/MauticCitrixBundle/Integration/CitrixAbstractIntegration.php +++ b/plugins/MauticCitrixBundle/Integration/CitrixAbstractIntegration.php @@ -140,34 +140,46 @@ public function getAuthenticationUrl() } /** - * {@inheritdoc} - * - * @return bool + * @return string */ - public function isAuthorized() + public function getApiKey() { $keys = $this->getKeys(); - return isset($keys[$this->getAuthTokenKey()]); + return $keys[$this->getAuthTokenKey()]; } /** * @return string */ - public function getApiKey() + public function getOrganizerKey() { $keys = $this->getKeys(); - return $keys[$this->getAuthTokenKey()]; + return $keys['organizer_key']; } /** - * @return string + * Get the keys for the refresh token and expiry. + * + * @return array */ - public function getOrganizerKey() + public function getRefreshTokenKeys() { - $keys = $this->getKeys(); + return ['refresh_token', 'expires']; + } - return $keys['organizer_key']; + /** + * {@inheritdoc} + * + * @param $data + */ + public function prepareResponseForExtraction($data) + { + if (is_array($data) && isset($data['expires_in'])) { + $data['expires'] = $data['expires_in'] + time(); + } + + return $data; } } From ca547f42c1cfef7d461905402ae80914a06e36e4 Mon Sep 17 00:00:00 2001 From: Alan Hartless Date: Wed, 12 Feb 2020 21:35:12 -0600 Subject: [PATCH 13/17] Fixed AbstractIntegration to be UnifiedIntegrationInterface in order to support icons for plugins based on IntegrationsBundle --- app/bundles/PluginBundle/Helper/IntegrationHelper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/bundles/PluginBundle/Helper/IntegrationHelper.php b/app/bundles/PluginBundle/Helper/IntegrationHelper.php index 9ee754359c5..0cedfd5a730 100644 --- a/app/bundles/PluginBundle/Helper/IntegrationHelper.php +++ b/app/bundles/PluginBundle/Helper/IntegrationHelper.php @@ -20,6 +20,7 @@ use Mautic\PluginBundle\Entity\Integration; use Mautic\PluginBundle\Entity\Plugin; use Mautic\PluginBundle\Integration\AbstractIntegration; +use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Finder\Finder; @@ -662,7 +663,7 @@ public function getIconPath($integration) } elseif ($integration instanceof Plugin) { // A bundle so check for an icon $icon = $pluginPath.'/'.$integration->getBundle().'/Assets/img/icon.png'; - } elseif ($integration instanceof AbstractIntegration) { + } elseif ($integration instanceof UnifiedIntegrationInterface) { return $integration->getIcon(); } From c280a641906cf1debfc47981f9178e351ee5c5b0 Mon Sep 17 00:00:00 2001 From: Alan Hartless Date: Wed, 12 Feb 2020 22:48:23 -0600 Subject: [PATCH 14/17] Prevented PHP notice when a plugin does not leverage integration settings "supportedFeatures" --- app/bundles/IntegrationsBundle/Views/Config/form.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/bundles/IntegrationsBundle/Views/Config/form.html.php b/app/bundles/IntegrationsBundle/Views/Config/form.html.php index 39d00790219..3d4d0d392cd 100644 --- a/app/bundles/IntegrationsBundle/Views/Config/form.html.php +++ b/app/bundles/IntegrationsBundle/Views/Config/form.html.php @@ -95,7 +95,7 @@
row($form['supportedFeatures']); + echo $view['form']->rowIfExists($form, 'supportedFeatures'); if ($useFeatureSettings || $useSyncFeatures): echo '
'; From 7f6b399da387f9c5cf9822e82076474f5cfa65ac Mon Sep 17 00:00:00 2001 From: Alan Hartless Date: Wed, 12 Feb 2020 22:48:53 -0600 Subject: [PATCH 15/17] Fixed test to be compatible with PhpUnit 7 --- .../Tests/EventListener/IntegrationRequestSubscriberTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php index f36bb55dd1c..923ef2eaf89 100644 --- a/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php +++ b/plugins/MauticCitrixBundle/Tests/EventListener/IntegrationRequestSubscriberTest.php @@ -15,9 +15,9 @@ use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface; use Mautic\PluginBundle\PluginEvents; use MauticPlugin\MauticCitrixBundle\EventListener\IntegrationRequestSubscriber; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; -class IntegrationRequestSubscriberTest extends PHPUnit_Framework_TestCase +class IntegrationRequestSubscriberTest extends TestCase { /** @var PluginIntegrationRequestEvent */ protected $event; From 0fcfc930396dffc1425c085272cf616cc0c8266c Mon Sep 17 00:00:00 2001 From: Alan Hartless Date: Wed, 12 Feb 2020 19:33:22 -0600 Subject: [PATCH 16/17] Fixed duplicate getRefreshTokenKeys from merge --- .../Integration/CitrixAbstractIntegration.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/plugins/MauticCitrixBundle/Integration/CitrixAbstractIntegration.php b/plugins/MauticCitrixBundle/Integration/CitrixAbstractIntegration.php index 3c704ac9bb4..6d449e88165 100644 --- a/plugins/MauticCitrixBundle/Integration/CitrixAbstractIntegration.php +++ b/plugins/MauticCitrixBundle/Integration/CitrixAbstractIntegration.php @@ -41,17 +41,6 @@ public function setIntegrationSettings(Integration $settings) parent::setIntegrationSettings($settings); } - /** - * Refresh tokens. - */ - public function getRefreshTokenKeys() - { - return [ - 'refresh_token', - 'expires_in', - ]; - } - /** * {@inheritdoc} * From 7d2bd0e2d98f99ef43b3cc790412b85ad77f4e53 Mon Sep 17 00:00:00 2001 From: Alan Hartless Date: Thu, 13 Feb 2020 01:53:33 -0600 Subject: [PATCH 17/17] PHP CS fixes --- app/bundles/PluginBundle/Helper/oAuthHelper.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/bundles/PluginBundle/Helper/oAuthHelper.php b/app/bundles/PluginBundle/Helper/oAuthHelper.php index 6c0954e7cd6..5098f7e1a5d 100644 --- a/app/bundles/PluginBundle/Helper/oAuthHelper.php +++ b/app/bundles/PluginBundle/Helper/oAuthHelper.php @@ -35,13 +35,6 @@ class oAuthHelper private $request; - /** - * oAuthHelper constructor. - * - * @param UnifiedIntegrationInterface $integration - * @param Request|null $request - * @param array $settings - */ public function __construct(UnifiedIntegrationInterface $integration, Request $request = null, $settings = []) { $clientId = $integration->getClientIdKey();