refactor(plugin): rebrand as MT3SMarketingProgram, release 0.17.0

Rename the plugin's vendor/namespace from experiential/Program to mt3s/MT3SMarketingProgram (composer: mt3s/mautic-marketing-program-bundle):

- ProgramBundle -> MT3SMarketingProgramBundle; extension, integration,
  config support, permissions, events and twig extension renamed likewise
- Initiative* -> Program*: controller (InitiativeController ->
  ProgramController), model, entities, repositories, form types and views
  (new _tabs/_task_table/_tab_table_filter partials, details page)
- Settings config form theme -> _config_mt3smarketingprogramconfig_widget;
  routes and translations re-prefixed (mt3s_marketing_program_*)
- Assets: icon.svg -> mt3s-mp-icon.svg; program.js -> mt3s-mp-program.js
  (OnLoad hooks renamed mt3sMpProgram*)
- Add Command/RefreshStatsCommand; Migrations/Version_0_17_0.php renames
  the tables to mt3s_mp_program_*
This commit is contained in:
Alexandre Gain committed 2026-11-15 17:48:01 +01:00
1 parent 687d33d30c
commit ea88b7a772
131 files changed
+3238 -2836

No files matched your search

+3 -5
View File
@@ -2,12 +2,10 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\InitiativeObjective;
/**
* Since 0.10.0 objectives have a type, the key of an objective type set up in Settings >
* Configuration > Plan Settings (parameter plan_objective_types). Adds initiative_objectives.type for
@@ -28,11 +26,11 @@ class Version_0_10_0 extends AbstractMigration
protected function up(): void
{
$objectives = $this->concatPrefix(InitiativeObjective::TABLE_NAME);
$objectives = $this->concatPrefix('initiative_objectives');
$table = $this->entityManager->getConnection()->createSchemaManager()->introspectTable($objectives);
if (!$table->hasColumn('type')) {
$this->addSql(sprintf('ALTER TABLE %s ADD type VARCHAR(%d) DEFAULT NULL', $objectives, InitiativeObjective::TYPE_MAX_LENGTH));
$this->addSql(sprintf('ALTER TABLE %s ADD type VARCHAR(%d) DEFAULT NULL', $objectives, 64));
}
}
}
+3 -5
View File
@@ -2,12 +2,10 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\InitiativeObjective;
/**
* Since 0.10.1 objectives have a priority, a whole number from 1 (highest) to 99 (lowest). Adds
* initiative_objectives.priority for installs created before 0.10.1: NOT NULL with the default 1, and the
@@ -26,14 +24,14 @@ class Version_0_10_1 extends AbstractMigration
protected function up(): void
{
$objectives = $this->concatPrefix(InitiativeObjective::TABLE_NAME);
$objectives = $this->concatPrefix('initiative_objectives');
$table = $this->entityManager->getConnection()->createSchemaManager()->introspectTable($objectives);
if (!$table->hasColumn('priority')) {
$this->addSql(sprintf(
"ALTER TABLE %s ADD priority INT NOT NULL DEFAULT %d",
$objectives,
InitiativeObjective::PRIORITY_MIN
1
));
}
}
+9 -11
View File
@@ -2,15 +2,13 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\Tools\SchemaTool;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Audience;
use MauticPlugin\ProgramBundle\Entity\AudienceType as AudienceTypeEnum;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Audience;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\AudienceType as AudienceTypeEnum;
/**
* 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
@@ -53,8 +51,8 @@ class Version_0_11_0 extends AbstractMigration
// 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('initiative_audiences'))) {
$this->addSql($this->getCreateTableSql('initiative_audiences'));
}
if (!$schema->hasTable($this->concatPrefix('initiative_audiences_stages'))
@@ -65,7 +63,7 @@ class Version_0_11_0 extends AbstractMigration
foreach ($this->getColumnsToRename($schema) as $field => $column) {
$this->addSql(sprintf(
'ALTER TABLE %s CHANGE %s %s',
$this->concatPrefix(Audience::TABLE_NAME),
$this->concatPrefix('initiative_audiences'),
$field,
$this->getColumnDefinition($field, $column)
));
@@ -77,11 +75,11 @@ class Version_0_11_0 extends AbstractMigration
*/
private function getColumnsToRename(Schema $schema): array
{
if (!$schema->hasTable($this->concatPrefix(Audience::TABLE_NAME))) {
if (!$schema->hasTable($this->concatPrefix('initiative_audiences'))) {
return [];
}
$table = $schema->getTable($this->concatPrefix(Audience::TABLE_NAME));
$table = $schema->getTable($this->concatPrefix('initiative_audiences'));
$rename = [];
foreach (self::COLUMNS as $field => $column) {
@@ -95,7 +93,7 @@ class Version_0_11_0 extends AbstractMigration
private function hasForeignKeys(Schema $schema): bool
{
$audiences = $this->concatPrefix(Audience::TABLE_NAME);
$audiences = $this->concatPrefix('initiative_audiences');
if (!$schema->hasTable($audiences)) {
return false;
+11 -13
View File
@@ -2,14 +2,12 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\Tools\SchemaTool;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\ProgramBundle\Entity\InitiativeStakeholder;
use MauticPlugin\ProgramBundle\Entity\Stakeholder;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Stakeholder;
/**
* Since 0.12.0 planning has a global stakeholder directory (table initiative_stakeholders), and each plan
@@ -33,26 +31,26 @@ class Version_0_12_0 extends AbstractMigration
{
$schema = $this->entityManager->getConnection()->createSchemaManager()->introspectSchema();
if (!$schema->hasTable($this->concatPrefix(Stakeholder::TABLE_NAME))) {
$this->addSql($this->getCreateTableSql(Stakeholder::class, Stakeholder::TABLE_NAME));
if (!$schema->hasTable($this->concatPrefix('initiative_stakeholders'))) {
$this->addSql($this->getCreateTableSql(Stakeholder::class, 'initiative_stakeholders'));
}
if (!$schema->hasTable($this->concatPrefix(InitiativeStakeholder::TABLE_NAME))) {
$this->addSql($this->getCreateTableSql(InitiativeStakeholder::class, InitiativeStakeholder::TABLE_NAME));
if (!$schema->hasTable($this->concatPrefix('initiative_stakeholders_initiative'))) {
$this->addSql($this->getCreateTableSql(InitiativeStakeholder::class, 'initiative_stakeholders_initiative'));
}
if (!$this->hasForeignKeys($schema)) {
$this->addSql($this->generateAlterTableForeignKeyStatement(
InitiativeStakeholder::TABLE_NAME,
'initiative_stakeholders_initiative',
['plan_id'],
Initiative::TABLE_NAME,
'initiatives',
['id'],
'ON DELETE CASCADE'
));
$this->addSql($this->generateAlterTableForeignKeyStatement(
InitiativeStakeholder::TABLE_NAME,
'initiative_stakeholders_initiative',
['stakeholder_id'],
Stakeholder::TABLE_NAME,
'initiative_stakeholders',
['id'],
'ON DELETE CASCADE'
));
@@ -64,7 +62,7 @@ class Version_0_12_0 extends AbstractMigration
*/
private function hasForeignKeys(Schema $schema): bool
{
$links = $this->concatPrefix(InitiativeStakeholder::TABLE_NAME);
$links = $this->concatPrefix('initiative_stakeholders_initiative');
if (!$schema->hasTable($links)) {
return false;
+12 -12
View File
@@ -2,14 +2,14 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\Tools\SchemaTool;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Task;
use MauticPlugin\ProgramBundle\Entity\TaskDependency;
use MauticPlugin\ProgramBundle\Entity\TaskRaci;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Task;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\TaskDependency;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\TaskRaci;
/**
* Since 0.13.0 tasks are reworked:
@@ -35,7 +35,7 @@ class Version_0_13_0 extends AbstractMigration
protected function up(): void
{
$tasks = $this->concatPrefix(Task::TABLE_NAME);
$tasks = $this->concatPrefix('initiative_tasks');
$table = $this->entityManager->getConnection()->createSchemaManager()->introspectTable($tasks);
// New columns.
@@ -43,7 +43,7 @@ class Version_0_13_0 extends AbstractMigration
$this->addSql(sprintf(
"ALTER TABLE %s ADD task_kind VARCHAR(20) NOT NULL DEFAULT '%s'",
$tasks,
\MauticPlugin\ProgramBundle\Entity\TaskKind::Task->value
\MauticPlugin\MT3SMarketingProgramBundle\Entity\TaskKind::Task->value
));
}
if (!$table->hasColumn('definition_of_done')) {
@@ -71,20 +71,20 @@ class Version_0_13_0 extends AbstractMigration
}
// New tables. Each is created when missing on its own, so a partial earlier run is repaired.
if (!$this->introspectSchema()->hasTable($this->concatPrefix(TaskDependency::TABLE_NAME))) {
foreach ($this->getCreateTableSqls(TaskDependency::class, TaskDependency::TABLE_NAME) as $sql) {
if (!$this->introspectSchema()->hasTable($this->concatPrefix('initiative_task_dependencies'))) {
foreach ($this->getCreateTableSqls(TaskDependency::class, 'initiative_task_dependencies') as $sql) {
$this->addSql($sql);
}
}
if (!$this->introspectSchema()->hasTable($this->concatPrefix(TaskRaci::TABLE_NAME))) {
foreach ($this->getCreateTableSqls(TaskRaci::class, TaskRaci::TABLE_NAME) as $sql) {
if (!$this->introspectSchema()->hasTable($this->concatPrefix('initiative_task_raci'))) {
foreach ($this->getCreateTableSqls(TaskRaci::class, 'initiative_task_raci') as $sql) {
$this->addSql($sql);
}
}
// The RACI join table comes with the TaskRaci entity's SQL (CREATE TABLE initiative_task_raci_stakeholders),
// but it may be missing while initiative_task_raci exists (a partial earlier run).
if (!$this->introspectSchema()->hasTable($this->concatPrefix(TaskRaci::JOIN_TABLE_NAME))) {
foreach ($this->getCreateTableSqls(TaskRaci::class, TaskRaci::JOIN_TABLE_NAME) as $sql) {
if (!$this->introspectSchema()->hasTable($this->concatPrefix('initiative_task_raci_stakeholders'))) {
foreach ($this->getCreateTableSqls(TaskRaci::class, 'initiative_task_raci_stakeholders') as $sql) {
$this->addSql($sql);
}
}
+6 -9
View File
@@ -2,14 +2,11 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Audience;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\ProgramBundle\Entity\InitiativeAudience;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Audience;
/**
* Since 0.14.0 audiences are a global directory (Planning > Audiences, called Targets before 0.15.0),
* like stakeholders:
@@ -147,9 +144,9 @@ class Version_0_14_0 extends AbstractMigration
// core tables, such as plans, at install time).
if (!$this->hasForeignKeys($schema)) {
$this->addSql($this->generateAlterTableForeignKeyStatement(
$oldNaming ? 'initiative_audiences_initiative' : InitiativeAudience::TABLE_NAME,
$oldNaming ? 'initiative_audiences_initiative' : 'initiative_audiences_initiative',
['plan_id'],
Initiative::TABLE_NAME,
'initiatives',
['id'],
'ON DELETE CASCADE'
));
@@ -166,7 +163,7 @@ class Version_0_14_0 extends AbstractMigration
private function getTableNames(Schema $schema): ?array
{
foreach ([
[Audience::TABLE_NAME, InitiativeAudience::TABLE_NAME],
['initiative_audiences', 'initiative_audiences_initiative'],
['initiative_audiences', 'initiative_audiences_initiative'],
] as [$directory, $links]) {
if ($schema->hasTable($this->concatPrefix($directory))) {
@@ -184,7 +181,7 @@ class Version_0_14_0 extends AbstractMigration
*/
private function hasForeignKeys(Schema $schema): bool
{
foreach (['initiative_audiences_initiative', InitiativeAudience::TABLE_NAME] as $links) {
foreach (['initiative_audiences_initiative', 'initiative_audiences_initiative'] as $links) {
$links = $this->concatPrefix($links);
if (!$schema->hasTable($links)) {
+3 -5
View File
@@ -2,13 +2,11 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Audience;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Audience;
/**
* Historical migration (from 0.15.0, when the bundle was still PlanBundle): it renamed "targets"
* to "audiences" — plan_targets became plan_audiences (its target_type column audience_type),
@@ -23,7 +21,7 @@ class Version_0_15_0 extends AbstractMigration
{
protected function isApplicable(Schema $schema): bool
{
if (!$schema->hasTable($this->concatPrefix(Initiative::TABLE_NAME))
if (!$schema->hasTable($this->concatPrefix('initiatives'))
&& !$schema->hasTable($this->concatPrefix('plans'))) {
return false;
}
+2 -3
View File
@@ -2,14 +2,13 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Initiative;
/**
* Since 0.16.0 the PlanBundle is the ProgramBundle, and a plan is an initiative: the Planning
* Since 0.16.0 the PlanBundle is the MT3SMarketingProgramBundle, and a plan is an initiative: the Planning
* menu is Programs, the Plans page is Initiatives. The database follows:
* - plans becomes initiatives;
* - plan_objectives, plan_description_items, plan_allocation_items become initiative_*;
+218
View File
@@ -0,0 +1,218 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
/**
* Since 0.17.0 the ProgramBundle is the MT3SMarketingProgramBundle, and an initiative is a marketing
* program: the Programs menu is Marketing Programs. The database follows:
* - initiatives becomes mt3s_mp_programs;
* - initiative_objectives, initiative_description_items, initiative_allocation_items become
* mt3s_mp_program_*;
* - initiative_tasks, initiative_task_dependencies, initiative_task_raci,
* initiative_task_raci_stakeholders become mt3s_mp_program_task_*;
* - initiative_stakeholders, initiative_stakeholders_initiative become mt3s_mp_program_stakeholders
* and mt3s_mp_program_stakeholders_program;
* - initiative_audiences, initiative_audiences_initiative, initiative_audiences_segments,
* initiative_audiences_stages become mt3s_mp_program_audiences*;
* - the link tables' initiative_id columns become program_id; the stakeholders link's
* role_in_initiative becomes role_in_program.
*
* The rows the rename orphans follow too: the plugins row (bundle ProgramBundle, kept as an update
* so the installer does not treat the plugin as new), the role permission rows (bundle program,
* name initiatives), the categories rows (bundle plan from before 0.16.0 or initiative since), and
* the audit log rows (bundle PlanBundle/ProgramBundle).
*
* Every statement runs immediately and re-reads the schema first, so the migration picks up again
* wherever an earlier run stopped (MySQL auto-commits DDL, so a failing batch of addSql() can
* leave the renames half done). A fresh install created by the plugin installer already uses the
* new names from the entity mapping.
*/
class Version_0_17_0 extends AbstractMigration
{
/**
* Old table name => new table name, in dependency order.
*/
private const TABLES = [
'initiatives' => 'mt3s_mp_programs',
'initiative_objectives' => 'mt3s_mp_program_objectives',
'initiative_description_items' => 'mt3s_mp_program_description_items',
'initiative_allocation_items' => 'mt3s_mp_program_allocation_items',
'initiative_tasks' => 'mt3s_mp_program_tasks',
'initiative_task_dependencies' => 'mt3s_mp_program_task_dependencies',
'initiative_task_raci' => 'mt3s_mp_program_task_raci',
'initiative_task_raci_stakeholders' => 'mt3s_mp_program_task_raci_stakeholders',
'initiative_stakeholders' => 'mt3s_mp_program_stakeholders',
'initiative_stakeholders_initiative' => 'mt3s_mp_program_stakeholders_program',
'initiative_audiences' => 'mt3s_mp_program_audiences',
'initiative_audiences_initiative' => 'mt3s_mp_program_audiences_program',
'initiative_audiences_segments' => 'mt3s_mp_program_audiences_segments',
'initiative_audiences_stages' => 'mt3s_mp_program_audiences_stages',
];
/**
* Table (any of its names) => [old column => new column, definition].
*/
private const COLUMNS = [
['initiative_objectives', 'mt3s_mp_program_objectives', 'initiative_id', 'program_id', 'INT UNSIGNED NOT NULL'],
['initiative_description_items', 'mt3s_mp_program_description_items', 'initiative_id', 'program_id', 'INT UNSIGNED NOT NULL'],
['initiative_allocation_items', 'mt3s_mp_program_allocation_items', 'initiative_id', 'program_id', 'INT UNSIGNED NOT NULL'],
['initiative_tasks', 'mt3s_mp_program_tasks', 'initiative_id', 'program_id', 'INT UNSIGNED NOT NULL'],
['initiative_stakeholders_initiative', 'mt3s_mp_program_stakeholders_program', 'initiative_id', 'program_id', 'INT UNSIGNED NOT NULL'],
['initiative_stakeholders_initiative', 'mt3s_mp_program_stakeholders_program', 'role_in_initiative', 'role_in_program', 'VARCHAR(191) DEFAULT NULL'],
['initiative_audiences_initiative', 'mt3s_mp_program_audiences_program', 'initiative_id', 'program_id', 'INT UNSIGNED NOT NULL'],
];
protected function isApplicable(Schema $schema): bool
{
foreach (self::TABLES as $from => $to) {
if ($schema->hasTable($this->concatPrefix($from))) {
return true;
}
}
foreach (self::COLUMNS as [$fromTable, $toTable, $fromColumn]) {
$table = $this->getTableName($schema, [$fromTable, $toTable]);
if (null !== $table) {
foreach ($schema->getTable($table)->getColumns() as $name => $column) {
if (strtolower($name) === strtolower($fromColumn)) {
return true;
}
}
}
}
// The pre-rename plugins row: the update target of an installed 0.16.0.
try {
$row = $this->entityManager->getConnection()->fetchOne(
sprintf("SELECT id FROM %s WHERE bundle = 'ProgramBundle'", $this->concatPrefix('plugins'))
);
} catch (\Throwable) {
$row = false;
}
return false !== $row;
}
protected function up(): void
{
// Tables, one rename at a time; stable database names unique.
foreach (self::TABLES as $from => $to) {
$this->renameTableIfExists($from, $to);
}
// Columns, resolving each table to whichever name it has now.
foreach (self::COLUMNS as [$fromTable, $toTable, $fromColumn, $toColumn, $definition]) {
$this->renameColumnIfExists([$fromTable, $toTable], $fromColumn, $toColumn, $definition);
}
$this->carryRowsOver();
}
/**
* The rows the rename orphans: the plugin's own, the roles' permissions, the categories and
* the audit log.
*/
private function carryRowsOver(): void
{
$connection = $this->entityManager->getConnection();
// The plugins row: keep the install an update of the same plugin, not a new one.
$oldBundle = $connection->fetchOne(
sprintf("SELECT id FROM %s WHERE bundle = 'ProgramBundle'", $this->concatPrefix('plugins'))
);
if (false !== $oldBundle) {
$connection->executeStatement(sprintf(
"UPDATE %s SET bundle = 'MT3SMarketingProgramBundle', name = 'MT3S Marketing Program' WHERE bundle = 'ProgramBundle'",
$this->concatPrefix('plugins')
));
}
// The roles' permission rows: the permission base follows the bundle name, and
// initiatives became programs (the 0.16.0 rename missed these).
$connection->executeStatement(sprintf(
"UPDATE %s SET name = 'programs' WHERE bundle = 'program' AND name = 'initiatives'",
$this->concatPrefix('permissions')
));
$connection->executeStatement(sprintf(
"UPDATE %s SET bundle = 'mt3smarketingprogram' WHERE bundle = 'program'",
$this->concatPrefix('permissions')
));
// The categories of the program category type (bundle column), plan-era rows included:
// the 0.16.0 rename left those behind too.
$connection->executeStatement(sprintf(
"UPDATE %s SET bundle = 'program' WHERE bundle IN ('plan', 'initiative')",
$this->concatPrefix('categories')
));
// The audit log rows about this plugin's entities.
$connection->executeStatement(sprintf(
"UPDATE %s SET bundle = 'MT3SMarketingProgramBundle' WHERE bundle IN ('PlanBundle', 'ProgramBundle')",
$this->concatPrefix('audit_logs')
));
}
/**
* Renames a table when the old name still exists and the new one doesn't.
*/
private function renameTableIfExists(string $from, string $to): void
{
$connection = $this->entityManager->getConnection();
if ($this->getTableName($connection->createSchemaManager()->introspectSchema(), [$from, $to]) === $this->concatPrefix($from)) {
$connection->executeStatement(sprintf(
'RENAME TABLE %1$s TO %2$s',
$this->concatPrefix($from),
$this->concatPrefix($to)
));
}
}
/**
* @param list<string> $tables the table's possible names, oldest first: the first that exists is used
*/
private function renameColumnIfExists(array $tables, string $fromColumn, string $toColumn, string $definition): void
{
$connection = $this->entityManager->getConnection();
$table = $this->getTableName($connection->createSchemaManager()->introspectSchema(), $tables);
if (null === $table) {
return;
}
foreach ($connection->createSchemaManager()->introspectTable($table)->getColumns() as $name => $column) {
if (strtolower($name) === strtolower($fromColumn)) {
$connection->executeStatement(sprintf(
'ALTER TABLE %s CHANGE %s %s %s',
$table,
$name,
$toColumn,
$definition
));
return;
}
}
}
/**
* The first of the given table names that exists, prefixed.
*
* @param list<string> $tables
*/
private function getTableName(Schema $schema, array $tables): ?string
{
foreach ($tables as $table) {
if ($schema->hasTable($this->concatPrefix($table))) {
return $this->concatPrefix($table);
}
}
return null;
}
}
+4 -6
View File
@@ -2,13 +2,11 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Initiative;
/**
* Brings the plans table in line with the entity mapping.
*
@@ -50,14 +48,14 @@ class Version_0_2_0 extends AbstractMigration
if ($this->statusNeedsResize($table)) {
$this->addSql(sprintf(
'ALTER TABLE %s MODIFY status VARCHAR(%d) NOT NULL',
$this->concatPrefix(Initiative::TABLE_NAME),
$this->concatPrefix('initiatives'),
self::STATUS_LENGTH
));
}
foreach ($this->getMissingForeignKeys($table) as $column => $referenceTable) {
$this->addSql($this->generateAlterTableForeignKeyStatement(
Initiative::TABLE_NAME,
'initiatives',
[$column],
$referenceTable,
['id'],
@@ -68,7 +66,7 @@ class Version_0_2_0 extends AbstractMigration
private function getTable(Schema $schema): ?Table
{
$name = $this->concatPrefix(Initiative::TABLE_NAME);
$name = $this->concatPrefix('initiatives');
return $schema->hasTable($name) ? $schema->getTable($name) : null;
}
+5 -8
View File
@@ -2,13 +2,10 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\ProgramBundle\Entity\InitiativeObjective;
/**
* Adds plans.version and the initiative_objectives table to installs created before 0.3.0.
*
@@ -28,16 +25,16 @@ class Version_0_3_0 extends AbstractMigration
protected function up(): void
{
$schema = $this->entityManager->getConnection()->createSchemaManager()->introspectSchema();
$plans = $this->concatPrefix(Initiative::TABLE_NAME);
$objectives = $this->concatPrefix(InitiativeObjective::TABLE_NAME);
$plans = $this->concatPrefix('initiatives');
$objectives = $this->concatPrefix('initiative_objectives');
if (!$schema->getTable($plans)->hasColumn('version')) {
$this->addSql("ALTER TABLE {$plans} ADD version SMALLINT UNSIGNED DEFAULT 1 NOT NULL");
}
if (!$schema->hasTable($objectives)) {
$index = $this->generatePropertyName(InitiativeObjective::TABLE_NAME, 'idx', ['plan_id']);
$foreignKey = $this->generatePropertyName(InitiativeObjective::TABLE_NAME, 'fk', ['plan_id']);
$index = $this->generatePropertyName('initiative_objectives', 'idx', ['plan_id']);
$foreignKey = $this->generatePropertyName('initiative_objectives', 'fk', ['plan_id']);
$this->addSql("CREATE TABLE {$objectives} (
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
+7 -8
View File
@@ -2,14 +2,13 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\ORM\Tools\SchemaTool;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\ProgramBundle\Entity\Task;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Task;
/**
* Adds the initiative_tasks table and its foreign keys to installs created before 0.4.0.
@@ -31,7 +30,7 @@ class Version_0_4_0 extends AbstractMigration
* so only plan_id is repaired here.
*/
private const FOREIGN_KEYS = [
'plan_id' => [Initiative::TABLE_NAME, 'CASCADE'],
'plan_id' => ['initiatives', 'CASCADE'],
];
protected function isApplicable(Schema $schema): bool
@@ -46,7 +45,7 @@ class Version_0_4_0 extends AbstractMigration
protected function up(): void
{
$schema = $this->entityManager->getConnection()->createSchemaManager()->introspectSchema();
$tasks = $this->concatPrefix(Task::TABLE_NAME);
$tasks = $this->concatPrefix('initiative_tasks');
$missingFk = self::FOREIGN_KEYS;
if (!$schema->hasTable($tasks)) {
@@ -57,7 +56,7 @@ class Version_0_4_0 extends AbstractMigration
foreach ($missingFk as $column => [$referenceTable, $onDelete]) {
$this->addSql($this->generateAlterTableForeignKeyStatement(
Task::TABLE_NAME,
'initiative_tasks',
[$column],
$referenceTable,
['id'],
@@ -69,7 +68,7 @@ class Version_0_4_0 extends AbstractMigration
private function getCreateTableSql(): string
{
$schemaTool = new SchemaTool($this->entityManager);
$prefix = 'CREATE TABLE '.$this->concatPrefix(Task::TABLE_NAME).' ';
$prefix = 'CREATE TABLE '.$this->concatPrefix('initiative_tasks').' ';
foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata(Task::class)]) as $sql) {
if (str_starts_with($sql, $prefix)) {
@@ -77,7 +76,7 @@ class Version_0_4_0 extends AbstractMigration
}
}
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.Task::TABLE_NAME.'.');
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.'initiative_tasks'.'.');
}
/**
+4 -4
View File
@@ -2,12 +2,12 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Task;
use MauticPlugin\ProgramBundle\Entity\TaskStatus;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Task;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\TaskStatus;
/**
* Adds start_date, end_date and status (default "new", indexed) to initiative_tasks, for installs created
@@ -28,7 +28,7 @@ class Version_0_5_0 extends AbstractMigration
protected function up(): void
{
$tasks = $this->concatPrefix(Task::TABLE_NAME);
$tasks = $this->concatPrefix('initiative_tasks');
$table = $this->entityManager->getConnection()->createSchemaManager()->introspectTable($tasks);
if (!$table->hasColumn('start_date')) {
+8 -11
View File
@@ -2,14 +2,11 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\Tools\SchemaTool;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\ProgramBundle\Entity\InitiativeDescriptionItem;
/**
* For installs created before 0.6.0:
* - creates initiative_description_items (and its foreign key to plans, ON DELETE CASCADE);
@@ -33,8 +30,8 @@ class Version_0_6_0 extends AbstractMigration
protected function up(): void
{
$schema = $this->entityManager->getConnection()->createSchemaManager()->introspectSchema();
$plans = $this->concatPrefix(Initiative::TABLE_NAME);
$items = $this->concatPrefix(InitiativeDescriptionItem::TABLE_NAME);
$plans = $this->concatPrefix('initiatives');
$items = $this->concatPrefix('initiative_description_items');
if (!$schema->hasTable($items)) {
$this->addSql($this->getCreateTableSql());
@@ -42,9 +39,9 @@ class Version_0_6_0 extends AbstractMigration
if (!$schema->hasTable($items) || !$this->hasPlanForeignKey($schema)) {
$this->addSql($this->generateAlterTableForeignKeyStatement(
InitiativeDescriptionItem::TABLE_NAME,
'initiative_description_items',
['plan_id'],
Initiative::TABLE_NAME,
'initiatives',
['id'],
'ON DELETE CASCADE'
));
@@ -57,7 +54,7 @@ class Version_0_6_0 extends AbstractMigration
private function hasPlanForeignKey(Schema $schema): bool
{
$items = $this->concatPrefix(InitiativeDescriptionItem::TABLE_NAME);
$items = $this->concatPrefix('initiative_description_items');
if (!$schema->hasTable($items)) {
return false;
@@ -75,7 +72,7 @@ class Version_0_6_0 extends AbstractMigration
private function getCreateTableSql(): string
{
$schemaTool = new SchemaTool($this->entityManager);
$prefix = 'CREATE TABLE '.$this->concatPrefix(InitiativeDescriptionItem::TABLE_NAME).' ';
$prefix = 'CREATE TABLE '.$this->concatPrefix('initiative_description_items').' ';
foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata(InitiativeDescriptionItem::class)]) as $sql) {
if (str_starts_with($sql, $prefix)) {
@@ -83,6 +80,6 @@ class Version_0_6_0 extends AbstractMigration
}
}
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.InitiativeDescriptionItem::TABLE_NAME.'.');
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.'initiative_description_items'.'.');
}
}
+7 -10
View File
@@ -2,14 +2,11 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\Tools\SchemaTool;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\ProgramBundle\Entity\InitiativeAllocationItem;
/**
* Creates initiative_allocation_items (and its foreign key to plans, ON DELETE CASCADE) for installs created
* before 0.7.0. Each step runs only if needed. As in Version_0_4_0, only the CREATE TABLE statement for
@@ -29,7 +26,7 @@ class Version_0_7_0 extends AbstractMigration
protected function up(): void
{
$schema = $this->entityManager->getConnection()->createSchemaManager()->introspectSchema();
$items = $this->concatPrefix(InitiativeAllocationItem::TABLE_NAME);
$items = $this->concatPrefix('initiative_allocation_items');
if (!$schema->hasTable($items)) {
$this->addSql($this->getCreateTableSql());
@@ -37,9 +34,9 @@ class Version_0_7_0 extends AbstractMigration
if (!$this->hasPlanForeignKey($schema)) {
$this->addSql($this->generateAlterTableForeignKeyStatement(
InitiativeAllocationItem::TABLE_NAME,
'initiative_allocation_items',
['plan_id'],
Initiative::TABLE_NAME,
'initiatives',
['id'],
'ON DELETE CASCADE'
));
@@ -48,7 +45,7 @@ class Version_0_7_0 extends AbstractMigration
private function hasPlanForeignKey(Schema $schema): bool
{
$items = $this->concatPrefix(InitiativeAllocationItem::TABLE_NAME);
$items = $this->concatPrefix('initiative_allocation_items');
if (!$schema->hasTable($items)) {
return false;
@@ -66,7 +63,7 @@ class Version_0_7_0 extends AbstractMigration
private function getCreateTableSql(): string
{
$schemaTool = new SchemaTool($this->entityManager);
$prefix = 'CREATE TABLE '.$this->concatPrefix(InitiativeAllocationItem::TABLE_NAME).' ';
$prefix = 'CREATE TABLE '.$this->concatPrefix('initiative_allocation_items').' ';
foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata(InitiativeAllocationItem::class)]) as $sql) {
if (str_starts_with($sql, $prefix)) {
@@ -74,6 +71,6 @@ class Version_0_7_0 extends AbstractMigration
}
}
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.InitiativeAllocationItem::TABLE_NAME.'.');
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.'initiative_allocation_items'.'.');
}
}
+3 -6
View File
@@ -2,13 +2,10 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\ProgramBundle\Entity\InitiativeAllocationItem;
/**
* Since 0.8.0 every amount is in one general currency (Settings > Configuration > Plan Settings, parameter
* program_currency), so the per-record currency columns are dropped: plans.currency,
@@ -21,8 +18,8 @@ class Version_0_8_0 extends AbstractMigration
* Table => columns to drop.
*/
private const COLUMNS = [
Initiative::TABLE_NAME => ['currency'],
InitiativeAllocationItem::TABLE_NAME => ['planned_currency', 'real_currency'],
'initiatives' => ['currency'],
'initiative_allocation_items' => ['planned_currency', 'real_currency'],
];
protected function isApplicable(Schema $schema): bool
+3 -3
View File
@@ -2,11 +2,11 @@
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Migrations;
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\ProgramBundle\Entity\Task;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Task;
/**
* Since 0.9.0 tasks have a type, the key of a task type set up in Settings > Configuration > Plan
@@ -27,7 +27,7 @@ class Version_0_9_0 extends AbstractMigration
protected function up(): void
{
$tasks = $this->concatPrefix(Task::TABLE_NAME);
$tasks = $this->concatPrefix('initiative_tasks');
$table = $this->entityManager->getConnection()->createSchemaManager()->introspectTable($tasks);
if (!$table->hasColumn('type')) {