Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\PluginBundle\Controller;
|
||||
|
||||
use Mautic\CoreBundle\Controller\AjaxController as CommonAjaxController;
|
||||
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\Helper\IntegrationHelper;
|
||||
use Mautic\PluginBundle\Model\PluginModel;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class AjaxController extends CommonAjaxController
|
||||
{
|
||||
public function setIntegrationFilterAction(Request $request): \Symfony\Component\HttpFoundation\JsonResponse
|
||||
{
|
||||
$session = $request->getSession();
|
||||
$pluginFilter = (int) $request->get('plugin');
|
||||
$session->set('mautic.integrations.filter', $pluginFilter);
|
||||
|
||||
return $this->sendJsonResponse(['success' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML for list of fields.
|
||||
*/
|
||||
public function getIntegrationFieldsAction(Request $request, IntegrationHelper $helper): \Symfony\Component\HttpFoundation\JsonResponse
|
||||
{
|
||||
$integration = $request->query->get('integration');
|
||||
$settings = $request->query->all()['settings'] ?? [];
|
||||
$page = $request->query->get('page');
|
||||
|
||||
$dataArray = ['success' => 0];
|
||||
|
||||
if (!empty($integration) && !empty($settings)) {
|
||||
/** @var \Mautic\PluginBundle\Integration\AbstractIntegration $integrationObject */
|
||||
$integrationObject = $helper->getIntegrationObject($integration);
|
||||
|
||||
if ($integrationObject) {
|
||||
if (!$object = $request->attributes->get('object')) {
|
||||
$object = $settings['object'] ?? 'lead';
|
||||
}
|
||||
|
||||
$isLead = ('lead' === $object);
|
||||
$integrationFields = ($isLead)
|
||||
? $integrationObject->getFormLeadFields($settings)
|
||||
: $integrationObject->getFormCompanyFields(
|
||||
$settings
|
||||
);
|
||||
|
||||
if (!empty($integrationFields)) {
|
||||
$session = $request->getSession();
|
||||
$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 ? 'integration_fields' : 'integration_company_fields';
|
||||
$form = $this->createForm(
|
||||
$isLead ? FieldsType::class : CompanyFieldsType::class,
|
||||
$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->coreParametersHelper->get('default_pagelimit'),
|
||||
]
|
||||
);
|
||||
|
||||
$html = $this->render('@MauticCore/Helper/blank_form.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'formTheme' => '@MauticPlugin/FormTheme/Integration/layout.html.twig',
|
||||
'function' => 'row',
|
||||
]
|
||||
)->getContent();
|
||||
|
||||
if (!isset($settings['prefix'])) {
|
||||
$prefix = 'integration_details[featureSettings]['.$object.'Fields]';
|
||||
} else {
|
||||
$prefix = $settings['prefix'];
|
||||
}
|
||||
|
||||
$idPrefix = str_replace(['][', '[', ']'], '_', $prefix);
|
||||
if (str_ends_with($idPrefix, '_')) {
|
||||
$idPrefix = substr($idPrefix, 0, -1);
|
||||
}
|
||||
$html = preg_replace('/'.$form->getName().'\[(.*?)\]/', $prefix.'[$1]', $html);
|
||||
$html = str_replace($form->getName(), $idPrefix, $html);
|
||||
$dataArray['success'] = 1;
|
||||
$dataArray['html'] = $html;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->sendJsonResponse($dataArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML for integration properties.
|
||||
*/
|
||||
public function getIntegrationConfigAction(Request $request, IntegrationHelper $integrationHelper): \Symfony\Component\HttpFoundation\JsonResponse
|
||||
{
|
||||
$integration = $request->query->get('integration');
|
||||
$settings = $request->query->all()['settings'] ?? [];
|
||||
$dataArray = ['success' => 0];
|
||||
|
||||
if (!empty($integration) && !empty($settings)) {
|
||||
/** @var \Mautic\PluginBundle\Integration\AbstractIntegration $object */
|
||||
$object = $integrationHelper->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,
|
||||
]);
|
||||
|
||||
$html = $this->render('@MauticCore/Helper/blank_form.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'function' => 'widget',
|
||||
'formTheme' => '@MauticPlugin/FormTheme/Integration/layout.html.twig',
|
||||
'variables' => [
|
||||
'integration' => $object,
|
||||
],
|
||||
])->getContent();
|
||||
|
||||
$prefix = str_replace('[integration]', '[config]', $settings['name']);
|
||||
$idPrefix = str_replace(['][', '[', ']'], '_', $prefix);
|
||||
if (str_ends_with($idPrefix, '_')) {
|
||||
$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);
|
||||
}
|
||||
|
||||
public function getIntegrationCampaignStatusAction(Request $request, IntegrationHelper $integrationHelper): \Symfony\Component\HttpFoundation\JsonResponse
|
||||
{
|
||||
$integration = $request->query->get('integration');
|
||||
$campaign = $request->query->get('campaign');
|
||||
$settings = $request->query->all()['settings'] ?? [];
|
||||
$dataArray = ['success' => 0];
|
||||
$statusData = [];
|
||||
if (!empty($integration) && !empty($campaign)) {
|
||||
/** @var \Mautic\PluginBundle\Integration\AbstractIntegration $object */
|
||||
$object = $integrationHelper->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,
|
||||
]);
|
||||
|
||||
$html = $this->render('@MauticCore/Helper/blank_form.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'formTheme' => '@MauticPlugin/FormTheme/Integration/layout.html.twig',
|
||||
'function' => 'widget',
|
||||
'variables' => [
|
||||
'integration' => $object,
|
||||
],
|
||||
])->getContent();
|
||||
|
||||
$prefix = str_replace('[integration]', '[campaign_member_status][campaign_member_status]', $settings['name']);
|
||||
|
||||
$idPrefix = str_replace(['][', '[', ']'], '_', $prefix);
|
||||
|
||||
if (str_ends_with($idPrefix, '_')) {
|
||||
$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);
|
||||
}
|
||||
|
||||
public function matchFieldsAction(Request $request, IntegrationHelper $integrationHelper): \Symfony\Component\HttpFoundation\JsonResponse
|
||||
{
|
||||
$integration = $request->request->get('integration');
|
||||
$integration_field = $request->request->get('integrationField');
|
||||
$mautic_field = $request->request->get('mauticField');
|
||||
$update_mautic = $request->request->get('updateMautic');
|
||||
$object = $request->request->get('object');
|
||||
|
||||
$integration_object = $integrationHelper->getIntegrationObject($integration);
|
||||
$entity = $integration_object->getIntegrationSettings();
|
||||
$featureSettings = $entity->getFeatureSettings();
|
||||
$doNotMatchField = ('-1' === $mautic_field || '' === $mautic_field);
|
||||
if ('lead' == $object) {
|
||||
$fields = 'leadFields';
|
||||
$updateFields = 'update_mautic';
|
||||
} else {
|
||||
$fields = 'companyFields';
|
||||
$updateFields = 'update_mautic_company';
|
||||
}
|
||||
$newFeatureSettings = [];
|
||||
if ($doNotMatchField) {
|
||||
if (isset($featureSettings[$updateFields]) && array_key_exists($integration_field, $featureSettings[$updateFields])) {
|
||||
unset($featureSettings[$updateFields][$integration_field]);
|
||||
}
|
||||
if (isset($featureSettings[$fields]) && array_key_exists($integration_field, $featureSettings[$fields])) {
|
||||
unset($featureSettings[$fields][$integration_field]);
|
||||
}
|
||||
$dataArray = ['success' => 0];
|
||||
} else {
|
||||
$newFeatureSettings[$integration_field] = $update_mautic;
|
||||
if (isset($featureSettings[$updateFields])) {
|
||||
$featureSettings[$updateFields] = array_merge($featureSettings[$updateFields], $newFeatureSettings);
|
||||
} else {
|
||||
$featureSettings[$updateFields] = $newFeatureSettings;
|
||||
}
|
||||
$newFeatureSettings[$integration_field] = $mautic_field;
|
||||
if (isset($featureSettings[$fields])) {
|
||||
$featureSettings[$fields] = array_merge($featureSettings[$fields], $newFeatureSettings);
|
||||
} else {
|
||||
$featureSettings[$fields] = $newFeatureSettings;
|
||||
}
|
||||
|
||||
$dataArray = ['success' => 1];
|
||||
}
|
||||
$entity->setFeatureSettings($featureSettings);
|
||||
|
||||
$pluginModel = $this->getModel('plugin');
|
||||
\assert($pluginModel instanceof PluginModel);
|
||||
$pluginModel->saveFeatureSettings($entity);
|
||||
|
||||
return $this->sendJsonResponse($dataArray);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\PluginBundle\Controller;
|
||||
|
||||
use Mautic\CoreBundle\Controller\FormController;
|
||||
use Mautic\PluginBundle\Event\PluginIntegrationAuthRedirectEvent;
|
||||
use Mautic\PluginBundle\Helper\IntegrationHelper;
|
||||
use Mautic\PluginBundle\PluginEvents;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class AuthController extends FormController
|
||||
{
|
||||
/**
|
||||
* @param string $integration
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function authCallbackAction(Request $request, IntegrationHelper $integrationHelper, $integration): JsonResponse|RedirectResponse
|
||||
{
|
||||
$isAjax = $request->isXmlHttpRequest();
|
||||
$session = $request->getSession();
|
||||
|
||||
$integrationObject = $integrationHelper->getIntegrationObject($integration);
|
||||
|
||||
// check to see if the service exists
|
||||
if (!$integrationObject) {
|
||||
$session->set('mautic.integration.postauth.message', ['mautic.integration.notfound', ['%name%' => $integration], 'error']);
|
||||
if ($isAjax) {
|
||||
return new JsonResponse(['url' => $this->generateUrl('mautic_integration_auth_postauth', ['integration' => $integration])]);
|
||||
} else {
|
||||
return new RedirectResponse($this->generateUrl('mautic_integration_auth_postauth', ['integration' => $integration]));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$error = $integrationObject->authCallback();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$session->set('mautic.integration.postauth.message', [$e->getMessage(), [], 'error']);
|
||||
$redirectUrl = $this->generateUrl('mautic_integration_auth_postauth', ['integration' => $integration]);
|
||||
if ($isAjax) {
|
||||
return new JsonResponse(['url' => $redirectUrl]);
|
||||
} else {
|
||||
return new RedirectResponse($redirectUrl);
|
||||
}
|
||||
}
|
||||
|
||||
// check for error
|
||||
if ($error) {
|
||||
$type = 'error';
|
||||
$message = 'mautic.integration.error.oauthfail';
|
||||
$params = ['%error%' => $error];
|
||||
} else {
|
||||
$type = 'notice';
|
||||
$message = 'mautic.integration.notice.oauthsuccess';
|
||||
$params = [];
|
||||
}
|
||||
|
||||
$session->set('mautic.integration.postauth.message', [$message, $params, $type]);
|
||||
|
||||
$identifier[$integration] = null;
|
||||
$socialCache = [];
|
||||
$userData = $integrationObject->getUserData($identifier, $socialCache);
|
||||
|
||||
$session->set('mautic.integration.'.$integration.'.userdata', $userData);
|
||||
|
||||
return new RedirectResponse($this->generateUrl('mautic_integration_auth_postauth', ['integration' => $integration]));
|
||||
}
|
||||
|
||||
public function authStatusAction(Request $request, $integration): \Symfony\Component\HttpFoundation\Response
|
||||
{
|
||||
$postAuthTemplate = '@MauticPlugin/Auth/postauth.html.twig';
|
||||
|
||||
$session = $request->getSession();
|
||||
$postMessage = $session->get('mautic.integration.postauth.message');
|
||||
$userData = [];
|
||||
|
||||
if (isset($integration)) {
|
||||
$userData = $session->get('mautic.integration.'.$integration.'.userdata');
|
||||
}
|
||||
|
||||
$message = $type = '';
|
||||
$alert = 'success';
|
||||
if (!empty($postMessage)) {
|
||||
$message = $this->translator->trans($postMessage[0], $postMessage[1], 'flashes');
|
||||
$session->remove('mautic.integration.postauth.message');
|
||||
$type = $postMessage[2];
|
||||
if ('error' == $type) {
|
||||
$alert = 'danger';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render($postAuthTemplate, ['message' => $message, 'alert' => $alert, 'data' => $userData]);
|
||||
}
|
||||
|
||||
public function authUserAction(IntegrationHelper $integrationHelper, $integration): RedirectResponse
|
||||
{
|
||||
$integrationObject = $integrationHelper->getIntegrationObject($integration);
|
||||
|
||||
$settings['method'] = 'GET';
|
||||
$settings['integration'] = $integrationObject->getName();
|
||||
|
||||
/** @var \Mautic\PluginBundle\Integration\AbstractIntegration $integrationObject */
|
||||
$event = $this->dispatcher->dispatch(
|
||||
new PluginIntegrationAuthRedirectEvent(
|
||||
$integrationObject,
|
||||
$integrationObject->getAuthLoginUrl()
|
||||
),
|
||||
PluginEvents::PLUGIN_ON_INTEGRATION_AUTH_REDIRECT
|
||||
);
|
||||
$oauthUrl = $event->getAuthUrl();
|
||||
|
||||
return new RedirectResponse($oauthUrl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,464 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\PluginBundle\Controller;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Mautic\CoreBundle\Controller\FormController;
|
||||
use Mautic\CoreBundle\Helper\InputHelper;
|
||||
use Mautic\PluginBundle\Event\PluginIntegrationAuthRedirectEvent;
|
||||
use Mautic\PluginBundle\Event\PluginIntegrationEvent;
|
||||
use Mautic\PluginBundle\Facade\ReloadFacade;
|
||||
use Mautic\PluginBundle\Form\Type\DetailsType;
|
||||
use Mautic\PluginBundle\Helper\IntegrationHelper;
|
||||
use Mautic\PluginBundle\Integration\AbstractIntegration;
|
||||
use Mautic\PluginBundle\Model\PluginModel;
|
||||
use Mautic\PluginBundle\PluginEvents;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class PluginController extends FormController
|
||||
{
|
||||
/**
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function indexAction(Request $request, IntegrationHelper $integrationHelper)
|
||||
{
|
||||
if (!$this->security->isGranted('plugin:plugins:manage')) {
|
||||
return $this->accessDenied();
|
||||
}
|
||||
|
||||
/** @var PluginModel $pluginModel */
|
||||
$pluginModel = $this->getModel('plugin');
|
||||
|
||||
// List of plugins for filter and to show as a single integration
|
||||
$plugins = $pluginModel->getEntities(
|
||||
[
|
||||
'filter' => [
|
||||
'force' => [
|
||||
[
|
||||
'column' => 'p.isMissing',
|
||||
'expr' => 'eq',
|
||||
'value' => 0,
|
||||
],
|
||||
],
|
||||
],
|
||||
'hydration_mode' => 'hydrate_array',
|
||||
]
|
||||
);
|
||||
|
||||
$session = $request->getSession();
|
||||
$pluginFilter = $request->get('plugin', $session->get('mautic.integrations.filter', ''));
|
||||
|
||||
$session->set('mautic.integrations.filter', $pluginFilter);
|
||||
|
||||
$integrationObjects = $integrationHelper->getIntegrationObjects(null, null, true);
|
||||
$integrations = $foundPlugins = [];
|
||||
|
||||
foreach ($integrationObjects as $name => $object) {
|
||||
$settings = $object->getIntegrationSettings();
|
||||
$plugin = $settings->getPlugin();
|
||||
$pluginId = $plugin ? $plugin->getId() : $name;
|
||||
if (isset($plugins[$pluginId]) || $pluginId === $name) {
|
||||
$integrations[$name] = [
|
||||
'name' => $object->getName(),
|
||||
'display' => $object->getDisplayName(),
|
||||
'icon' => $integrationHelper->getIconPath($object),
|
||||
'enabled' => $settings->isPublished(),
|
||||
'plugin' => $pluginId,
|
||||
'isBundle' => false,
|
||||
];
|
||||
}
|
||||
|
||||
$foundPlugins[$pluginId] = true;
|
||||
}
|
||||
|
||||
$nonIntegrationPlugins = array_diff_key($plugins, $foundPlugins);
|
||||
foreach ($nonIntegrationPlugins as $plugin) {
|
||||
$integrations[$plugin['name']] = [
|
||||
'name' => $plugin['bundle'],
|
||||
'display' => $plugin['name'],
|
||||
'icon' => $integrationHelper->getIconPath($plugin),
|
||||
'enabled' => true,
|
||||
'plugin' => $plugin['id'],
|
||||
'description' => $plugin['description'],
|
||||
'isBundle' => true,
|
||||
];
|
||||
}
|
||||
|
||||
// sort by name
|
||||
uksort(
|
||||
$integrations,
|
||||
fn ($a, $b): int => strnatcasecmp($a, $b)
|
||||
);
|
||||
|
||||
$tmpl = $request->isXmlHttpRequest() ? $request->get('tmpl', 'index') : 'index';
|
||||
|
||||
if (!empty($pluginFilter)) {
|
||||
foreach ($plugins as $plugin) {
|
||||
if ($plugin['id'] == $pluginFilter) {
|
||||
$pluginName = $plugin['name'];
|
||||
$pluginId = $plugin['id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->delegateView(
|
||||
[
|
||||
'viewParameters' => [
|
||||
'items' => $integrations,
|
||||
'tmpl' => $tmpl,
|
||||
'pluginFilter' => ($pluginFilter) ? ['id' => $pluginId, 'name' => $pluginName] : false,
|
||||
'plugins' => $plugins,
|
||||
],
|
||||
'contentTemplate' => '@MauticPlugin/Integration/grid.html.twig',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mautic_plugin_index',
|
||||
'mauticContent' => 'integration',
|
||||
'route' => $this->generateUrl('mautic_plugin_index'),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function configAction(Request $request, EntityManagerInterface $em, IntegrationHelper $integrationHelper, LoggerInterface $mauticLogger, $name, $activeTab = 'details-container', $page = 1)
|
||||
{
|
||||
if (!$this->security->isGranted('plugin:plugins:manage')) {
|
||||
return $this->accessDenied();
|
||||
}
|
||||
if (!empty($request->get('activeTab'))) {
|
||||
$activeTab = $request->get('activeTab');
|
||||
}
|
||||
|
||||
$session = $request->getSession();
|
||||
|
||||
$integrationDetailsPost = $request->request->all()['integration_details'] ?? [];
|
||||
$authorize = empty($integrationDetailsPost['in_auth']) ? false : true;
|
||||
|
||||
/** @var AbstractIntegration $integrationObject */
|
||||
$integrationObject = $integrationHelper->getIntegrationObject($name);
|
||||
|
||||
// Verify that the requested integration exists
|
||||
if (empty($integrationObject)) {
|
||||
throw $this->createNotFoundException($this->translator->trans('mautic.core.url.error.404'));
|
||||
}
|
||||
|
||||
$object = ('leadFieldsContainer' === $activeTab) ? 'lead' : 'company';
|
||||
$limit = $this->coreParametersHelper->get('default_pagelimit');
|
||||
$start = (1 === $page) ? 0 : (($page - 1) * $limit);
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
$session->set('mautic.plugin.'.$name.'.'.$object.'.start', $start);
|
||||
$session->set('mautic.plugin.'.$name.'.'.$object.'.page', $page);
|
||||
|
||||
/** @var PluginModel $pluginModel */
|
||||
$pluginModel = $this->getModel('plugin');
|
||||
$leadFields = $pluginModel->getLeadFields();
|
||||
$companyFields = $pluginModel->getCompanyFields();
|
||||
/** @var AbstractIntegration $integrationObject */
|
||||
$entity = $integrationObject->getIntegrationSettings();
|
||||
$existingPublishedState = $entity->getIsPublished();
|
||||
$form = $this->createForm(
|
||||
DetailsType::class,
|
||||
$entity,
|
||||
[
|
||||
'integration' => $entity->getName(),
|
||||
'lead_fields' => $leadFields,
|
||||
'company_fields' => $companyFields,
|
||||
'integration_object' => $integrationObject,
|
||||
'action' => $this->generateUrl('mautic_plugin_config', ['name' => $name]),
|
||||
]
|
||||
);
|
||||
|
||||
if ('POST' == $request->getMethod()) {
|
||||
$valid = false;
|
||||
if (!$cancelled = $this->isFormCancelled($form)) {
|
||||
$currentKeys = $integrationObject->getDecryptedApiKeys($entity);
|
||||
$currentFeatureSettings = $entity->getFeatureSettings();
|
||||
$valid = $this->isFormValid($form);
|
||||
|
||||
if ($authorize || $valid) {
|
||||
$integration = $entity->getName();
|
||||
|
||||
if (isset($form['apiKeys'])) {
|
||||
$keys = $form['apiKeys']->getData();
|
||||
|
||||
// Prevent merged keys
|
||||
$secretKeys = $integrationObject->getSecretKeys();
|
||||
foreach ($secretKeys as $secretKey) {
|
||||
if (empty($keys[$secretKey]) && !empty($currentKeys[$secretKey])) {
|
||||
$keys[$secretKey] = $currentKeys[$secretKey];
|
||||
}
|
||||
}
|
||||
$keys = $this->removeAuthData($keys, $currentKeys, $integrationObject);
|
||||
$integrationObject->encryptAndSetApiKeys($keys, $entity);
|
||||
|
||||
$integrationObject->encryptAndSetApiKeys($keys, $entity);
|
||||
}
|
||||
|
||||
if (!$authorize) {
|
||||
$features = $entity->getSupportedFeatures();
|
||||
if (in_array('public_profile', $features) || in_array('push_lead', $features)) {
|
||||
// Ungroup the fields
|
||||
$mauticLeadFields = [];
|
||||
foreach ($leadFields as $groupFields) {
|
||||
$mauticLeadFields = array_merge($mauticLeadFields, $groupFields);
|
||||
}
|
||||
$mauticCompanyFields = [];
|
||||
foreach ($companyFields as $groupFields) {
|
||||
$mauticCompanyFields = array_merge($mauticCompanyFields, $groupFields);
|
||||
}
|
||||
|
||||
if ($missing = $integrationObject->cleanUpFields($entity, $mauticLeadFields, $mauticCompanyFields)) {
|
||||
if ($entity->getIsPublished()) {
|
||||
// Only fail validation if the integration is enabled
|
||||
if (!empty($missing['leadFields'])) {
|
||||
$valid = false;
|
||||
|
||||
$form->get('featureSettings')->get('leadFields')->addError(
|
||||
new FormError(
|
||||
$this->translator->trans('mautic.plugin.field.required_mapping_missing', [], 'validators')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($missing['companyFields'])) {
|
||||
$valid = false;
|
||||
|
||||
$form->get('featureSettings')->get('companyFields')->addError(
|
||||
new FormError(
|
||||
$this->translator->trans('mautic.plugin.field.required_mapping_missing', [], 'validators')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// make sure they aren't overwritten because of API connection issues
|
||||
$entity->setFeatureSettings($currentFeatureSettings);
|
||||
}
|
||||
|
||||
if ($valid || $authorize) {
|
||||
$dispatcher = $this->dispatcher;
|
||||
$mauticLogger->info('Dispatching integration config save event.');
|
||||
if ($dispatcher->hasListeners(PluginEvents::PLUGIN_ON_INTEGRATION_CONFIG_SAVE)) {
|
||||
$mauticLogger->info('Event dispatcher has integration config save listeners.');
|
||||
if (!$valid && !$existingPublishedState) {
|
||||
$integrationObject->getIntegrationSettings()->setIsPublished(false);
|
||||
}
|
||||
$event = new PluginIntegrationEvent($integrationObject);
|
||||
|
||||
$dispatcher->dispatch($event, PluginEvents::PLUGIN_ON_INTEGRATION_CONFIG_SAVE);
|
||||
|
||||
$entity = $event->getEntity();
|
||||
}
|
||||
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
if ($authorize) {
|
||||
// redirect to the oauth URL
|
||||
/** @var AbstractIntegration $integrationObject */
|
||||
$event = $this->dispatcher->dispatch(
|
||||
new PluginIntegrationAuthRedirectEvent(
|
||||
$integrationObject,
|
||||
$integrationObject->getAuthLoginUrl()
|
||||
),
|
||||
PluginEvents::PLUGIN_ON_INTEGRATION_AUTH_REDIRECT
|
||||
);
|
||||
$oauthUrl = $event->getAuthUrl();
|
||||
|
||||
return new JsonResponse(
|
||||
[
|
||||
'integration' => $integration,
|
||||
'authUrl' => $oauthUrl,
|
||||
'authorize' => 1,
|
||||
'popupBlockerMessage' => $this->translator->trans('mautic.core.popupblocked'),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (($cancelled || ($valid && !$this->isFormApplied($form))) && !$authorize) {
|
||||
// Close the modal and return back to the list view
|
||||
return new JsonResponse(
|
||||
[
|
||||
'closeModal' => 1,
|
||||
'enabled' => $entity->getIsPublished(),
|
||||
'name' => $integrationObject->getName(),
|
||||
'mauticContent' => 'integrationConfig',
|
||||
'sidebar' => $this->renderView('@MauticCore/LeftPanel/index.html.twig'),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$template = $integrationObject->getFormTemplate();
|
||||
$objectTheme = $integrationObject->getFormTheme();
|
||||
$themes = [
|
||||
'@MauticPlugin/FormTheme/Integration/layout.html.twig',
|
||||
];
|
||||
if (is_array($objectTheme)) {
|
||||
$themes = array_merge($themes, $objectTheme);
|
||||
} elseif (is_string($objectTheme)) {
|
||||
$themes[] = $objectTheme;
|
||||
}
|
||||
$themes = array_unique($themes);
|
||||
|
||||
$formSettings = $integrationObject->getFormSettings();
|
||||
$callbackUrl = !empty($formSettings['requires_callback']) ? $integrationObject->getAuthCallbackUrl() : '';
|
||||
|
||||
$formNotes = [];
|
||||
$noteSections = ['authorization', 'features', 'feature_settings', 'custom'];
|
||||
foreach ($noteSections as $section) {
|
||||
if ('custom' === $section) {
|
||||
$formNotes[$section] = $integrationObject->getFormNotes($section);
|
||||
} else {
|
||||
[$specialInstructions, $alertType] = $integrationObject->getFormNotes($section);
|
||||
|
||||
if (!empty($specialInstructions)) {
|
||||
$formNotes[$section] = [
|
||||
'note' => $specialInstructions,
|
||||
'type' => $alertType,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->delegateView(
|
||||
[
|
||||
'viewParameters' => [
|
||||
'form' => $form->createView(),
|
||||
'description' => $integrationObject->getDescription(),
|
||||
'formSettings' => $formSettings,
|
||||
'formNotes' => $formNotes,
|
||||
'callbackUrl' => $callbackUrl,
|
||||
'activeTab' => $activeTab,
|
||||
'formThemes' => $themes,
|
||||
],
|
||||
'contentTemplate' => $template,
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mautic_plugin_index',
|
||||
'mauticContent' => 'integrationConfig',
|
||||
'route' => false,
|
||||
'sidebar' => $this->renderView('@MauticCore/LeftPanel/index.html.twig'),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|JsonResponse|RedirectResponse|Response
|
||||
*/
|
||||
public function infoAction(IntegrationHelper $integrationHelper, $name)
|
||||
{
|
||||
if (!$this->security->isGranted('plugin:plugins:manage')) {
|
||||
return $this->accessDenied();
|
||||
}
|
||||
|
||||
/** @var PluginModel $pluginModel */
|
||||
$pluginModel = $this->getModel('plugin');
|
||||
|
||||
$bundle = $pluginModel->getRepository()->findOneBy(
|
||||
[
|
||||
'bundle' => InputHelper::clean($name),
|
||||
]
|
||||
);
|
||||
|
||||
if (!$bundle) {
|
||||
return $this->accessDenied();
|
||||
}
|
||||
|
||||
$bundle->splitDescriptions();
|
||||
|
||||
return $this->delegateView(
|
||||
[
|
||||
'viewParameters' => [
|
||||
'bundle' => $bundle,
|
||||
'icon' => $integrationHelper->getIconPath($bundle),
|
||||
],
|
||||
'contentTemplate' => '@MauticPlugin/Integration/info.html.twig',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mautic_plugin_index',
|
||||
'mauticContent' => 'integration',
|
||||
'route' => false,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the addon bundles directly and loads bundles which are not registered to the database.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function reloadAction(Request $request, ReloadFacade $reloadFacade)
|
||||
{
|
||||
if (!$this->security->isGranted('plugin:plugins:manage')) {
|
||||
return $this->accessDenied();
|
||||
}
|
||||
|
||||
$this->addFlashMessage(
|
||||
$reloadFacade->reloadPlugins()
|
||||
);
|
||||
|
||||
$viewParameters = [
|
||||
'page' => $request->getSession()->get('mautic.plugin.page'),
|
||||
];
|
||||
|
||||
// Refresh the index contents
|
||||
return $this->postActionRedirect(
|
||||
[
|
||||
'returnUrl' => $this->generateUrl('mautic_plugin_index', $viewParameters),
|
||||
'viewParameters' => $viewParameters,
|
||||
'contentTemplate' => 'Mautic\PluginBundle\Controller\PluginController::indexAction',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mautic_plugin_index',
|
||||
'mauticContent' => 'plugin',
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array <string,mixed> $keys
|
||||
* @param array <string,mixed> $currentKeys
|
||||
*
|
||||
* @return array <string,mixed>
|
||||
*
|
||||
* @phpstan-ignore-next-line Ignore as AbstractIntegration is deprecated
|
||||
*/
|
||||
private function removeAuthData(array $keys, array $currentKeys, AbstractIntegration $integrationObject): array
|
||||
{
|
||||
$resetTokens = false;
|
||||
$secretKeys = array_unique(array_merge($integrationObject->getSecretKeys(), [$integrationObject->getClientIdKey()]));
|
||||
|
||||
foreach ($secretKeys as $secretKey) {
|
||||
if (($keys[$secretKey] ?? null) !== ($currentKeys[$secretKey] ?? null)) {
|
||||
$resetTokens = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$resetTokens) {
|
||||
return $keys;
|
||||
}
|
||||
|
||||
$keysToRemove = array_unique(array_merge($integrationObject->getRefreshTokenKeys(), [$integrationObject->getAuthTokenKey()]));
|
||||
|
||||
return array_diff_key($keys, array_flip($keysToRemove));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user