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_*
95 lines
2.9 KiB
PHP
95 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\Migrations;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
use Doctrine\DBAL\Schema\Table;
|
|
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
|
/**
|
|
* Brings the plans table in line with the entity mapping.
|
|
*
|
|
* The plugin installer only runs SchemaTool on the plugin's own entities, so it drops the foreign keys
|
|
* to core tables (users, categories). This migration adds them with ON DELETE SET NULL, and shrinks the
|
|
* status column to VARCHAR(20). It is idempotent: it runs on plugin update (by the core migration
|
|
* engine) and right after install (by PluginInstallSubscriber).
|
|
*/
|
|
class Version_0_2_0 extends AbstractMigration
|
|
{
|
|
private const STATUS_LENGTH = 20;
|
|
|
|
/**
|
|
* Local column => referenced core table.
|
|
*/
|
|
private const FOREIGN_KEYS = [
|
|
'owner_id' => 'users',
|
|
'category_id' => 'categories',
|
|
];
|
|
|
|
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();
|
|
$table = $this->getTable($schema);
|
|
|
|
if (null === $table) {
|
|
return;
|
|
}
|
|
|
|
if ($this->statusNeedsResize($table)) {
|
|
$this->addSql(sprintf(
|
|
'ALTER TABLE %s MODIFY status VARCHAR(%d) NOT NULL',
|
|
$this->concatPrefix('initiatives'),
|
|
self::STATUS_LENGTH
|
|
));
|
|
}
|
|
|
|
foreach ($this->getMissingForeignKeys($table) as $column => $referenceTable) {
|
|
$this->addSql($this->generateAlterTableForeignKeyStatement(
|
|
'initiatives',
|
|
[$column],
|
|
$referenceTable,
|
|
['id'],
|
|
'ON DELETE SET NULL'
|
|
));
|
|
}
|
|
}
|
|
|
|
private function getTable(Schema $schema): ?Table
|
|
{
|
|
$name = $this->concatPrefix('initiatives');
|
|
|
|
return $schema->hasTable($name) ? $schema->getTable($name) : null;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
private function getMissingForeignKeys(Table $table): array
|
|
{
|
|
$missing = self::FOREIGN_KEYS;
|
|
|
|
foreach ($table->getForeignKeys() as $foreignKey) {
|
|
foreach ($foreignKey->getLocalColumns() as $column) {
|
|
unset($missing[$column]);
|
|
}
|
|
}
|
|
|
|
return $missing;
|
|
}
|
|
|
|
private function statusNeedsResize(Table $table): bool
|
|
{
|
|
return $table->hasColumn('status') && self::STATUS_LENGTH !== $table->getColumn('status')->getLength();
|
|
}
|
|
}
|