Files
Alexandre Gain dce849610c Merge the Smartlinks plugin (SmartlinksBundle 0.6.0) into the bundle as the Smart Links domain (0.18.0)
Two domains, one MT3S bundle: Marketing Programs (unchanged) and the
imported Smart Links (smart links + UTM taxonomies), each keeping its
own menu, tables, routes and translations.

- Code moved from MauticPlugin\SmartlinksBundle\ to
  MauticPlugin\MT3SMarketingProgramBundle\; template namespace
  @Smartlinks/ -> @MT3SMarketingProgram/; smartlinks.js ->
  Assets/js/mt3s-mp-smartlinks.js; icon -> Assets/img/smartlinks-icon.svg.
- Incoming migrations renamed Version_0_X_0_SmartLinks.php to avoid
  the class-name collision; schema untouched, data intact.
- Permissions folded into MT3SMarketingProgramPermissions:
  smart_links + taxonomies under the mt3smarketingprogram: base
  (roles that had the old smartlinks: grants must be re-granted).
- config.php: Smart Links routes + menu group, public /l/{slug},
  SmartlinksIntegration services, smartlinks_* parameters (legacy
  utm_manager_* keys still readable), version 0.18.0. The 0.17.0
  placeholder /s/marketing-program-utm-taxonomies is replaced by the
  real /s/utm-taxonomies.
- Translations merged (en_US) and added (fr_FR); Tests/ + phpunit moved
  in; readme documents both domains and the 0.18.0 merge history.

Verified live: menus, both config tabs, both lists + forms, program
pages, public redirect with taxonomy UTM values, host + unknown-slug
404s, 90/90 unit tests, full php -l, all ini catalogs parse.
2026-11-16 13:48:13 +01:00

98 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink;
/**
* Adds the Mautic destinations to the Smart Links: a landing page or a standalone form.
*
* Idempotent: runs on plugin update (core's migration engine) and right after a fresh
* install (PluginInstallSubscriber), and stops when the columns already exist.
*/
class Version_0_4_0_SmartLinks extends AbstractMigration
{
/**
* Local column => referenced core table.
*/
private const FOREIGN_KEYS = [
'page_id' => 'pages',
'form_id' => 'forms',
];
protected function isApplicable(Schema $schema): bool
{
$table = $this->getTable($schema);
if (null === $table) {
return false;
}
foreach (array_keys(self::FOREIGN_KEYS) as $column) {
if (!$table->hasColumn($column)) {
return true;
}
}
return [] !== $this->getMissingForeignKeys($table);
}
protected function up(): void
{
$schema = $this->entityManager->getConnection()->createSchemaManager()->introspectSchema();
$table = $this->getTable($schema);
if (null === $table) {
return;
}
foreach (array_keys(self::FOREIGN_KEYS) as $column) {
if (!$table->hasColumn($column)) {
$this->addSql(sprintf(
'ALTER TABLE %s ADD %s INT UNSIGNED DEFAULT NULL',
$this->concatPrefix(SmartLink::TABLE_NAME),
$column
));
}
}
foreach ($this->getMissingForeignKeys($table) as $column => $referenceTable) {
$this->addSql($this->generateAlterTableForeignKeyStatement(
SmartLink::TABLE_NAME,
[$column],
$referenceTable,
['id'],
'ON DELETE SET NULL'
));
}
}
private function getTable(Schema $schema): ?Table
{
$name = $this->concatPrefix(SmartLink::TABLE_NAME);
return $schema->hasTable($name) ? $schema->getTable($name) : null;
}
/**
* @return array<string, string>
*/
private function getMissingForeignKeys(Table $table): array
{
$missing = self::FOREIGN_KEYS;
foreach ($table->getForeignKeys() as $foreignKey) {
foreach ($foreignKey->getLocalColumns() as $column) {
unset($missing[$column]);
}
}
return $missing;
}
}