feat: Add TargetType form and migration for plan targets
- Implemented TargetType form for managing target details including name, type, priority, stages, estimated size, profile criteria, pain points, value proposition, and preferred channels. - Created migration scripts for adding type and priority columns to plan objectives and tasks. - Added migration for creating plan targets and plan target stages tables, including foreign key constraints. - Introduced stakeholder management with forms and views for creating, editing, and listing stakeholders. - Enhanced UI with read more functionality for long text descriptions and filtering options in plan tab tables.
This commit is contained in:
1 parent
8c8d7a6f95
commit
8696acd01c
52 files changed
+3178
-125
No files matched your search
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\PlanBundle\Entity\PlanObjective;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
protected function up(): void
|
||||
{
|
||||
$objectives = $this->concatPrefix(PlanObjective::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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\PlanBundle\Entity\PlanObjective;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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');
|
||||
}
|
||||
|
||||
protected function up(): void
|
||||
{
|
||||
$objectives = $this->concatPrefix(PlanObjective::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
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\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;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
class Version_0_11_0 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Field name => column name, for the columns an early version of the mapping left in camelCase.
|
||||
*/
|
||||
private const COLUMNS = [
|
||||
'targetType' => 'target_type',
|
||||
'profileCriteria' => 'profile_criteria',
|
||||
'painPoints' => 'pain_points',
|
||||
'valueProposition' => 'value_proposition',
|
||||
];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
if (!$schema->hasTable($this->concatPrefix('plan_target_stages'))) {
|
||||
$this->addSql($this->getCreateTableSql('plan_target_stages'));
|
||||
}
|
||||
|
||||
foreach ($this->getColumnsToRename($schema) as $field => $column) {
|
||||
$this->addSql(sprintf(
|
||||
'ALTER TABLE %s CHANGE %s %s',
|
||||
$this->concatPrefix(Target::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'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string> field name => column name, for the camelCase columns still present
|
||||
*/
|
||||
private function getColumnsToRename(Schema $schema): array
|
||||
{
|
||||
if (!$schema->hasTable($this->concatPrefix(Target::TABLE_NAME))) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$table = $schema->getTable($this->concatPrefix(Target::TABLE_NAME));
|
||||
$rename = [];
|
||||
|
||||
foreach (self::COLUMNS as $field => $column) {
|
||||
if ($table->hasColumn($field) && !$table->hasColumn($column)) {
|
||||
$rename[$field] = $column;
|
||||
}
|
||||
}
|
||||
|
||||
return $rename;
|
||||
}
|
||||
|
||||
private function hasForeignKeys(Schema $schema): bool
|
||||
{
|
||||
$targets = $this->concatPrefix(Target::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($targets)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($schema->getTable($targets)->getForeignKeys() as $foreignKey) {
|
||||
if (in_array('plan_id', $foreignKey->getLocalColumns(), true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The MySQL column definition matching the entity mapping, for a CHANGE that renames the column.
|
||||
*/
|
||||
private function getColumnDefinition(string $field, string $column): string
|
||||
{
|
||||
$definitions = [
|
||||
'targetType' => sprintf("%s VARCHAR(30) NOT NULL DEFAULT '%s'", $column, TargetTypeEnum::Persona->value),
|
||||
'profileCriteria' => $column.' LONGTEXT DEFAULT NULL',
|
||||
'painPoints' => $column.' LONGTEXT DEFAULT NULL',
|
||||
'valueProposition' => $column.' LONGTEXT DEFAULT NULL',
|
||||
];
|
||||
|
||||
return $definitions[$field] ?? $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* The CREATE TABLE statement for one of this migration's tables, from Doctrine's SchemaTool.
|
||||
*/
|
||||
private function getCreateTableSql(string $table): string
|
||||
{
|
||||
$schemaTool = new SchemaTool($this->entityManager);
|
||||
$prefix = 'CREATE TABLE '.$this->concatPrefix($table).' ';
|
||||
|
||||
foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata(Target::class)]) as $sql) {
|
||||
if (str_starts_with($sql, $prefix)) {
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.$table.'.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
protected function up(): void
|
||||
{
|
||||
$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(PlanStakeholder::TABLE_NAME))) {
|
||||
$this->addSql($this->getCreateTableSql(PlanStakeholder::class, PlanStakeholder::TABLE_NAME));
|
||||
}
|
||||
|
||||
if (!$this->hasForeignKeys($schema)) {
|
||||
$this->addSql($this->generateAlterTableForeignKeyStatement(
|
||||
PlanStakeholder::TABLE_NAME,
|
||||
['plan_id'],
|
||||
Plan::TABLE_NAME,
|
||||
['id'],
|
||||
'ON DELETE CASCADE'
|
||||
));
|
||||
$this->addSql($this->generateAlterTableForeignKeyStatement(
|
||||
PlanStakeholder::TABLE_NAME,
|
||||
['stakeholder_id'],
|
||||
Stakeholder::TABLE_NAME,
|
||||
['id'],
|
||||
'ON DELETE CASCADE'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True when both foreign keys of the link table exist (plan_id, stakeholder_id).
|
||||
*/
|
||||
private function hasForeignKeys(Schema $schema): bool
|
||||
{
|
||||
$links = $this->concatPrefix(PlanStakeholder::TABLE_NAME);
|
||||
|
||||
if (!$schema->hasTable($links)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$columns = [];
|
||||
foreach ($schema->getTable($links)->getForeignKeys() as $foreignKey) {
|
||||
$columns = array_merge($columns, $foreignKey->getLocalColumns());
|
||||
}
|
||||
|
||||
return in_array('plan_id', $columns, true) && in_array('stakeholder_id', $columns, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The CREATE TABLE statement for one of this migration's tables, from Doctrine's SchemaTool.
|
||||
*
|
||||
* @param class-string $entityClass
|
||||
*/
|
||||
private function getCreateTableSql(string $entityClass, string $table): string
|
||||
{
|
||||
$schemaTool = new SchemaTool($this->entityManager);
|
||||
$prefix = 'CREATE TABLE '.$this->concatPrefix($table).' ';
|
||||
|
||||
foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata($entityClass)]) as $sql) {
|
||||
if (str_starts_with($sql, $prefix)) {
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.$table.'.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\PlanBundle\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
||||
use MauticPlugin\PlanBundle\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
|
||||
* 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.
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
protected function up(): void
|
||||
{
|
||||
$tasks = $this->concatPrefix(Task::TABLE_NAME);
|
||||
$table = $this->entityManager->getConnection()->createSchemaManager()->introspectTable($tasks);
|
||||
|
||||
if (!$table->hasColumn('type')) {
|
||||
$this->addSql(sprintf('ALTER TABLE %s ADD type VARCHAR(%d) DEFAULT NULL', $tasks, Task::TYPE_MAX_LENGTH));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user