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.
73 lines
2.3 KiB
PHP
73 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\Form\Validator;
|
|
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Model\UtmTaxonomyModel;
|
|
|
|
/**
|
|
* Business rules of the UTM Taxonomy form. The form types call these methods from Callback
|
|
* constraints; each method returns translation keys (validators domain) and parameters.
|
|
*/
|
|
final class UtmTaxonomyValidator
|
|
{
|
|
public const ERROR_NAME_TAKEN = 'mt3s.smart_links.taxonomies.error.name_taken';
|
|
public const ERROR_NAME_CHARACTERS = 'mt3s.smart_links.taxonomies.error.name_characters';
|
|
public const ERROR_VALUE_INVALID = 'mt3s.smart_links.taxonomies.error.value_invalid';
|
|
public const ERROR_VALUE_DUPLICATE = 'mt3s.smart_links.config.error.value_duplicate';
|
|
|
|
public function __construct(
|
|
private readonly UtmTaxonomyModel $taxonomyModel,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Unique, non-empty name. Free of the characters local.php can't carry ("%", "{", "}").
|
|
*
|
|
* @return list<array{0: string, 1: array<string, string>}>
|
|
*/
|
|
public function validateName(string $name, ?int $ignoreId = null): array
|
|
{
|
|
if (1 !== preg_match('/^[^%{}]+$/', $name)) {
|
|
return [[self::ERROR_NAME_CHARACTERS, []]];
|
|
}
|
|
|
|
if ($this->taxonomyModel->isNameTaken($name, $ignoreId)) {
|
|
return [[self::ERROR_NAME_TAKEN, ['%name%' => $name]]];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* The value list of a `free` parameter (its editable textarea): every line must respect
|
|
* the technical pattern of the URL values, and duplicates are rejected.
|
|
*
|
|
* @param list<array{0: string, 1: string}> $parsed
|
|
*
|
|
* @return list<array{0: string, 1: array<string, string>}>
|
|
*/
|
|
public function validateValues(array $parsed): array
|
|
{
|
|
$errors = [];
|
|
$seen = [];
|
|
|
|
foreach ($parsed as [$value]) {
|
|
if ('' === $value) {
|
|
continue;
|
|
}
|
|
|
|
if (isset($seen[$value]) && 1 === $seen[$value]) {
|
|
$errors[] = [self::ERROR_VALUE_DUPLICATE, ['%value%' => $value]];
|
|
}
|
|
$seen[$value] = ($seen[$value] ?? 0) + 1;
|
|
|
|
if (1 !== preg_match(UtmSettingsValidator::VALUE_PATTERN, $value)) {
|
|
$errors[] = [self::ERROR_VALUE_INVALID, ['%value%' => $value]];
|
|
}
|
|
}
|
|
|
|
return $errors;
|
|
}
|
|
} |