refactor(plugin): rename Plan to Program and add audience/UTM routes
Rename the Plan bundle to Program across config, routes, menus, and controllers (Plan -> Initiative), bump version to 0.16.0, and introduce new audience and UTM taxonomy routes and permissions to support the expanded Programs feature set.
This commit is contained in:
1 parent
8268fad886
commit
71ff11390b
121 files changed
+5011
-2874
No files matched your search
@@ -2,21 +2,29 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\Migrations;
|
||||
namespace MauticPlugin\ProgramBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\PlanBundle\Entity\Plan;
|
||||
use MauticPlugin\PlanBundle\Entity\Target;
|
||||
use MauticPlugin\PlanBundle\Entity\TargetType as TargetTypeEnum;
|
||||
use MauticPlugin\ProgramBundle\Entity\Audience;
|
||||
use MauticPlugin\ProgramBundle\Entity\AudienceType as AudienceTypeEnum;
|
||||
use MauticPlugin\ProgramBundle\Entity\Initiative;
|
||||
|
||||
/**
|
||||
* Since 0.11.0 a plan has targets (table plan_targets) with any number of Mautic stages (join table
|
||||
* plan_target_stages). Creates both tables for installs created before 0.11.0, and repairs the ones the
|
||||
* plugin installer created without foreign keys (it drops foreign keys that point to core tables, such
|
||||
* as stages) or with camelCase column names (an early version of the mapping). Each step runs only if
|
||||
* needed.
|
||||
* Since 0.11.0 a plan has audiences (table initiative_audiences, initiative_audiences_stages before 0.15.0) with any
|
||||
* number of Mautic stages (join table initiative_audiences_stages). Creates both tables for installs created
|
||||
* before 0.11.0, and repairs the ones the plugin installer created with camelCase column names (an
|
||||
* early version of the mapping). Each step runs only if needed.
|
||||
*
|
||||
* Since 0.14.0 audiences are a global directory: initiative_audiences no longer carries plan_id (the plan
|
||||
* association lives in initiative_audiences_initiative), so the plan_id repair is retired here; only the
|
||||
* camelCase repair can still apply to an old install.
|
||||
*
|
||||
* Since 0.15.0 the tables are initiative_audiences and initiative_audiences_stages: an install already on 0.14.0
|
||||
* was migrated by 0.15.0, so this migration creates nothing; one created before 0.11.0 that skipped
|
||||
* every version since gets the current tables from the entity mapping directly, by looking for the
|
||||
* current names too.
|
||||
*/
|
||||
class Version_0_11_0 extends AbstractMigration
|
||||
{
|
||||
@@ -32,49 +40,36 @@ class Version_0_11_0 extends AbstractMigration
|
||||
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
if (!$schema->hasTable($this->concatPrefix(Plan::TABLE_NAME))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$schema->hasTable($this->concatPrefix(Target::TABLE_NAME))
|
||||
|| !$schema->hasTable($this->concatPrefix('plan_target_stages'))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Repair mode: missing foreign keys or camelCase columns.
|
||||
return [] !== $this->getColumnsToRename($schema) || !$this->hasForeignKeys($schema);
|
||||
// Historical migration: its changes were applied on every install that ran
|
||||
// it before 0.16.0 (this plugin renamed Plan→Program/Initiative in 0.16.0), and
|
||||
// a fresh install creates the current tables from the entity mapping. Never
|
||||
// applicable anymore.
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function up(): void
|
||||
{
|
||||
$schema = $this->entityManager->getConnection()->createSchemaManager()->introspectSchema();
|
||||
|
||||
if (!$schema->hasTable($this->concatPrefix(Target::TABLE_NAME))) {
|
||||
$this->addSql($this->getCreateTableSql(Target::TABLE_NAME));
|
||||
// An install created before 0.11.0 that somehow never got the tables: create the current
|
||||
// (0.15.0) ones from the entity mapping directly.
|
||||
if (!$schema->hasTable($this->concatPrefix(Audience::TABLE_NAME))) {
|
||||
$this->addSql($this->getCreateTableSql(Audience::TABLE_NAME));
|
||||
}
|
||||
|
||||
if (!$schema->hasTable($this->concatPrefix('plan_target_stages'))) {
|
||||
$this->addSql($this->getCreateTableSql('plan_target_stages'));
|
||||
if (!$schema->hasTable($this->concatPrefix('initiative_audiences_stages'))
|
||||
&& !$schema->hasTable($this->concatPrefix('initiative_audiences_stages'))) {
|
||||
$this->addSql($this->getCreateTableSql('initiative_audiences_stages'));
|
||||
}
|
||||
|
||||
foreach ($this->getColumnsToRename($schema) as $field => $column) {
|
||||
$this->addSql(sprintf(
|
||||
'ALTER TABLE %s CHANGE %s %s',
|
||||
$this->concatPrefix(Target::TABLE_NAME),
|
||||
$this->concatPrefix(Audience::TABLE_NAME),
|
||||
$field,
|
||||
$this->getColumnDefinition($field, $column)
|
||||
));
|
||||
}
|
||||
|
||||
if (!$this->hasForeignKeys($schema)) {
|
||||
$this->addSql($this->generateAlterTableForeignKeyStatement(
|
||||
Target::TABLE_NAME,
|
||||
['plan_id'],
|
||||
Plan::TABLE_NAME,
|
||||
['id'],
|
||||
'ON DELETE CASCADE'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,11 +77,11 @@ class Version_0_11_0 extends AbstractMigration
|
||||
*/
|
||||
private function getColumnsToRename(Schema $schema): array
|
||||
{
|
||||
if (!$schema->hasTable($this->concatPrefix(Target::TABLE_NAME))) {
|
||||
if (!$schema->hasTable($this->concatPrefix(Audience::TABLE_NAME))) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$table = $schema->getTable($this->concatPrefix(Target::TABLE_NAME));
|
||||
$table = $schema->getTable($this->concatPrefix(Audience::TABLE_NAME));
|
||||
$rename = [];
|
||||
|
||||
foreach (self::COLUMNS as $field => $column) {
|
||||
@@ -100,13 +95,13 @@ class Version_0_11_0 extends AbstractMigration
|
||||
|
||||
private function hasForeignKeys(Schema $schema): bool
|
||||
{
|
||||
$targets = $this->concatPrefix(Target::TABLE_NAME);
|
||||
$audiences = $this->concatPrefix(Audience::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($targets)) {
|
||||
if (!$schema->hasTable($audiences)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($schema->getTable($targets)->getForeignKeys() as $foreignKey) {
|
||||
foreach ($schema->getTable($audiences)->getForeignKeys() as $foreignKey) {
|
||||
if (in_array('plan_id', $foreignKey->getLocalColumns(), true)) {
|
||||
return true;
|
||||
}
|
||||
@@ -121,7 +116,7 @@ class Version_0_11_0 extends AbstractMigration
|
||||
private function getColumnDefinition(string $field, string $column): string
|
||||
{
|
||||
$definitions = [
|
||||
'targetType' => sprintf("%s VARCHAR(30) NOT NULL DEFAULT '%s'", $column, TargetTypeEnum::Persona->value),
|
||||
'targetType' => sprintf("%s VARCHAR(30) NOT NULL DEFAULT '%s'", $column, AudienceTypeEnum::Persona->value),
|
||||
'profileCriteria' => $column.' LONGTEXT DEFAULT NULL',
|
||||
'painPoints' => $column.' LONGTEXT DEFAULT NULL',
|
||||
'valueProposition' => $column.' LONGTEXT DEFAULT NULL',
|
||||
@@ -138,7 +133,7 @@ class Version_0_11_0 extends AbstractMigration
|
||||
$schemaTool = new SchemaTool($this->entityManager);
|
||||
$prefix = 'CREATE TABLE '.$this->concatPrefix($table).' ';
|
||||
|
||||
foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata(Target::class)]) as $sql) {
|
||||
foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata(Audience::class)]) as $sql) {
|
||||
if (str_starts_with($sql, $prefix)) {
|
||||
return $sql;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user