Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions Command/CustomItemsScheduledExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace MauticPlugin\CustomObjectsBundle\Command;

use Mautic\CoreBundle\Helper\ExitCode;
use Mautic\CoreBundle\Templating\Helper\FormatterHelper;
use Mautic\CoreBundle\Twig\Helper\FormatterHelper;
use MauticPlugin\CustomObjectsBundle\CustomItemEvents;
use MauticPlugin\CustomObjectsBundle\Event\CustomItemExportSchedulerEvent;
use MauticPlugin\CustomObjectsBundle\Model\CustomItemExportSchedulerModel;
Expand All @@ -18,20 +17,11 @@
class CustomItemsScheduledExportCommand extends Command
{
public const COMMAND_NAME = 'mautic:custom_items:scheduled_export';

private CustomItemExportSchedulerModel $customItemExportSchedulerModel;
private EventDispatcherInterface $eventDispatcher;
private FormatterHelper $formatterHelper;

public function __construct(
CustomItemExportSchedulerModel $customItemExportSchedulerModel,
EventDispatcherInterface $eventDispatcher,
FormatterHelper $formatterHelper
private CustomItemExportSchedulerModel $customItemExportSchedulerModel,
private EventDispatcherInterface $eventDispatcher,
private FormatterHelper $formatterHelper
) {
$this->customItemExportSchedulerModel = $customItemExportSchedulerModel;
$this->eventDispatcher = $eventDispatcher;
$this->formatterHelper = $formatterHelper;

parent::__construct();
}

Expand All @@ -58,14 +48,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int

foreach ($customItemExportSchedulers as $customItemExportScheduler) {
$customItemExportSchedulerEvent = new CustomItemExportSchedulerEvent($customItemExportScheduler);
$this->eventDispatcher->dispatch(CustomItemEvents::CUSTOM_ITEM_PREPARE_EXPORT_FILE, $customItemExportSchedulerEvent);
$this->eventDispatcher->dispatch(CustomItemEvents::CUSTOM_ITEM_MAIL_EXPORT_FILE, $customItemExportSchedulerEvent);
$this->eventDispatcher->dispatch(CustomItemEvents::POST_EXPORT_MAIL_SENT, $customItemExportSchedulerEvent);
$this->eventDispatcher->dispatch($customItemExportSchedulerEvent, CustomItemEvents::CUSTOM_ITEM_PREPARE_EXPORT_FILE);
$this->eventDispatcher->dispatch($customItemExportSchedulerEvent, CustomItemEvents::CUSTOM_ITEM_MAIL_EXPORT_FILE);
$this->eventDispatcher->dispatch($customItemExportSchedulerEvent, CustomItemEvents::POST_EXPORT_MAIL_SENT);
++$count;
}

$output->writeln('CustomItem export email(s) sent: '.$count);

return ExitCode::SUCCESS;
return Command::SUCCESS;
}
}
9 changes: 3 additions & 6 deletions Command/GenerateSampleDataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
namespace MauticPlugin\CustomObjectsBundle\Command;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\ORM\EntityManager;
use MauticPlugin\CustomObjectsBundle\Helper\RandomHelper;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;

class GenerateSampleDataCommand extends ContainerAwareCommand
class GenerateSampleDataCommand extends Command
{
/**
* @var EntityManager
Expand Down Expand Up @@ -67,7 +66,7 @@ protected function configure(): void
parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$enquirer = $this->getHelper('question');
Expand Down Expand Up @@ -112,7 +111,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
/**
* @return int[]
*
* @throws DBALException
*/
private function createCustomObjectsWithItems(): array
{
Expand Down Expand Up @@ -222,7 +220,6 @@ private function generateProductRelations(int $contactId, int $coProductId, int
/**
* @return int Last inserted row ID
*
* @throws DBALException
*/
private function insertInto(string $table, array $row): int
{
Expand Down
561 changes: 43 additions & 518 deletions Config/config.php

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions Config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

use Mautic\CoreBundle\DependencyInjection\MauticCoreExtension;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return function (ContainerConfigurator $configurator): void {
$services = $configurator->services()
->defaults()
->autowire()
->autoconfigure()
->public();

$excludes = [
'Serializer',
'Report',
'Extension'
];

$services->load('MauticPlugin\\CustomObjectsBundle\\', '../')
->exclude('../{'.implode(',', array_merge(MauticCoreExtension::DEFAULT_EXCLUDES, $excludes)).'}');

$services->load('MauticPlugin\\CustomObjectsBundle\\Repository\\', '../Repository/*Repository.php')
->tag(Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG);

$services->alias('mautic.custom.model.field', MauticPlugin\CustomObjectsBundle\Model\CustomFieldModel::class);
$services->alias('mautic.custom.model.field.value', MauticPlugin\CustomObjectsBundle\Model\CustomFieldValueModel::class);
$services->alias('mautic.custom.model.item', MauticPlugin\CustomObjectsBundle\Model\CustomItemModel::class);
$services->alias('mautic.custom.model.import.item', MauticPlugin\CustomObjectsBundle\Model\CustomItemImportModel::class);
$services->alias('mautic.custom.model.import.xref.contact', MauticPlugin\CustomObjectsBundle\Model\CustomItemXrefContactModel::class);
$services->alias('mautic.custom.model.field.option', MauticPlugin\CustomObjectsBundle\Model\CustomFieldOptionModel::class);
$services->alias('mautic.custom.model.object', MauticPlugin\CustomObjectsBundle\Model\CustomObjectModel::class);
$services->alias('mautic.custom.model.export_scheduler', MauticPlugin\CustomObjectsBundle\Model\CustomItemExportSchedulerModel::class);

$services->alias('custom_field.repository', MauticPlugin\CustomObjectsBundle\Repository\CustomFieldRepository::class);
$services->alias('custom_item.repository', MauticPlugin\CustomObjectsBundle\Repository\CustomItemRepository::class);
$services->alias('custom_object.repository', MauticPlugin\CustomObjectsBundle\Repository\CustomObjectRepository::class);
$services->alias('custom_item.xref.contact.repository', MauticPlugin\CustomObjectsBundle\Repository\CustomItemXrefContactRepository::class);
$services->alias('custom_item.xref.custom_item.repository', MauticPlugin\CustomObjectsBundle\Repository\CustomItemXrefCustomItemRepository::class);
$services->alias('custom_item_export_scheduler.repository', MauticPlugin\CustomObjectsBundle\Repository\CustomItemExportSchedulerRepository::class);
};
93 changes: 35 additions & 58 deletions Controller/CustomField/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,51 @@

namespace MauticPlugin\CustomObjectsBundle\Controller\CustomField;

use Mautic\CoreBundle\Service\FlashBag;
use Mautic\CoreBundle\Helper\UserHelper;
use Doctrine\Persistence\ManagerRegistry;
use Mautic\CoreBundle\Factory\ModelFactory;
use Mautic\CoreBundle\Translation\Translator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Form\FormFactoryInterface;
use Mautic\CoreBundle\Controller\CommonController;
use MauticPlugin\CustomObjectsBundle\Entity\CustomFieldFactory;
use Mautic\CoreBundle\Helper\CoreParametersHelper;
use Symfony\Component\HttpFoundation\RequestStack;
use MauticPlugin\CustomObjectsBundle\Entity\CustomObject;
use MauticPlugin\CustomObjectsBundle\Exception\ForbiddenException;
use MauticPlugin\CustomObjectsBundle\Exception\NotFoundException;
use MauticPlugin\CustomObjectsBundle\Form\Type\CustomFieldType;
use Mautic\CoreBundle\Security\Permissions\CorePermissions;
use MauticPlugin\CustomObjectsBundle\Model\CustomFieldModel;
use MauticPlugin\CustomObjectsBundle\Model\CustomObjectModel;
use MauticPlugin\CustomObjectsBundle\Provider\CustomFieldPermissionProvider;
use MauticPlugin\CustomObjectsBundle\Entity\CustomFieldFactory;
use MauticPlugin\CustomObjectsBundle\Form\Type\CustomFieldType;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use MauticPlugin\CustomObjectsBundle\Exception\NotFoundException;
use MauticPlugin\CustomObjectsBundle\Exception\ForbiddenException;
use MauticPlugin\CustomObjectsBundle\Provider\CustomFieldRouteProvider;
use MauticPlugin\CustomObjectsBundle\Provider\CustomObjectRouteProvider;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use MauticPlugin\CustomObjectsBundle\Provider\CustomFieldPermissionProvider;

class FormController extends CommonController
{
/**
* @var FormFactory
*/
private $formFactory;

/**
* @var CustomFieldModel
*/
private $customFieldModel;

/**
* @var CustomFieldPermissionProvider
*/
private $permissionProvider;

/**
* @var CustomFieldRouteProvider
*/
private $fieldRouteProvider;

/**
* @var CustomFieldFactory
*/
private $customFieldFactory;

/**
* @var CustomObjectModel
*/
private $customObjectModel;

/**
* @var CustomObjectRouteProvider
*/
private $objectRouteProvider;

public function __construct(
FormFactory $formFactory,
CustomFieldModel $customFieldModel,
CustomFieldFactory $customFieldFactory,
CustomFieldPermissionProvider $permissionProvider,
CustomFieldRouteProvider $fieldRouteProvider,
CustomObjectModel $customObjectModel,
CustomObjectRouteProvider $objectRouteProvider
private FormFactoryInterface $formFactory,
ManagerRegistry $doctrine,
ModelFactory $modelFactory,
UserHelper $userHelper,
CoreParametersHelper $coreParametersHelper,
EventDispatcherInterface $dispatcher,
Translator $translator,
FlashBag $flashBag,
RequestStack $requestStack,
CorePermissions $security,
private CustomObjectRouteProvider $objectRouteProvider,
private CustomFieldRouteProvider $fieldRouteProvider,
private CustomFieldFactory $customFieldFactory,
private CustomObjectModel $customObjectModel,
private CustomFieldModel $customFieldModel,
private CustomFieldPermissionProvider $permissionProvider,
) {
$this->formFactory = $formFactory;
$this->customFieldModel = $customFieldModel;
$this->customFieldFactory = $customFieldFactory;
$this->permissionProvider = $permissionProvider;
$this->fieldRouteProvider = $fieldRouteProvider;
$this->customObjectModel = $customObjectModel;
$this->objectRouteProvider = $objectRouteProvider;
parent::__construct($doctrine, $modelFactory, $userHelper, $coreParametersHelper, $dispatcher, $translator, $flashBag, $requestStack, $security);
}

public function renderFormAction(Request $request): Response
Expand Down Expand Up @@ -114,7 +91,7 @@ public function renderFormAction(Request $request): Response
'customField' => $customField,
'form' => $form->createView(),
],
'contentTemplate' => 'CustomObjectsBundle:CustomField:form.html.php',
'contentTemplate' => '@CustomObjects/CustomField/form.html.twig',
'passthroughVars' => [
'mauticContent' => 'customField',
'route' => $route,
Expand Down
78 changes: 29 additions & 49 deletions Controller/CustomField/SaveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@
use MauticPlugin\CustomObjectsBundle\Model\CustomObjectModel;
use MauticPlugin\CustomObjectsBundle\Provider\CustomFieldPermissionProvider;
use MauticPlugin\CustomObjectsBundle\Provider\CustomFieldRouteProvider;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Translation\TranslatorInterface;

use Doctrine\Persistence\ManagerRegistry;
use Mautic\CoreBundle\Factory\ModelFactory;
use Mautic\CoreBundle\Helper\UserHelper;
use Mautic\CoreBundle\Helper\CoreParametersHelper;
use Mautic\CoreBundle\Service\FlashBag;
use Mautic\CoreBundle\Translation\Translator;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Mautic\CoreBundle\Security\Permissions\CorePermissions;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Form\FormFactoryInterface;
/**
* This controller is not used for saving to database, it is used only to generate forms and data validation.
* Persisting is handled in:.
Expand All @@ -31,52 +38,25 @@
*/
class SaveController extends CommonController
{
/**
* @var FormFactory
*/
private $formFactory;

/**
* @var CustomFieldModel
*/
private $customFieldModel;

/**
* @var CustomFieldFactory
*/
private $customFieldFactory;

/**
* @var CustomFieldPermissionProvider
*/
private $permissionProvider;

/**
* @var CustomFieldRouteProvider
*/
private $fieldRouteProvider;

/**
* @var CustomObjectModel
*/
private $customObjectModel;

public function __construct(
FormFactory $formFactory,
TranslatorInterface $translator,
CustomFieldModel $customFieldModel,
CustomFieldFactory $customFieldFactory,
CustomFieldPermissionProvider $permissionProvider,
CustomFieldRouteProvider $fieldRouteProvider,
CustomObjectModel $customObjectModel
private FormFactoryInterface $formFactory,
ManagerRegistry $doctrine,
ModelFactory $modelFactory,
UserHelper $userHelper,
CoreParametersHelper $coreParametersHelper,
EventDispatcherInterface $dispatcher,
Translator $translator,
FlashBag $flashBag,
RequestStack $requestStack,
CorePermissions $security,
private CustomFieldRouteProvider $fieldRouteProvider,
private CustomFieldFactory $customFieldFactory,
private CustomObjectModel $customObjectModel,
private CustomFieldModel $customFieldModel,
private CustomFieldPermissionProvider $permissionProvider,
) {
$this->formFactory = $formFactory;
$this->translator = $translator;
$this->customFieldModel = $customFieldModel;
$this->customFieldFactory = $customFieldFactory;
$this->permissionProvider = $permissionProvider;
$this->fieldRouteProvider = $fieldRouteProvider;
$this->customObjectModel = $customObjectModel;
parent::__construct($doctrine, $modelFactory, $userHelper, $coreParametersHelper, $dispatcher, $translator, $flashBag, $requestStack, $security);
}

/**
Expand Down Expand Up @@ -134,7 +114,7 @@ public function saveAction(Request $request)
'customField' => $customField,
'form' => $form->createView(),
],
'contentTemplate' => 'CustomObjectsBundle:CustomField:form.html.php',
'contentTemplate' => '@CustomObjects/CustomField/form.html.twig',
'passthroughVars' => [
'mauticContent' => 'customField',
'route' => $route,
Expand Down Expand Up @@ -178,7 +158,7 @@ private function buildSuccessForm(CustomObject $customObject, CustomField $custo
);

$template = $this->render(
'CustomObjectsBundle:CustomObject:_form-fields.html.php',
'@CustomObjects/CustomObject/_form-fields.html.twig',
[
'form' => $form->createView(),
'panelId' => $panelId, // Panel id to me replaced if edit
Expand Down Expand Up @@ -212,7 +192,7 @@ private function buildSuccessForm(CustomObject $customObject, CustomField $custo
*
* @see \Symfony\Component\Form\Exception\TransformationFailedException
*
* @param string[] $customFieldPost
* @param array<string, mixed> $customFieldPost
*/
private function recreateOptionsFromPost(array $customFieldPost, CustomField $customField): void
{
Expand Down
Loading
Loading