Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\ChannelBundle\Controller;
|
||||
|
||||
use Mautic\ChannelBundle\Model\MessageQueueModel;
|
||||
use Mautic\CoreBundle\Controller\AjaxController as CommonAjaxController;
|
||||
use Mautic\CoreBundle\Controller\AjaxLookupControllerTrait;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class AjaxController extends CommonAjaxController
|
||||
{
|
||||
use AjaxLookupControllerTrait;
|
||||
|
||||
public function cancelQueuedMessageEventAction(Request $request): JsonResponse
|
||||
{
|
||||
$dataArray = ['success' => 0];
|
||||
$messageQueueId = (int) $request->request->get('channelId');
|
||||
$queueModel = $this->getModel('channel.queue');
|
||||
\assert($queueModel instanceof MessageQueueModel);
|
||||
$queuedMessage = $queueModel->getEntity($messageQueueId);
|
||||
if ($queuedMessage) {
|
||||
$queuedMessage->setStatus('cancelled');
|
||||
$queueModel->saveEntity($queuedMessage);
|
||||
$dataArray = ['success' => 1];
|
||||
}
|
||||
|
||||
return $this->sendJsonResponse($dataArray);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\ChannelBundle\Controller\Api;
|
||||
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Mautic\ApiBundle\Controller\CommonApiController;
|
||||
use Mautic\ApiBundle\Helper\EntityResultHelper;
|
||||
use Mautic\ChannelBundle\ChannelEvents;
|
||||
use Mautic\ChannelBundle\Entity\Message;
|
||||
use Mautic\ChannelBundle\Event\ChannelEvent;
|
||||
use Mautic\ChannelBundle\Model\MessageModel;
|
||||
use Mautic\CoreBundle\Factory\ModelFactory;
|
||||
use Mautic\CoreBundle\Helper\AppVersion;
|
||||
use Mautic\CoreBundle\Helper\CoreParametersHelper;
|
||||
use Mautic\CoreBundle\Security\Permissions\CorePermissions;
|
||||
use Mautic\CoreBundle\Translation\Translator;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
|
||||
/**
|
||||
* @extends CommonApiController<Message>
|
||||
*/
|
||||
class MessageApiController extends CommonApiController
|
||||
{
|
||||
/**
|
||||
* @var MessageModel|null
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
public function __construct(
|
||||
CorePermissions $security,
|
||||
Translator $translator,
|
||||
EntityResultHelper $entityResultHelper,
|
||||
RouterInterface $router,
|
||||
FormFactoryInterface $formFactory,
|
||||
AppVersion $appVersion,
|
||||
private RequestStack $requestStack,
|
||||
ManagerRegistry $doctrine,
|
||||
ModelFactory $modelFactory,
|
||||
EventDispatcherInterface $dispatcher,
|
||||
CoreParametersHelper $coreParametersHelper,
|
||||
) {
|
||||
$messageModel = $modelFactory->getModel('channel.message');
|
||||
\assert($messageModel instanceof MessageModel);
|
||||
$this->model = $messageModel;
|
||||
$this->entityClass = Message::class;
|
||||
$this->entityNameOne = 'message';
|
||||
$this->entityNameMulti = 'messages';
|
||||
$this->serializerGroups = ['messageDetails', 'messageChannelList', 'categoryList', 'publishDetails'];
|
||||
|
||||
parent::__construct($security, $translator, $entityResultHelper, $router, $formFactory, $appVersion, $requestStack, $doctrine, $modelFactory, $dispatcher, $coreParametersHelper);
|
||||
}
|
||||
|
||||
protected function prepareParametersFromRequest(FormInterface $form, array &$params, ?object $entity = null, array $masks = [], array $fields = []): void
|
||||
{
|
||||
parent::prepareParametersFromRequest($form, $params, $entity, $masks);
|
||||
|
||||
if ('PATCH' === $this->requestStack->getCurrentRequest()->getMethod() && !isset($params['channels'])) {
|
||||
return;
|
||||
} elseif (!isset($params['channels'])) {
|
||||
$params['channels'] = [];
|
||||
}
|
||||
|
||||
$channels = $this->model->getChannels();
|
||||
|
||||
foreach ($channels as $channelType => $channel) {
|
||||
if (!isset($params['channels'][$channelType])) {
|
||||
$params['channels'][$channelType] = ['isEnabled' => 0];
|
||||
} else {
|
||||
$params['channels'][$channelType]['isEnabled'] = (int) $params['channels'][$channelType]['isEnabled'];
|
||||
}
|
||||
$params['channels'][$channelType]['channel'] = $channelType;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and set channel names to the response.
|
||||
*/
|
||||
protected function preSerializeEntity(object $entity, string $action = 'view'): void
|
||||
{
|
||||
$event = $this->dispatcher->dispatch(new ChannelEvent(), ChannelEvents::ADD_CHANNEL);
|
||||
|
||||
foreach ($entity->getChannels() as $channel) {
|
||||
$repository = $event->getRepositoryName($channel->getChannel());
|
||||
$nameColumn = $event->getNameColumn($channel->getChannel());
|
||||
$name = $this->model->getChannelName($channel->getChannelId(), $repository, $nameColumn);
|
||||
$channel->setChannelName($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\ChannelBundle\Controller;
|
||||
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Mautic\ChannelBundle\Model\ChannelActionModel;
|
||||
use Mautic\ChannelBundle\Model\FrequencyActionModel;
|
||||
use Mautic\CoreBundle\Controller\AbstractFormController;
|
||||
use Mautic\CoreBundle\Factory\ModelFactory;
|
||||
use Mautic\CoreBundle\Helper\CoreParametersHelper;
|
||||
use Mautic\CoreBundle\Helper\UserHelper;
|
||||
use Mautic\CoreBundle\Security\Permissions\CorePermissions;
|
||||
use Mautic\CoreBundle\Service\FlashBag;
|
||||
use Mautic\CoreBundle\Translation\Translator;
|
||||
use Mautic\LeadBundle\Form\Type\ContactChannelsType;
|
||||
use Mautic\LeadBundle\Model\LeadModel;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
class BatchContactController extends AbstractFormController
|
||||
{
|
||||
public function __construct(
|
||||
private ChannelActionModel $channelActionModel,
|
||||
private FrequencyActionModel $frequencyActionModel,
|
||||
private LeadModel $contactModel,
|
||||
ManagerRegistry $doctrine,
|
||||
ModelFactory $modelFactory,
|
||||
UserHelper $userHelper,
|
||||
CoreParametersHelper $coreParametersHelper,
|
||||
EventDispatcherInterface $dispatcher,
|
||||
Translator $translator,
|
||||
FlashBag $flashBag,
|
||||
RequestStack $requestStack,
|
||||
CorePermissions $security,
|
||||
) {
|
||||
parent::__construct($doctrine, $modelFactory, $userHelper, $coreParametersHelper, $dispatcher, $translator, $flashBag, $requestStack, $security);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the batch action.
|
||||
*/
|
||||
public function setAction(Request $request): JsonResponse
|
||||
{
|
||||
$params = $request->get('contact_channels', []);
|
||||
$ids = empty($params['ids']) ? [] : json_decode($params['ids']);
|
||||
|
||||
if ($ids && is_array($ids)) {
|
||||
$subscribedChannels = $params['subscribed_channels'] ?? [];
|
||||
$preferredChannel = $params['preferred_channel'] ?? null;
|
||||
|
||||
$this->channelActionModel->update($ids, $subscribedChannels);
|
||||
$this->frequencyActionModel->update($ids, $params, $preferredChannel);
|
||||
|
||||
$this->addFlashMessage('mautic.lead.batch_leads_affected', [
|
||||
'%count%' => count($ids),
|
||||
]);
|
||||
} else {
|
||||
$this->addFlashMessage('mautic.core.error.ids.missing');
|
||||
}
|
||||
|
||||
return new JsonResponse([
|
||||
'closeModal' => true,
|
||||
'flashes' => $this->getFlashContent(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* View for batch action.
|
||||
*/
|
||||
public function indexAction(): \Symfony\Component\HttpFoundation\Response
|
||||
{
|
||||
$route = $this->generateUrl('mautic_channel_batch_contact_set');
|
||||
|
||||
return $this->delegateView([
|
||||
'viewParameters' => [
|
||||
'form' => $this->createForm(ContactChannelsType::class, [], [
|
||||
'action' => $route,
|
||||
'channels' => $this->contactModel->getPreferenceChannels(),
|
||||
'public_view' => false,
|
||||
'save_button' => true,
|
||||
])->createView(),
|
||||
],
|
||||
'contentTemplate' => '@MauticLead/Batch/channel.html.twig',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mautic_contact_index',
|
||||
'mauticContent' => 'leadBatch',
|
||||
'route' => $route,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\ChannelBundle\Controller;
|
||||
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Mautic\ChannelBundle\Entity\Channel;
|
||||
use Mautic\ChannelBundle\Model\MessageModel;
|
||||
use Mautic\CoreBundle\Controller\AbstractStandardFormController;
|
||||
use Mautic\CoreBundle\Factory\ModelFactory;
|
||||
use Mautic\CoreBundle\Factory\PageHelperFactoryInterface;
|
||||
use Mautic\CoreBundle\Helper\Chart\LineChart;
|
||||
use Mautic\CoreBundle\Helper\CoreParametersHelper;
|
||||
use Mautic\CoreBundle\Helper\UserHelper;
|
||||
use Mautic\CoreBundle\Security\Permissions\CorePermissions;
|
||||
use Mautic\CoreBundle\Service\FlashBag;
|
||||
use Mautic\CoreBundle\Translation\Translator;
|
||||
use Mautic\FormBundle\Helper\FormFieldHelper;
|
||||
use Mautic\LeadBundle\Controller\EntityContactsTrait;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class MessageController extends AbstractStandardFormController
|
||||
{
|
||||
use EntityContactsTrait;
|
||||
|
||||
public function __construct(
|
||||
FormFactoryInterface $formFactory,
|
||||
FormFieldHelper $fieldHelper,
|
||||
ManagerRegistry $doctrine,
|
||||
ModelFactory $modelFactory,
|
||||
UserHelper $userHelper,
|
||||
CoreParametersHelper $coreParametersHelper,
|
||||
EventDispatcherInterface $dispatcher,
|
||||
Translator $translator,
|
||||
FlashBag $flashBag,
|
||||
private RequestStack $requestStack,
|
||||
CorePermissions $security,
|
||||
) {
|
||||
parent::__construct($formFactory, $fieldHelper, $doctrine, $modelFactory, $userHelper, $coreParametersHelper, $dispatcher, $translator, $flashBag, $requestStack, $security);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function batchDeleteAction(Request $request)
|
||||
{
|
||||
return $this->batchDeleteStandard($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Mautic\CoreBundle\Controller\Response|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function cloneAction(Request $request, $objectId)
|
||||
{
|
||||
return $this->cloneStandard($request, $objectId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $ignorePost
|
||||
*
|
||||
* @return \Mautic\CoreBundle\Controller\Response|\Symfony\Component\HttpFoundation\JsonResponse
|
||||
*/
|
||||
public function editAction(Request $request, $objectId, $ignorePost = false)
|
||||
{
|
||||
return $this->editStandard($request, $objectId, $ignorePost);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
*/
|
||||
public function indexAction(Request $request, $page = 1): Response
|
||||
{
|
||||
return $this->indexStandard($request, $page);
|
||||
}
|
||||
|
||||
public function newAction(Request $request): Response
|
||||
{
|
||||
return $this->newStandard($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function viewAction(Request $request, $objectId)
|
||||
{
|
||||
return $this->viewStandard($request, $objectId, 'message', 'channel');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
protected function getViewArguments(array $args, $action): array
|
||||
{
|
||||
/** @var MessageModel $model */
|
||||
$model = $this->getModel($this->getModelName());
|
||||
$viewParameters = [];
|
||||
switch ($action) {
|
||||
case 'index':
|
||||
$viewParameters = [
|
||||
'headerTitle' => $this->translator->trans('mautic.channel.messages'),
|
||||
'listHeaders' => [
|
||||
[
|
||||
'text' => 'mautic.core.channels',
|
||||
'class' => 'visible-md visible-lg',
|
||||
],
|
||||
],
|
||||
'listItemTemplate' => '@MauticChannel/Message/list_item.html.twig',
|
||||
'enableCloneButton' => true,
|
||||
];
|
||||
|
||||
break;
|
||||
case 'view':
|
||||
$message = $args['viewParameters']['item'];
|
||||
|
||||
// Init the date range filter form
|
||||
$returnUrl = $this->generateUrl(
|
||||
'mautic_message_action',
|
||||
[
|
||||
'objectAction' => 'view',
|
||||
'objectId' => $message->getId(),
|
||||
]
|
||||
);
|
||||
|
||||
[$dateFrom, $dateTo] = $this->getViewDateRange($this->requestStack->getCurrentRequest(), $message->getId(), $returnUrl, 'local', $dateRangeForm);
|
||||
$chart = new LineChart(null, $dateFrom, $dateTo);
|
||||
|
||||
/** @var Channel[] $channels */
|
||||
$channels = $model->getChannels();
|
||||
$messageChannels = $message->getChannels();
|
||||
$chart->setDataset(
|
||||
$this->translator->trans('mautic.core.all'),
|
||||
$model->getLeadStatsPost($message->getId(), $dateFrom, $dateTo)
|
||||
);
|
||||
|
||||
$messagedLeads = [
|
||||
'all' => $this->forward(
|
||||
'Mautic\ChannelBundle\Controller\MessageController::contactsAction',
|
||||
[
|
||||
'objectId' => $message->getId(),
|
||||
'page' => $this->requestStack->getCurrentRequest()->getSession()->get('mautic.'.$this->getSessionBase('all').'.contact.page', 1),
|
||||
'ignoreAjax' => true,
|
||||
'channel' => 'all',
|
||||
]
|
||||
)->getContent(),
|
||||
];
|
||||
|
||||
foreach ($messageChannels as $channel) {
|
||||
if ($channel->isEnabled() && isset($channels[$channel->getChannel()])) {
|
||||
$chart->setDataset(
|
||||
$channels[$channel->getChannel()]['label'],
|
||||
$model->getLeadStatsPost($message->getId(), $dateFrom, $dateTo, $channel->getChannel())
|
||||
);
|
||||
|
||||
$messagedLeads[$channel->getChannel()] = $this->forward(
|
||||
'Mautic\ChannelBundle\Controller\MessageController::contactsAction',
|
||||
[
|
||||
'objectId' => $message->getId(),
|
||||
'page' => $this->requestStack->getCurrentRequest()->getSession()->get(
|
||||
'mautic.'.$this->getSessionBase($channel->getChannel()).'.contact.page',
|
||||
1
|
||||
),
|
||||
'ignoreAjax' => true,
|
||||
'channel' => $channel->getChannel(),
|
||||
]
|
||||
)->getContent();
|
||||
}
|
||||
}
|
||||
|
||||
$viewParameters = [
|
||||
'channels' => $channels,
|
||||
'channelContents' => $model->getMessageChannels($message->getId()),
|
||||
'dateRangeForm' => $dateRangeForm->createView(),
|
||||
'eventCounts' => $chart->render(),
|
||||
'messagedLeads' => $messagedLeads,
|
||||
];
|
||||
break;
|
||||
case 'new':
|
||||
case 'edit':
|
||||
$viewParameters = [
|
||||
'channels' => $model->getChannels(),
|
||||
];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$args['viewParameters'] = array_merge($args['viewParameters'], $viewParameters);
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function deleteAction(Request $request, $objectId)
|
||||
{
|
||||
return $this->deleteStandard($request, $objectId);
|
||||
}
|
||||
|
||||
protected function getTemplateBase(): string
|
||||
{
|
||||
return '@MauticChannel/Message';
|
||||
}
|
||||
|
||||
protected function getFormView(FormInterface $form, $view): FormView
|
||||
{
|
||||
return $form->createView();
|
||||
}
|
||||
|
||||
protected function getJsLoadMethodPrefix(): string
|
||||
{
|
||||
return 'messages';
|
||||
}
|
||||
|
||||
protected function getModelName(): string
|
||||
{
|
||||
return 'channel.message';
|
||||
}
|
||||
|
||||
protected function getRouteBase(): string
|
||||
{
|
||||
return 'message';
|
||||
}
|
||||
|
||||
/***
|
||||
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSessionBase($objectId = null): string
|
||||
{
|
||||
return 'message'.(($objectId) ? '.'.$objectId : '');
|
||||
}
|
||||
|
||||
protected function getTranslationBase(): string
|
||||
{
|
||||
return 'mautic.channel.message';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
*
|
||||
* @return JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function contactsAction(
|
||||
Request $request,
|
||||
PageHelperFactoryInterface $pageHelperFactory,
|
||||
$objectId,
|
||||
$channel,
|
||||
$page = 1,
|
||||
) {
|
||||
$filter = [];
|
||||
if ('all' !== $channel) {
|
||||
$returnUrl = $this->generateUrl(
|
||||
'mautic_message_action',
|
||||
[
|
||||
'objectAction' => 'view',
|
||||
'objectId' => $objectId,
|
||||
]
|
||||
);
|
||||
[$dateFrom, $dateTo] = $this->getViewDateRange($request, $objectId, $returnUrl, 'UTC');
|
||||
|
||||
$filter = [
|
||||
'channel' => $channel,
|
||||
[
|
||||
'col' => 'entity.date_triggered',
|
||||
'expr' => 'between',
|
||||
'val' => [
|
||||
$dateFrom->format('Y-m-d H:i:s'),
|
||||
$dateTo->format('Y-m-d H:i:s'),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $this->generateContactsGrid(
|
||||
$request,
|
||||
$pageHelperFactory,
|
||||
$objectId,
|
||||
$page,
|
||||
'channel:messages:view',
|
||||
'message.'.$channel,
|
||||
'campaign_lead_event_log',
|
||||
$channel,
|
||||
null,
|
||||
$filter,
|
||||
[
|
||||
[
|
||||
'type' => 'join',
|
||||
'from_alias' => 'entity',
|
||||
'table' => 'campaign_events',
|
||||
'alias' => 'event',
|
||||
'condition' => "entity.event_id = event.id and event.channel = 'channel.message' and event.channel_id = ".(int) $objectId,
|
||||
],
|
||||
],
|
||||
null,
|
||||
[
|
||||
'channel' => $channel ?: 'all',
|
||||
],
|
||||
'.message-'.$channel
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user