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,15 +2,15 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\Migrations;
|
||||
namespace MauticPlugin\ProgramBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\PlanBundle\Entity\PlanObjective;
|
||||
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 plan_objectives.type for
|
||||
* Configuration > Plan Settings (parameter plan_objective_types). Adds initiative_objectives.type for
|
||||
* installs created before 0.10.0. The column is nullable: existing objectives have no type yet, and
|
||||
* each one must be given a type before the plan can be saved again (validation requires it). Runs only
|
||||
* when the column is missing.
|
||||
@@ -19,22 +19,20 @@ class Version_0_10_0 extends AbstractMigration
|
||||
{
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
$objectives = $this->concatPrefix(PlanObjective::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($objectives)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !$schema->getTable($objectives)->hasColumn('type');
|
||||
// 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
|
||||
{
|
||||
$objectives = $this->concatPrefix(PlanObjective::TABLE_NAME);
|
||||
$objectives = $this->concatPrefix(InitiativeObjective::TABLE_NAME);
|
||||
$table = $this->entityManager->getConnection()->createSchemaManager()->introspectTable($objectives);
|
||||
|
||||
if (!$table->hasColumn('type')) {
|
||||
$this->addSql(sprintf('ALTER TABLE %s ADD type VARCHAR(%d) DEFAULT NULL', $objectives, PlanObjective::TYPE_MAX_LENGTH));
|
||||
$this->addSql(sprintf('ALTER TABLE %s ADD type VARCHAR(%d) DEFAULT NULL', $objectives, InitiativeObjective::TYPE_MAX_LENGTH));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,40 +2,38 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\Migrations;
|
||||
namespace MauticPlugin\ProgramBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\PlanBundle\Entity\PlanObjective;
|
||||
use MauticPlugin\ProgramBundle\Entity\InitiativeObjective;
|
||||
|
||||
/**
|
||||
* Since 0.10.1 objectives have a priority, a whole number from 1 (highest) to 99 (lowest). Adds
|
||||
* plan_objectives.priority for installs created before 0.10.1: NOT NULL with the default 1, and the
|
||||
* initiative_objectives.priority for installs created before 0.10.1: NOT NULL with the default 1, and the
|
||||
* existing objectives get that default. Runs only when the column is missing.
|
||||
*/
|
||||
class Version_0_10_1 extends AbstractMigration
|
||||
{
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
$objectives = $this->concatPrefix(PlanObjective::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($objectives)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !$schema->getTable($objectives)->hasColumn('priority');
|
||||
// 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
|
||||
{
|
||||
$objectives = $this->concatPrefix(PlanObjective::TABLE_NAME);
|
||||
$objectives = $this->concatPrefix(InitiativeObjective::TABLE_NAME);
|
||||
$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,
|
||||
PlanObjective::PRIORITY_MIN
|
||||
InitiativeObjective::PRIORITY_MIN
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
|
||||
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\PlanStakeholder;
|
||||
use MauticPlugin\PlanBundle\Entity\Stakeholder;
|
||||
use MauticPlugin\ProgramBundle\Entity\Initiative;
|
||||
use MauticPlugin\ProgramBundle\Entity\InitiativeStakeholder;
|
||||
use MauticPlugin\ProgramBundle\Entity\Stakeholder;
|
||||
|
||||
/**
|
||||
* Since 0.12.0 planning has a global stakeholder directory (table plan_stakeholders), and each plan
|
||||
* links to its stakeholders through plan_stakeholders_plan, which carries the stakeholder's role in
|
||||
* Since 0.12.0 planning has a global stakeholder directory (table initiative_stakeholders), and each plan
|
||||
* links to its stakeholders through initiative_stakeholders_initiative, which carries the stakeholder's role in
|
||||
* the plan. Creates both tables for installs created before 0.12.0, and repairs the ones the plugin
|
||||
* installer created without foreign keys (it drops foreign keys that point to core tables). Each step
|
||||
* runs only if needed.
|
||||
@@ -22,16 +22,11 @@ class Version_0_12_0 extends AbstractMigration
|
||||
{
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
if (!$schema->hasTable($this->concatPrefix(Plan::TABLE_NAME))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$schema->hasTable($this->concatPrefix(Stakeholder::TABLE_NAME))
|
||||
|| !$schema->hasTable($this->concatPrefix(PlanStakeholder::TABLE_NAME))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !$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
|
||||
@@ -42,20 +37,20 @@ class Version_0_12_0 extends AbstractMigration
|
||||
$this->addSql($this->getCreateTableSql(Stakeholder::class, Stakeholder::TABLE_NAME));
|
||||
}
|
||||
|
||||
if (!$schema->hasTable($this->concatPrefix(PlanStakeholder::TABLE_NAME))) {
|
||||
$this->addSql($this->getCreateTableSql(PlanStakeholder::class, PlanStakeholder::TABLE_NAME));
|
||||
if (!$schema->hasTable($this->concatPrefix(InitiativeStakeholder::TABLE_NAME))) {
|
||||
$this->addSql($this->getCreateTableSql(InitiativeStakeholder::class, InitiativeStakeholder::TABLE_NAME));
|
||||
}
|
||||
|
||||
if (!$this->hasForeignKeys($schema)) {
|
||||
$this->addSql($this->generateAlterTableForeignKeyStatement(
|
||||
PlanStakeholder::TABLE_NAME,
|
||||
InitiativeStakeholder::TABLE_NAME,
|
||||
['plan_id'],
|
||||
Plan::TABLE_NAME,
|
||||
Initiative::TABLE_NAME,
|
||||
['id'],
|
||||
'ON DELETE CASCADE'
|
||||
));
|
||||
$this->addSql($this->generateAlterTableForeignKeyStatement(
|
||||
PlanStakeholder::TABLE_NAME,
|
||||
InitiativeStakeholder::TABLE_NAME,
|
||||
['stakeholder_id'],
|
||||
Stakeholder::TABLE_NAME,
|
||||
['id'],
|
||||
@@ -69,7 +64,7 @@ class Version_0_12_0 extends AbstractMigration
|
||||
*/
|
||||
private function hasForeignKeys(Schema $schema): bool
|
||||
{
|
||||
$links = $this->concatPrefix(PlanStakeholder::TABLE_NAME);
|
||||
$links = $this->concatPrefix(InitiativeStakeholder::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($links)) {
|
||||
return false;
|
||||
|
||||
@@ -2,21 +2,21 @@
|
||||
|
||||
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\Task;
|
||||
use MauticPlugin\PlanBundle\Entity\TaskDependency;
|
||||
use MauticPlugin\PlanBundle\Entity\TaskRaci;
|
||||
use MauticPlugin\ProgramBundle\Entity\Task;
|
||||
use MauticPlugin\ProgramBundle\Entity\TaskDependency;
|
||||
use MauticPlugin\ProgramBundle\Entity\TaskRaci;
|
||||
|
||||
/**
|
||||
* Since 0.13.0 tasks are reworked:
|
||||
* - start_date and end_date become DATE (no time); existing values are truncated to the date;
|
||||
* - new columns task_kind (default 'task'), definition_of_done, planned_work;
|
||||
* - new tables plan_task_dependencies (dependency graph) and plan_task_raci with its
|
||||
* plan_task_raci_stakeholders join table;
|
||||
* - new tables initiative_task_dependencies (dependency graph) and initiative_task_raci with its
|
||||
* initiative_task_raci_stakeholders join table;
|
||||
* - the parent/child tree is dropped: parent_id and its index are removed, replaced by the
|
||||
* dependency graph.
|
||||
*
|
||||
@@ -26,21 +26,11 @@ class Version_0_13_0 extends AbstractMigration
|
||||
{
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
$tasks = $this->concatPrefix(Task::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($tasks)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$table = $schema->getTable($tasks);
|
||||
|
||||
return !$table->hasColumn('task_kind')
|
||||
|| !$table->hasColumn('definition_of_done')
|
||||
|| !$table->hasColumn('planned_work')
|
||||
|| $table->hasColumn('parent_id')
|
||||
|| !$schema->hasTable($this->concatPrefix(TaskDependency::TABLE_NAME))
|
||||
|| !$schema->hasTable($this->concatPrefix(TaskRaci::TABLE_NAME))
|
||||
|| !$schema->hasTable($this->concatPrefix(TaskRaci::JOIN_TABLE_NAME));
|
||||
// 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
|
||||
@@ -53,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\PlanBundle\Entity\TaskKind::Task->value
|
||||
\MauticPlugin\ProgramBundle\Entity\TaskKind::Task->value
|
||||
));
|
||||
}
|
||||
if (!$table->hasColumn('definition_of_done')) {
|
||||
@@ -91,8 +81,8 @@ class Version_0_13_0 extends AbstractMigration
|
||||
$this->addSql($sql);
|
||||
}
|
||||
}
|
||||
// The RACI join table comes with the TaskRaci entity's SQL (CREATE TABLE plan_task_raci_stakeholders),
|
||||
// but it may be missing while plan_task_raci exists (a partial earlier run).
|
||||
// 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) {
|
||||
$this->addSql($sql);
|
||||
@@ -107,7 +97,7 @@ class Version_0_13_0 extends AbstractMigration
|
||||
|
||||
/**
|
||||
* The CREATE TABLE statements of one of this migration's entities, from Doctrine's SchemaTool —
|
||||
* the entity's table and, for TaskRaci, its join table plan_task_raci_stakeholders too.
|
||||
* the entity's table and, for TaskRaci, its join table initiative_task_raci_stakeholders too.
|
||||
*
|
||||
* @param class-string $entityClass
|
||||
*
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\ProgramBundle\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;
|
||||
|
||||
/**
|
||||
* Since 0.14.0 audiences are a global directory (Planning > Audiences, called Targets before 0.15.0),
|
||||
* like stakeholders:
|
||||
* - the existing initiative_audiences rows become the directory entries; is_published and the audit
|
||||
* columns (FormEntity) are added;
|
||||
* - the new persona attributes are added: tagline, motivations, barriers, frustrations
|
||||
* (replacing pain_points, whose texts are moved), triggers, decision_role, preferred_tones;
|
||||
* - the initiative-specific fields (priority, value proposition, position) move to the new link table
|
||||
* initiative_audiences_initiative, one row per (plan, target); the existing rows are copied there, then the
|
||||
* initiative-specific columns (and plan_id) are dropped from initiative_audiences.
|
||||
*
|
||||
* Since 0.15.0 the tables are named initiative_audiences and initiative_audiences_initiative: this migration only
|
||||
* still applies to an install on 0.13.x with the old names, or to repair one the plugin installer
|
||||
* created without foreign keys (it drops foreign keys that point to core tables). Each step runs
|
||||
* only if needed. Which persona attributes are offered is an admin setting (AudienceAttributes).
|
||||
*/
|
||||
class Version_0_14_0 extends AbstractMigration
|
||||
{
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
// 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();
|
||||
|
||||
$names = $this->getTableNames($schema);
|
||||
|
||||
// Fresh install created before 0.11.0: no directory table yet. Nothing to migrate here.
|
||||
if (null === $names) {
|
||||
return;
|
||||
}
|
||||
|
||||
[$directory, $links] = $names;
|
||||
$oldNaming = 'initiative_audiences' === $directory;
|
||||
|
||||
$table = $schema->getTable($directory);
|
||||
$shared = fn (string $column): bool => $table->hasColumn($this->concatPrefix($column));
|
||||
|
||||
// Directory columns: is_published and the audit columns of FormEntity (the installer adds
|
||||
// them on a fresh install; they are missing only on an upgrade from 0.13.0).
|
||||
if (!$shared('is_published')) {
|
||||
$this->addSql(sprintf('ALTER TABLE %s ADD is_published TINYINT(1) NOT NULL DEFAULT 1', $directory));
|
||||
$this->addSql(sprintf(
|
||||
'ALTER TABLE %1$s ADD date_added DATETIME DEFAULT NULL, ADD created_by INT DEFAULT NULL, '.
|
||||
'ADD created_by_user VARCHAR(191) DEFAULT NULL, ADD date_modified DATETIME DEFAULT NULL, '.
|
||||
'ADD modified_by INT DEFAULT NULL, ADD modified_by_user VARCHAR(191) DEFAULT NULL, '.
|
||||
'ADD checked_out DATETIME DEFAULT NULL, ADD checked_out_by INT DEFAULT NULL, '.
|
||||
'ADD checked_out_by_user VARCHAR(191) DEFAULT NULL',
|
||||
$directory
|
||||
));
|
||||
}
|
||||
|
||||
// The new persona attributes (free text).
|
||||
foreach (['tagline', 'motivations', 'barriers', 'triggers'] as $column) {
|
||||
if (!$shared($column)) {
|
||||
$this->addSql(sprintf('ALTER TABLE %s ADD %s LONGTEXT DEFAULT NULL', $directory, $column));
|
||||
}
|
||||
}
|
||||
|
||||
// frustrations replaces pain_points: add the column, move the texts, then drop the old one
|
||||
// (dropped with the initiative-specific columns below, in one sweep).
|
||||
if (!$shared('frustrations')) {
|
||||
$this->addSql(sprintf('ALTER TABLE %s ADD frustrations LONGTEXT DEFAULT NULL', $directory));
|
||||
if ($shared('pain_points')) {
|
||||
$this->addSql(sprintf(
|
||||
'UPDATE %s SET frustrations = pain_points WHERE frustrations IS NULL AND pain_points IS NOT NULL',
|
||||
$directory
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// decision_role: a key of the admin-configured list (program_audience_decision_roles).
|
||||
if (!$shared('decision_role')) {
|
||||
$this->addSql(sprintf('ALTER TABLE %s ADD decision_role VARCHAR(64) DEFAULT NULL', $directory));
|
||||
}
|
||||
|
||||
// preferred_tones: a JSON list of keys of the admin-configured list (program_audience_tones).
|
||||
if (!$shared('preferred_tones')) {
|
||||
$this->addSql(sprintf("ALTER TABLE %s ADD preferred_tones LONGTEXT DEFAULT NULL COMMENT '(DC2Type:json)'", $directory));
|
||||
}
|
||||
|
||||
// The link table, one row per (plan, audience), with the initiative-specific fields. Under the old
|
||||
// naming it keeps the old names (initiative_audiences_initiative, target_id); 0.15.0 renames both.
|
||||
if (!$schema->hasTable($links)) {
|
||||
$linkIdColumn = $oldNaming ? 'target_id' : 'audience_id';
|
||||
$this->addSql(sprintf(
|
||||
'CREATE TABLE IF NOT EXISTS %s (id INT UNSIGNED AUTO_INCREMENT NOT NULL, '.
|
||||
'plan_id INT UNSIGNED NOT NULL, %s INT UNSIGNED NOT NULL, priority VARCHAR(20) NOT NULL, '.
|
||||
'value_proposition LONGTEXT DEFAULT NULL, position INT NOT NULL, '.
|
||||
'INDEX IDX_%1$s_PLAN (plan_id), INDEX IDX_%1$s_LINK (%2$s), '.
|
||||
'PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB',
|
||||
$links,
|
||||
$linkIdColumn
|
||||
));
|
||||
|
||||
// Copy the existing rows: each audience of each plan becomes a directory entry plus a
|
||||
// link carrying the initiative-specific fields. The position follows the id order, so the
|
||||
// tab shows the same order as before the migration.
|
||||
if ($shared('plan_id')) {
|
||||
$this->addSql(sprintf(
|
||||
'INSERT INTO %1$s (plan_id, %2$s, priority, value_proposition, position) '.
|
||||
'SELECT t.plan_id, t.id, t.priority, t.value_proposition, '.
|
||||
'(SELECT COUNT(*) FROM %1$s l WHERE l.plan_id = t.plan_id AND l.%2$s <= t.id) '.
|
||||
'FROM %3$s t WHERE t.plan_id IS NOT NULL ORDER BY t.id ASC',
|
||||
$links,
|
||||
$linkIdColumn,
|
||||
$directory
|
||||
));
|
||||
|
||||
// The directory entry no longer belongs to a plan; the initiative-specific fields moved
|
||||
// to the link table; pain_points moved to frustrations; position is the link's.
|
||||
// Drop the old plan_id foreign key first: it would block the column drop.
|
||||
foreach ($schema->getTable($directory)->getForeignKeys() as $foreignKey) {
|
||||
if (in_array($this->concatPrefix('plan_id'), $foreignKey->getLocalColumns(), true)) {
|
||||
$this->addSql(sprintf('ALTER TABLE %s DROP FOREIGN KEY %s', $directory, $foreignKey->getName()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['plan_id', 'priority', 'value_proposition', 'position', 'pain_points'] as $column) {
|
||||
if ($shared($column)) {
|
||||
$this->addSql(sprintf('ALTER TABLE %s DROP COLUMN %s', $directory, $column));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Repair the foreign keys the plugin installer stripped (it drops the ones that point to
|
||||
// core tables, such as plans, at install time).
|
||||
if (!$this->hasForeignKeys($schema)) {
|
||||
$this->addSql($this->generateAlterTableForeignKeyStatement(
|
||||
$oldNaming ? 'initiative_audiences_initiative' : InitiativeAudience::TABLE_NAME,
|
||||
['plan_id'],
|
||||
Initiative::TABLE_NAME,
|
||||
['id'],
|
||||
'ON DELETE CASCADE'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The directory and link table names this install uses: the current ones (initiative_audiences,
|
||||
* initiative_audiences_initiative, since 0.15.0) or the ones before 0.15.0 (initiative_audiences, initiative_audiences_initiative).
|
||||
* Null when neither exists (a fresh install created before 0.11.0).
|
||||
*
|
||||
* @return array{string, string}|null
|
||||
*/
|
||||
private function getTableNames(Schema $schema): ?array
|
||||
{
|
||||
foreach ([
|
||||
[Audience::TABLE_NAME, InitiativeAudience::TABLE_NAME],
|
||||
['initiative_audiences', 'initiative_audiences_initiative'],
|
||||
] as [$directory, $links]) {
|
||||
if ($schema->hasTable($this->concatPrefix($directory))) {
|
||||
return [$this->concatPrefix($directory), $this->concatPrefix($links)];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the link table's plan_id foreign key exists (the one the installer strips; the
|
||||
* audience_id one points to a plugin table and survives). Checks the link table under either
|
||||
* naming (initiative_audiences_initiative before 0.15.0, initiative_audiences_initiative since).
|
||||
*/
|
||||
private function hasForeignKeys(Schema $schema): bool
|
||||
{
|
||||
foreach (['initiative_audiences_initiative', InitiativeAudience::TABLE_NAME] as $links) {
|
||||
$links = $this->concatPrefix($links);
|
||||
|
||||
if (!$schema->hasTable($links)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($schema->getTable($links)->getForeignKeys() as $foreignKey) {
|
||||
if (in_array('plan_id', $foreignKey->getLocalColumns(), true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// No link table (fresh install from before 0.11.0): up() creates it from the
|
||||
// mapping, foreign keys included — nothing to repair first.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\ProgramBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\ProgramBundle\Entity\Audience;
|
||||
use MauticPlugin\ProgramBundle\Entity\Initiative;
|
||||
|
||||
/**
|
||||
* 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),
|
||||
* plan_targets_plan became plan_audiences_plan (target_id became audience_id), plan_target_stages
|
||||
* became plan_audiences_stages — and created the segments join table plan_audiences_segments.
|
||||
*
|
||||
* Since 0.16.0 the tables are named initiative_* (the 0.16.0 migration renames them), so this
|
||||
* migration only still applies to an install upgrading from 0.14.x or older, which still carries
|
||||
* the plan_targets-era names. The names of that era are kept literal here on purpose.
|
||||
*/
|
||||
class Version_0_15_0 extends AbstractMigration
|
||||
{
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
if (!$schema->hasTable($this->concatPrefix(Initiative::TABLE_NAME))
|
||||
&& !$schema->hasTable($this->concatPrefix('plans'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The pre-0.15.0 names, or a missing piece of the 0.15.0 schema.
|
||||
return $schema->hasTable($this->concatPrefix('plan_targets'))
|
||||
|| $schema->hasTable($this->concatPrefix('plan_targets_plan'))
|
||||
|| $schema->hasTable($this->concatPrefix('plan_target_stages'))
|
||||
|| $this->needsColumnNameRename($schema, ['plan_targets', 'plan_audiences'], 'target_type')
|
||||
|| $this->needsColumnNameRename($schema, ['plan_targets_plan', 'plan_audiences_plan'], 'target_id')
|
||||
|| $this->needsColumnNameRename($schema, ['plan_target_stages', 'plan_audiences_stages'], 'target_id')
|
||||
|| !$schema->hasTable($this->concatPrefix('plan_audiences_segments'))
|
||||
|| $this->needsForeignKey($schema, 'plan_audiences_plan', 'plan_id')
|
||||
|| $this->needsForeignKey($schema, 'plan_audiences_segments', 'audience_id');
|
||||
}
|
||||
|
||||
protected function up(): void
|
||||
{
|
||||
// The directory table: plan_targets becomes plan_audiences.
|
||||
$this->renameTableIfExists('plan_targets', 'plan_audiences');
|
||||
|
||||
// Its type column: target_type becomes audience_type (on whichever name the table has now).
|
||||
$this->renameColumnIfExists(
|
||||
['plan_targets', 'plan_audiences'],
|
||||
'target_type',
|
||||
'audience_type',
|
||||
"VARCHAR(30) NOT NULL DEFAULT 'persona'"
|
||||
);
|
||||
|
||||
// The link table: plan_targets_plan becomes plan_audiences_plan.
|
||||
$this->renameTableIfExists('plan_targets_plan', 'plan_audiences_plan');
|
||||
|
||||
// Its audience reference: target_id becomes audience_id.
|
||||
$this->renameColumnIfExists(
|
||||
['plan_targets_plan', 'plan_audiences_plan'],
|
||||
'target_id',
|
||||
'audience_id',
|
||||
'INT UNSIGNED NOT NULL'
|
||||
);
|
||||
|
||||
// The stages join table: plan_target_stages becomes plan_audiences_stages.
|
||||
$this->renameTableIfExists('plan_target_stages', 'plan_audiences_stages');
|
||||
|
||||
// Same column rename, on whichever name the table has now.
|
||||
$this->renameColumnIfExists(
|
||||
['plan_target_stages', 'plan_audiences_stages'],
|
||||
'target_id',
|
||||
'audience_id',
|
||||
'INT UNSIGNED NOT NULL'
|
||||
);
|
||||
|
||||
// The segments join table: purely informational, created empty when missing.
|
||||
$this->createSegmentsTableIfMissing();
|
||||
|
||||
// The link table's plan_id foreign key, on the installs where it's missing.
|
||||
$this->repairLinkForeignKeyIfMissing();
|
||||
|
||||
// The segments table's audience_id foreign key: deleting an audience deletes its links.
|
||||
$this->repairSegmentsForeignKeyIfMissing();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the first of the tables that exists still carries the old column.
|
||||
*
|
||||
* @param list<string> $tables
|
||||
*/
|
||||
private function needsColumnNameRename(Schema $schema, array $tables, string $column): bool
|
||||
{
|
||||
$table = $this->getTableName($schema, $tables);
|
||||
|
||||
if (null === $table) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($schema->getTable($table)->getColumns() as $name => $columnObject) {
|
||||
if (strtolower($name) === strtolower($column)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the table exists and lacks a foreign key on the given column.
|
||||
*/
|
||||
private function needsForeignKey(Schema $schema, string $table, string $column): bool
|
||||
{
|
||||
$table = $this->concatPrefix($table);
|
||||
|
||||
if (!$schema->hasTable($table)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($schema->getTable($table)->getForeignKeys() as $foreignKey) {
|
||||
if (in_array($column, $foreignKey->getLocalColumns(), true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
private function createSegmentsTableIfMissing(): void
|
||||
{
|
||||
$connection = $this->entityManager->getConnection();
|
||||
|
||||
if ($connection->createSchemaManager()->introspectSchema()->hasTable($this->concatPrefix('initiative_audiences_segments'))
|
||||
|| $connection->createSchemaManager()->introspectSchema()->hasTable($this->concatPrefix('plan_audiences_segments'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$connection->executeStatement(sprintf(
|
||||
'CREATE TABLE IF NOT EXISTS %s (audience_id INT UNSIGNED NOT NULL, leadlist_id INT UNSIGNED NOT NULL, '.
|
||||
'INDEX IDX_%1$s_AUDIENCE (audience_id), INDEX IDX_%1$s_LEADLIST (leadlist_id), '.
|
||||
'PRIMARY KEY (audience_id, leadlist_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB',
|
||||
$this->concatPrefix('plan_audiences_segments')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the link table's plan_id foreign key when it's missing (the plugin installer drops
|
||||
* the foreign keys that point to core tables, such as plans — initiatives since 0.16.0).
|
||||
*/
|
||||
private function repairLinkForeignKeyIfMissing(): void
|
||||
{
|
||||
$connection = $this->entityManager->getConnection();
|
||||
$schema = $connection->createSchemaManager()->introspectSchema();
|
||||
$links = $this->getTableName($schema, ['plan_targets_plan', 'plan_audiences_plan']);
|
||||
|
||||
if (null === $links) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($schema->getTable($links)->getForeignKeys() as $foreignKey) {
|
||||
if (in_array('plan_id', $foreignKey->getLocalColumns(), true)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$connection->executeStatement(sprintf(
|
||||
'ALTER TABLE %1$s ADD CONSTRAINT FK_%1$s_plan_id FOREIGN KEY (plan_id) REFERENCES %2$s (id) ON DELETE CASCADE',
|
||||
$links,
|
||||
$this->concatPrefix('plans')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the segments table's audience_id foreign key when it's missing.
|
||||
*/
|
||||
private function repairSegmentsForeignKeyIfMissing(): void
|
||||
{
|
||||
$connection = $this->entityManager->getConnection();
|
||||
$schema = $connection->createSchemaManager()->introspectSchema();
|
||||
$segments = $this->getTableName($schema, ['initiative_audiences_segments', 'plan_audiences_segments']);
|
||||
|
||||
if (null === $segments) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($schema->getTable($segments)->getForeignKeys() as $foreignKey) {
|
||||
if (in_array('audience_id', $foreignKey->getLocalColumns(), true)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$audiences = $this->getTableName($schema, ['initiative_audiences', 'plan_audiences']);
|
||||
if (null === $audiences) {
|
||||
return;
|
||||
}
|
||||
|
||||
$connection->executeStatement(sprintf(
|
||||
'ALTER TABLE %1$s ADD CONSTRAINT FK_%1$s_audience_id FOREIGN KEY (audience_id) REFERENCES %2$s (id) ON DELETE CASCADE',
|
||||
$segments,
|
||||
$audiences
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\ProgramBundle\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
|
||||
* menu is Programs, the Plans page is Initiatives. The database follows:
|
||||
* - plans becomes initiatives;
|
||||
* - plan_objectives, plan_description_items, plan_allocation_items become initiative_*;
|
||||
* - plan_tasks, plan_task_dependencies, plan_task_raci, plan_task_raci_stakeholders become
|
||||
* initiative_*;
|
||||
* - plan_stakeholders, plan_stakeholders_plan become initiative_stakeholders and
|
||||
* initiative_stakeholders_initiative;
|
||||
* - plan_audiences, plan_audiences_plan, plan_audiences_segments, plan_audiences_stages become
|
||||
* initiative_*;
|
||||
* - the link tables' plan_id columns become initiative_id; plan_stakeholders_plan's
|
||||
* role_in_plan becomes role_in_initiative; plan_tasks' plan_id becomes initiative_id.
|
||||
*
|
||||
* 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_16_0 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Old table name => new table name, in dependency order (the audited tables first, then the
|
||||
* ones whose foreign keys point at them — RENAME TABLE takes both in one statement when
|
||||
* needed, but one rename per line keeps half-applied states recoverable).
|
||||
*/
|
||||
private const TABLES = [
|
||||
'plans' => 'initiatives',
|
||||
'plan_objectives' => 'initiative_objectives',
|
||||
'plan_description_items' => 'initiative_description_items',
|
||||
'plan_allocation_items' => 'initiative_allocation_items',
|
||||
'plan_tasks' => 'initiative_tasks',
|
||||
'plan_task_dependencies' => 'initiative_task_dependencies',
|
||||
'plan_task_raci' => 'initiative_task_raci',
|
||||
'plan_task_raci_stakeholders' => 'initiative_task_raci_stakeholders',
|
||||
'plan_stakeholders' => 'initiative_stakeholders',
|
||||
'plan_stakeholders_plan' => 'initiative_stakeholders_initiative',
|
||||
'plan_audiences' => 'initiative_audiences',
|
||||
'plan_audiences_plan' => 'initiative_audiences_initiative',
|
||||
'plan_audiences_segments' => 'initiative_audiences_segments',
|
||||
'plan_audiences_stages' => 'initiative_audiences_stages',
|
||||
];
|
||||
|
||||
/**
|
||||
* Table (any of its names) => [old column => [new column, definition]].
|
||||
*/
|
||||
private const COLUMNS = [
|
||||
['plan_objectives', 'initiative_objectives', 'plan_id', 'initiative_id', 'INT UNSIGNED NOT NULL'],
|
||||
['plan_description_items', 'initiative_description_items', 'plan_id', 'initiative_id', 'INT UNSIGNED NOT NULL'],
|
||||
['plan_allocation_items', 'initiative_allocation_items', 'plan_id', 'initiative_id', 'INT UNSIGNED NOT NULL'],
|
||||
['plan_tasks', 'initiative_tasks', 'plan_id', 'initiative_id', 'INT UNSIGNED NOT NULL'],
|
||||
['plan_stakeholders_plan', 'initiative_stakeholders_initiative', 'plan_id', 'initiative_id', 'INT UNSIGNED NOT NULL'],
|
||||
['plan_stakeholders_plan', 'initiative_stakeholders_initiative', 'role_in_plan', 'role_in_initiative', 'VARCHAR(191) DEFAULT NULL'],
|
||||
['plan_audiences_plan', 'initiative_audiences_initiative', 'plan_id', 'initiative_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, $toColumn]) {
|
||||
$table = $this->getTableName($schema, [$fromTable, $toTable]);
|
||||
if (null !== $table) {
|
||||
foreach ($schema->getTable($table)->getColumns() as $name => $column) {
|
||||
if (strtolower($name) === strtolower($fromColumn)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\Migrations;
|
||||
namespace MauticPlugin\ProgramBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\PlanBundle\Entity\Plan;
|
||||
use MauticPlugin\ProgramBundle\Entity\Initiative;
|
||||
|
||||
/**
|
||||
* Brings the plans table in line with the entity mapping.
|
||||
@@ -31,13 +31,11 @@ class Version_0_2_0 extends AbstractMigration
|
||||
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
$table = $this->getTable($schema);
|
||||
|
||||
if (null === $table) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return [] !== $this->getMissingForeignKeys($table) || $this->statusNeedsResize($table);
|
||||
// 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
|
||||
@@ -52,14 +50,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(Plan::TABLE_NAME),
|
||||
$this->concatPrefix(Initiative::TABLE_NAME),
|
||||
self::STATUS_LENGTH
|
||||
));
|
||||
}
|
||||
|
||||
foreach ($this->getMissingForeignKeys($table) as $column => $referenceTable) {
|
||||
$this->addSql($this->generateAlterTableForeignKeyStatement(
|
||||
Plan::TABLE_NAME,
|
||||
Initiative::TABLE_NAME,
|
||||
[$column],
|
||||
$referenceTable,
|
||||
['id'],
|
||||
@@ -70,7 +68,7 @@ class Version_0_2_0 extends AbstractMigration
|
||||
|
||||
private function getTable(Schema $schema): ?Table
|
||||
{
|
||||
$name = $this->concatPrefix(Plan::TABLE_NAME);
|
||||
$name = $this->concatPrefix(Initiative::TABLE_NAME);
|
||||
|
||||
return $schema->hasTable($name) ? $schema->getTable($name) : null;
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\Migrations;
|
||||
namespace MauticPlugin\ProgramBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\PlanBundle\Entity\Plan;
|
||||
use MauticPlugin\PlanBundle\Entity\PlanObjective;
|
||||
use MauticPlugin\ProgramBundle\Entity\Initiative;
|
||||
use MauticPlugin\ProgramBundle\Entity\InitiativeObjective;
|
||||
|
||||
/**
|
||||
* Adds plans.version and the plan_objectives table to installs created before 0.3.0.
|
||||
* Adds plans.version and the initiative_objectives table to installs created before 0.3.0.
|
||||
*
|
||||
* Fresh installs get both from the entity mapping, so this migration then finds nothing to do.
|
||||
*/
|
||||
@@ -18,29 +18,26 @@ class Version_0_3_0 extends AbstractMigration
|
||||
{
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
$plans = $this->concatPrefix(Plan::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($plans)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !$schema->getTable($plans)->hasColumn('version')
|
||||
|| !$schema->hasTable($this->concatPrefix(PlanObjective::TABLE_NAME));
|
||||
// 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();
|
||||
$plans = $this->concatPrefix(Plan::TABLE_NAME);
|
||||
$objectives = $this->concatPrefix(PlanObjective::TABLE_NAME);
|
||||
$plans = $this->concatPrefix(Initiative::TABLE_NAME);
|
||||
$objectives = $this->concatPrefix(InitiativeObjective::TABLE_NAME);
|
||||
|
||||
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(PlanObjective::TABLE_NAME, 'idx', ['plan_id']);
|
||||
$foreignKey = $this->generatePropertyName(PlanObjective::TABLE_NAME, 'fk', ['plan_id']);
|
||||
$index = $this->generatePropertyName(InitiativeObjective::TABLE_NAME, 'idx', ['plan_id']);
|
||||
$foreignKey = $this->generatePropertyName(InitiativeObjective::TABLE_NAME, 'fk', ['plan_id']);
|
||||
|
||||
$this->addSql("CREATE TABLE {$objectives} (
|
||||
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\Migrations;
|
||||
namespace MauticPlugin\ProgramBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\PlanBundle\Entity\Plan;
|
||||
use MauticPlugin\PlanBundle\Entity\Task;
|
||||
use MauticPlugin\ProgramBundle\Entity\Initiative;
|
||||
use MauticPlugin\ProgramBundle\Entity\Task;
|
||||
|
||||
/**
|
||||
* Adds the plan_tasks table and its foreign keys to installs created before 0.4.0.
|
||||
* Adds the initiative_tasks table and its foreign keys to installs created before 0.4.0.
|
||||
*
|
||||
* The CREATE TABLE comes from the Task mapping, so it can't drift from the entity. Only that statement
|
||||
* is kept: SchemaTool's output also contains statements for other tables (for example Symfony
|
||||
* Messenger's messenger_messages), which would fail on an existing install.
|
||||
*
|
||||
* The foreign keys are added one by one when missing, so the migration also repairs a plan_tasks table
|
||||
* The foreign keys are added one by one when missing, so the migration also repairs a initiative_tasks table
|
||||
* that exists without them. Fresh installs get everything from the entity mapping, so this migration
|
||||
* then finds nothing to do.
|
||||
*/
|
||||
@@ -31,20 +31,16 @@ class Version_0_4_0 extends AbstractMigration
|
||||
* so only plan_id is repaired here.
|
||||
*/
|
||||
private const FOREIGN_KEYS = [
|
||||
'plan_id' => [Plan::TABLE_NAME, 'CASCADE'],
|
||||
'plan_id' => [Initiative::TABLE_NAME, 'CASCADE'],
|
||||
];
|
||||
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
if (!$schema->hasTable($this->concatPrefix(Plan::TABLE_NAME))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tasks = $this->concatPrefix(Task::TABLE_NAME);
|
||||
|
||||
$table = $schema->hasTable($tasks) ? $schema->getTable($tasks) : null;
|
||||
|
||||
return null === $table || [] !== $this->getMissingForeignKeys($table);
|
||||
// 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
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\Migrations;
|
||||
namespace MauticPlugin\ProgramBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\PlanBundle\Entity\Task;
|
||||
use MauticPlugin\PlanBundle\Entity\TaskStatus;
|
||||
use MauticPlugin\ProgramBundle\Entity\Task;
|
||||
use MauticPlugin\ProgramBundle\Entity\TaskStatus;
|
||||
|
||||
/**
|
||||
* Adds start_date, end_date and status (default "new", indexed) to plan_tasks, for installs created
|
||||
* Adds start_date, end_date and status (default "new", indexed) to initiative_tasks, for installs created
|
||||
* before 0.5.0. Existing tasks get the status "new". Each column is added only if missing.
|
||||
*/
|
||||
class Version_0_5_0 extends AbstractMigration
|
||||
@@ -19,18 +19,11 @@ class Version_0_5_0 extends AbstractMigration
|
||||
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
$tasks = $this->concatPrefix(Task::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($tasks)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$table = $schema->getTable($tasks);
|
||||
|
||||
return !$table->hasColumn('start_date')
|
||||
|| !$table->hasColumn('end_date')
|
||||
|| !$table->hasColumn('status')
|
||||
|| !$table->hasIndex(self::STATUS_INDEX);
|
||||
// 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
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
|
||||
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\PlanDescriptionItem;
|
||||
use MauticPlugin\ProgramBundle\Entity\Initiative;
|
||||
use MauticPlugin\ProgramBundle\Entity\InitiativeDescriptionItem;
|
||||
|
||||
/**
|
||||
* For installs created before 0.6.0:
|
||||
* - creates plan_description_items (and its foreign key to plans, ON DELETE CASCADE);
|
||||
* - creates initiative_description_items (and its foreign key to plans, ON DELETE CASCADE);
|
||||
* - drops plans.description, which description items replace. Its content is deleted, as decided
|
||||
* when description items were introduced.
|
||||
*
|
||||
@@ -23,24 +23,18 @@ class Version_0_6_0 extends AbstractMigration
|
||||
{
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
$plans = $this->concatPrefix(Plan::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($plans)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$items = $this->concatPrefix(PlanDescriptionItem::TABLE_NAME);
|
||||
|
||||
return !$schema->hasTable($items)
|
||||
|| !$this->hasPlanForeignKey($schema)
|
||||
|| $schema->getTable($plans)->hasColumn('description');
|
||||
// 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();
|
||||
$plans = $this->concatPrefix(Plan::TABLE_NAME);
|
||||
$items = $this->concatPrefix(PlanDescriptionItem::TABLE_NAME);
|
||||
$plans = $this->concatPrefix(Initiative::TABLE_NAME);
|
||||
$items = $this->concatPrefix(InitiativeDescriptionItem::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($items)) {
|
||||
$this->addSql($this->getCreateTableSql());
|
||||
@@ -48,9 +42,9 @@ class Version_0_6_0 extends AbstractMigration
|
||||
|
||||
if (!$schema->hasTable($items) || !$this->hasPlanForeignKey($schema)) {
|
||||
$this->addSql($this->generateAlterTableForeignKeyStatement(
|
||||
PlanDescriptionItem::TABLE_NAME,
|
||||
InitiativeDescriptionItem::TABLE_NAME,
|
||||
['plan_id'],
|
||||
Plan::TABLE_NAME,
|
||||
Initiative::TABLE_NAME,
|
||||
['id'],
|
||||
'ON DELETE CASCADE'
|
||||
));
|
||||
@@ -63,7 +57,7 @@ class Version_0_6_0 extends AbstractMigration
|
||||
|
||||
private function hasPlanForeignKey(Schema $schema): bool
|
||||
{
|
||||
$items = $this->concatPrefix(PlanDescriptionItem::TABLE_NAME);
|
||||
$items = $this->concatPrefix(InitiativeDescriptionItem::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($items)) {
|
||||
return false;
|
||||
@@ -81,14 +75,14 @@ class Version_0_6_0 extends AbstractMigration
|
||||
private function getCreateTableSql(): string
|
||||
{
|
||||
$schemaTool = new SchemaTool($this->entityManager);
|
||||
$prefix = 'CREATE TABLE '.$this->concatPrefix(PlanDescriptionItem::TABLE_NAME).' ';
|
||||
$prefix = 'CREATE TABLE '.$this->concatPrefix(InitiativeDescriptionItem::TABLE_NAME).' ';
|
||||
|
||||
foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata(PlanDescriptionItem::class)]) as $sql) {
|
||||
foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata(InitiativeDescriptionItem::class)]) as $sql) {
|
||||
if (str_starts_with($sql, $prefix)) {
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.PlanDescriptionItem::TABLE_NAME.'.');
|
||||
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.InitiativeDescriptionItem::TABLE_NAME.'.');
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,16 @@
|
||||
|
||||
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\PlanAllocationItem;
|
||||
use MauticPlugin\ProgramBundle\Entity\Initiative;
|
||||
use MauticPlugin\ProgramBundle\Entity\InitiativeAllocationItem;
|
||||
|
||||
/**
|
||||
* Creates plan_allocation_items (and its foreign key to plans, ON DELETE CASCADE) for installs created
|
||||
* 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
|
||||
* this table is kept from SchemaTool's output.
|
||||
*/
|
||||
@@ -19,17 +19,17 @@ class Version_0_7_0 extends AbstractMigration
|
||||
{
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
if (!$schema->hasTable($this->concatPrefix(Plan::TABLE_NAME))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !$schema->hasTable($this->concatPrefix(PlanAllocationItem::TABLE_NAME)) || !$this->hasPlanForeignKey($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();
|
||||
$items = $this->concatPrefix(PlanAllocationItem::TABLE_NAME);
|
||||
$items = $this->concatPrefix(InitiativeAllocationItem::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($items)) {
|
||||
$this->addSql($this->getCreateTableSql());
|
||||
@@ -37,9 +37,9 @@ class Version_0_7_0 extends AbstractMigration
|
||||
|
||||
if (!$this->hasPlanForeignKey($schema)) {
|
||||
$this->addSql($this->generateAlterTableForeignKeyStatement(
|
||||
PlanAllocationItem::TABLE_NAME,
|
||||
InitiativeAllocationItem::TABLE_NAME,
|
||||
['plan_id'],
|
||||
Plan::TABLE_NAME,
|
||||
Initiative::TABLE_NAME,
|
||||
['id'],
|
||||
'ON DELETE CASCADE'
|
||||
));
|
||||
@@ -48,7 +48,7 @@ class Version_0_7_0 extends AbstractMigration
|
||||
|
||||
private function hasPlanForeignKey(Schema $schema): bool
|
||||
{
|
||||
$items = $this->concatPrefix(PlanAllocationItem::TABLE_NAME);
|
||||
$items = $this->concatPrefix(InitiativeAllocationItem::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($items)) {
|
||||
return false;
|
||||
@@ -66,14 +66,14 @@ class Version_0_7_0 extends AbstractMigration
|
||||
private function getCreateTableSql(): string
|
||||
{
|
||||
$schemaTool = new SchemaTool($this->entityManager);
|
||||
$prefix = 'CREATE TABLE '.$this->concatPrefix(PlanAllocationItem::TABLE_NAME).' ';
|
||||
$prefix = 'CREATE TABLE '.$this->concatPrefix(InitiativeAllocationItem::TABLE_NAME).' ';
|
||||
|
||||
foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata(PlanAllocationItem::class)]) as $sql) {
|
||||
foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata(InitiativeAllocationItem::class)]) as $sql) {
|
||||
if (str_starts_with($sql, $prefix)) {
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.PlanAllocationItem::TABLE_NAME.'.');
|
||||
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.InitiativeAllocationItem::TABLE_NAME.'.');
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,17 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\Migrations;
|
||||
namespace MauticPlugin\ProgramBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\PlanBundle\Entity\Plan;
|
||||
use MauticPlugin\PlanBundle\Entity\PlanAllocationItem;
|
||||
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
|
||||
* plan_currency), so the per-record currency columns are dropped: plans.currency,
|
||||
* plan_allocation_items.planned_currency and plan_allocation_items.real_currency. Amounts are kept as they
|
||||
* program_currency), so the per-record currency columns are dropped: plans.currency,
|
||||
* initiative_allocation_items.planned_currency and initiative_allocation_items.real_currency. Amounts are kept as they
|
||||
* are. Each column is dropped only if it exists.
|
||||
*/
|
||||
class Version_0_8_0 extends AbstractMigration
|
||||
@@ -21,13 +21,17 @@ class Version_0_8_0 extends AbstractMigration
|
||||
* Table => columns to drop.
|
||||
*/
|
||||
private const COLUMNS = [
|
||||
Plan::TABLE_NAME => ['currency'],
|
||||
PlanAllocationItem::TABLE_NAME => ['planned_currency', 'real_currency'],
|
||||
Initiative::TABLE_NAME => ['currency'],
|
||||
InitiativeAllocationItem::TABLE_NAME => ['planned_currency', 'real_currency'],
|
||||
];
|
||||
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
return [] !== $this->getColumnsToDrop($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
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\Migrations;
|
||||
namespace MauticPlugin\ProgramBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\PlanBundle\Entity\Task;
|
||||
use MauticPlugin\ProgramBundle\Entity\Task;
|
||||
|
||||
/**
|
||||
* Since 0.9.0 tasks have a type, the key of a task type set up in Settings > Configuration > Plan
|
||||
* Settings (parameter plan_task_types). Adds plan_tasks.type for installs created before 0.9.0. The
|
||||
* Settings (parameter plan_task_types). Adds initiative_tasks.type for installs created before 0.9.0. The
|
||||
* column is nullable: existing tasks have no type yet, and each one must be given one before it can be
|
||||
* saved again (validation requires it). Runs only when the column is missing.
|
||||
*/
|
||||
@@ -18,13 +18,11 @@ class Version_0_9_0 extends AbstractMigration
|
||||
{
|
||||
protected function isApplicable(Schema $schema): bool
|
||||
{
|
||||
$tasks = $this->concatPrefix(Task::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($tasks)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !$schema->getTable($tasks)->hasColumn('type');
|
||||
// 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
|
||||
|
||||
Reference in new issue
Block a user