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.
78 lines
2.7 KiB
PHP
78 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\Service;
|
|
|
|
use Mautic\CoreBundle\Helper\CoreParametersHelper;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Form\Type\SmartLinksConfigType;
|
|
|
|
/**
|
|
* Builds the public form of a Smart Link: https://{short_link_domain}/l/{slug}.
|
|
* The domain is set in Settings > Configuration > Smart Links Settings; the form shows it
|
|
* as a reminder (getShortLinkDomain(), without the scheme).
|
|
*/
|
|
final class SmartLinkShortUrlBuilder
|
|
{
|
|
public const PATH_PREFIX = '/l/';
|
|
|
|
public function __construct(
|
|
private readonly CoreParametersHelper $coreParametersHelper,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* The configured short link domain, without scheme or trailing slash, for example lnk.example.com.
|
|
* Empty when nothing is configured yet.
|
|
*/
|
|
public function getShortLinkDomain(): string
|
|
{
|
|
$stored = $this->coreParametersHelper->get(SmartLinksConfigType::CONFIG_PARAMETER, []);
|
|
|
|
// Upgrades keep the domain in local.php under a legacy key (the standalone
|
|
// SmartlinksBundle wrote `smartlinks_config`, the UtmManagerBundle before it
|
|
// `utm_manager_smart_links`); serve it until the Configuration page is saved again.
|
|
$legacyKeys = [
|
|
SmartLinksConfigType::LEGACY_SMARTLINKS_PARAMETER,
|
|
SmartLinksConfigType::LEGACY_CONFIG_PARAMETER,
|
|
];
|
|
foreach ($legacyKeys as $legacyKey) {
|
|
if (!is_array($stored) || '' === trim((string) ($stored['short_link_domain'] ?? ''))) {
|
|
$legacy = $this->coreParametersHelper->get($legacyKey, []);
|
|
if (is_array($legacy) && '' !== trim((string) ($legacy['short_link_domain'] ?? ''))) {
|
|
$stored = $legacy;
|
|
}
|
|
}
|
|
}
|
|
|
|
$domain = trim(is_array($stored) ? (string) ($stored['short_link_domain'] ?? '') : '');
|
|
|
|
return '' === $domain ? '' : rtrim($domain, '/');
|
|
}
|
|
|
|
/**
|
|
* The short link of a Smart Link, for example https://lnk.example.com/l/ab3x.
|
|
* Empty when no domain is configured, or when the link has no slug yet.
|
|
*/
|
|
public function buildShortUrl(SmartLink $smartLink): string
|
|
{
|
|
return $this->buildShortUrlFromSlug((string) ($smartLink->getSlug() ?? ''));
|
|
}
|
|
|
|
/**
|
|
* Same as buildShortUrl(), for a slug that was just typed in the form (live preview).
|
|
*/
|
|
public function buildShortUrlFromSlug(string $slug): string
|
|
{
|
|
$slug = trim($slug);
|
|
$domain = $this->getShortLinkDomain();
|
|
|
|
if ('' === $domain || '' === $slug) {
|
|
return '';
|
|
}
|
|
|
|
return 'https://'.$domain.self::PATH_PREFIX.$slug;
|
|
}
|
|
}
|