One bundle, two domains (Marketing Programs and Smart Links), one naming scheme.\nNothing in the database changed (no tables, columns, URLs or stored data);\nthe runtime was rebuilt and verified live.\n\n- Route names mautic_smartlinks_* -> mt3s_smartlinks_* (paths unchanged);\n the menu ids follow\n- Model service aliases collapsed to one canonical alias per model:\n mautic.mt3smarketingprogram.model.<entity> (core's mautic.<x>.model.<x>\n pattern), so getModel('mt3smarketingprogram.smart_link'); the dead\n mt3s.* and mautic.mt3smp.*-era aliases are gone\n- Translation keys mautic.smartlinks.* -> mt3s.smart_links.*\n (mautic.config.tab.smartlinksconfig stays: core derives it)\n- Settings parameters smartlinks_utm_config/smartlinks_config ->\n mt3s_smart_links_utm_config/mt3s_smart_links_config, with both legacy\n keys (smartlinks_* of the standalone bundle, utm_manager_* of the\n UtmManagerBundle era) still readable until the settings are saved again\n- JS loader prefixes smartlinksSmartLink/smartlinksUtmTaxonomy ->\n mt3sMpSmartLink/mt3sMpUtmTaxonomy (the mt3sMp* family of the program\n domain)\n- Integration/Support/ConfigSupport -> SmartlinksConfigSupport; integration\n display names aligned ('MT3S Marketing Program' / 'Smart Links'); the\n dead mautic.plugin.smartlinks.name catalog keys removed\n- phpunit suite renamed UtmManagerBundle -> MT3SMarketingProgramBundle;\n version 0.18.1\n\nVerified: full php -l, 90/90 unit tests (phpunit 11.5 phar), cache clear +\nwarm + assets regenerate + plugins reload (as www-data), live: both lists\nand forms (mauticContent mt3sMpSmartLink/mt3sMpUtmTaxonomy), both config\ntabs, the menu labels, the program pages (regression), the public /l/y32b\nredirect through the legacy utm_manager_* settings (302 with the taxonomy's\nUTM values, wrong host and unknown slug 404), all ini catalogs parse, zero\nnew log errors.
116 lines
3.6 KiB
PHP
116 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\Model;
|
|
|
|
use Mautic\CoreBundle\Model\FormModel;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Program;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Entity\ProgramRepository;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Event\MT3SMarketingProgramEvents;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Event\ProgramEvent;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Form\Type\ProgramType;
|
|
use Symfony\Component\Form\FormFactoryInterface;
|
|
use Symfony\Component\Form\FormInterface;
|
|
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
|
|
|
/**
|
|
* Available as mautic.mt3smarketingprogram.model.program, or getModel('mt3smarketingprogram.program').
|
|
*
|
|
* @extends FormModel<Program>
|
|
*/
|
|
class ProgramModel extends FormModel
|
|
{
|
|
public function getRepository(): ProgramRepository
|
|
{
|
|
$repository = $this->em->getRepository(Program::class);
|
|
\assert($repository instanceof ProgramRepository);
|
|
|
|
return $repository;
|
|
}
|
|
|
|
public function getPermissionBase(): string
|
|
{
|
|
return 'mt3smarketingprogram:programs';
|
|
}
|
|
|
|
/**
|
|
* With no ID, returns a new program with the current user as owner.
|
|
*/
|
|
public function getEntity($id = null): ?Program
|
|
{
|
|
if (null === $id) {
|
|
$program = new Program();
|
|
$program->setOwner($this->userHelper->getUser(true));
|
|
|
|
return $program;
|
|
}
|
|
|
|
$program = parent::getEntity($id);
|
|
|
|
return $program instanceof Program ? $program : null;
|
|
}
|
|
|
|
/**
|
|
* Keeps objective and description item positions contiguous (0..n-1) before saving, and
|
|
* dispatches the plugin's pre/post save events (created vs updated by the entity's ID).
|
|
*/
|
|
public function saveEntity($entity, $unlock = true): void
|
|
{
|
|
if ($entity instanceof Program) {
|
|
$isNew = null === $entity->getId();
|
|
|
|
$this->dispatcher->dispatch(new ProgramEvent($entity, $isNew), MT3SMarketingProgramEvents::PROGRAM_PRE_SAVE);
|
|
|
|
$entity->normalizePositions();
|
|
|
|
parent::saveEntity($entity, $unlock);
|
|
|
|
$this->dispatcher->dispatch(new ProgramEvent($entity, $isNew), MT3SMarketingProgramEvents::PROGRAM_POST_SAVE);
|
|
$this->dispatcher->dispatch(
|
|
new ProgramEvent($entity, $isNew),
|
|
$isNew ? MT3SMarketingProgramEvents::PROGRAM_CREATED : MT3SMarketingProgramEvents::PROGRAM_UPDATED
|
|
);
|
|
|
|
return;
|
|
}
|
|
|
|
parent::saveEntity($entity, $unlock);
|
|
}
|
|
|
|
/**
|
|
* Dispatches the plugin's delete events around the removal.
|
|
*/
|
|
public function deleteEntity($entity): void
|
|
{
|
|
if ($entity instanceof Program) {
|
|
$this->dispatcher->dispatch(new ProgramEvent($entity, false), MT3SMarketingProgramEvents::PROGRAM_PRE_DELETE);
|
|
|
|
parent::deleteEntity($entity);
|
|
|
|
$this->dispatcher->dispatch(new ProgramEvent($entity, false), MT3SMarketingProgramEvents::PROGRAM_POST_DELETE);
|
|
$this->dispatcher->dispatch(new ProgramEvent($entity, false), MT3SMarketingProgramEvents::PROGRAM_DELETED);
|
|
|
|
return;
|
|
}
|
|
|
|
parent::deleteEntity($entity);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $options
|
|
*/
|
|
public function createForm($entity, FormFactoryInterface $formFactory, $action = null, $options = []): FormInterface
|
|
{
|
|
if (!$entity instanceof Program) {
|
|
throw new MethodNotAllowedHttpException(['Program']);
|
|
}
|
|
|
|
if (!empty($action)) {
|
|
$options['action'] = $action;
|
|
}
|
|
|
|
return $formFactory->create(ProgramType::class, $entity, $options);
|
|
}
|
|
}
|