Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified integration interface #8433

Merged
merged 17 commits into from Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/bundles/AssetBundle/Controller/AjaxController.php
Expand Up @@ -43,6 +43,8 @@ protected function categoryListAction(Request $request)

/**
* @return \Symfony\Component\HttpFoundation\JsonResponse
*
* @throws \Exception
*/
protected function fetchRemoteFilesAction(Request $request)
{
Expand Down
3 changes: 2 additions & 1 deletion app/bundles/AssetBundle/Event/RemoteAssetBrowseEvent.php
Expand Up @@ -14,6 +14,7 @@
use Gaufrette\Adapter;
use Mautic\CoreBundle\Event\CommonEvent;
use Mautic\PluginBundle\Integration\AbstractIntegration;
use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface;

/**
* Class RemoteAssetBrowseEvent.
Expand All @@ -30,7 +31,7 @@ class RemoteAssetBrowseEvent extends CommonEvent
*/
private $integration;

public function __construct(AbstractIntegration $integration)
public function __construct(UnifiedIntegrationInterface $integration)
{
$this->integration = $integration;
}
Expand Down
2 changes: 1 addition & 1 deletion app/bundles/IntegrationsBundle/Views/Config/form.html.php
Expand Up @@ -95,7 +95,7 @@
<?php if ($showFeaturesTab): ?>
<div class="tab-pane fade <?php if ('features-container' == $activeTab): echo 'in active'; endif; ?> bdr-w-0" id="features-container">
<?php
echo $view['form']->row($form['supportedFeatures']);
echo $view['form']->rowIfExists($form, 'supportedFeatures');

if ($useFeatureSettings || $useSyncFeatures):
echo '<hr />';
Expand Down
11 changes: 6 additions & 5 deletions app/bundles/PluginBundle/Command/FetchLeadsCommand.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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))));
}

Expand Down
Expand Up @@ -11,7 +11,7 @@

namespace Mautic\PluginBundle\Event;

use Mautic\PluginBundle\Integration\AbstractIntegration;
use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface;

/**
* Class PluginIntegrationAuthCallbackUrlEvent.
Expand All @@ -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;
Expand Down
Expand Up @@ -11,7 +11,7 @@

namespace Mautic\PluginBundle\Event;

use Mautic\PluginBundle\Integration\AbstractIntegration;
use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface;

/**
* Class PluginIntegrationAuthRedirectEvent.
Expand All @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions app/bundles/PluginBundle/Event/PluginIntegrationEvent.php
Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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
Expand All @@ -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;
Expand Down
Expand Up @@ -11,7 +11,7 @@

namespace Mautic\PluginBundle\Event;

use Mautic\PluginBundle\Integration\AbstractIntegration;
use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface;

/**
* Class PluginIntegrationFormDisplayEvent.
Expand All @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions app/bundles/PluginBundle/Event/PluginIntegrationKeyEvent.php
Expand Up @@ -11,7 +11,7 @@

namespace Mautic\PluginBundle\Event;

use Mautic\PluginBundle\Integration\AbstractIntegration;
use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface;

/**
* Class PluginIntegrationKeyEvent.
Expand All @@ -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;
Expand Down
14 changes: 2 additions & 12 deletions app/bundles/PluginBundle/Event/PluginIntegrationRequestEvent.php
Expand Up @@ -11,7 +11,7 @@

namespace Mautic\PluginBundle\Event;

use Mautic\PluginBundle\Integration\AbstractIntegration;
use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface;

/**
* Class PluginIntegrationRequestEvent.
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion app/bundles/PluginBundle/Helper/IntegrationHelper.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions app/bundles/PluginBundle/Helper/oAuthHelper.php
Expand Up @@ -11,7 +11,7 @@

namespace Mautic\PluginBundle\Helper;

use Mautic\PluginBundle\Integration\AbstractIntegration;
use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface;
use Symfony\Component\HttpFoundation\Request;

/**
Expand All @@ -35,7 +35,7 @@ class oAuthHelper

private $request;

public function __construct(AbstractIntegration $integration, Request $request = null, $settings = [])
public function __construct(UnifiedIntegrationInterface $integration, Request $request = null, $settings = [])
{
$clientId = $integration->getClientIdKey();
$clientSecret = $integration->getClientSecretKey();
Expand Down
Expand Up @@ -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';
Expand Down
1 change: 0 additions & 1 deletion plugins/MauticCitrixBundle/Config/config.php
Expand Up @@ -78,7 +78,6 @@
],
'mautic.citrix.integration.request' => [
'class' => \MauticPlugin\MauticCitrixBundle\EventListener\IntegrationRequestSubscriber::class,
'arguments' => [],
],
],
'forms' => [
Expand Down
5 changes: 2 additions & 3 deletions plugins/MauticCitrixBundle/Controller/PublicController.php
Expand Up @@ -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',
Expand All @@ -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') ?: [];
Expand Down
Expand Up @@ -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']);
Expand Down
20 changes: 10 additions & 10 deletions plugins/MauticCitrixBundle/Form/Type/CitrixCampaignActionType.php
Expand Up @@ -65,28 +65,28 @@ 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;
}
}

$builder->add(
'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) {
$builder->add(
$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,
]
);
}
Expand All @@ -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)) {
Expand Down