first delivery

This commit is contained in:
Alexandre Gain committed 2026-11-07 19:31:49 +01:00
1 parent 793fbc0c91
commit f6684f3b2e
65 files changed
+5828

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\PlanBundle\Entity\Plan;
use MauticPlugin\PlanBundle\Entity\PlanAllocationItem;
/**
* 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
* are. Each column is dropped only if it exists.
*/
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'],
];
protected function isApplicable(Schema $schema): bool
{
return [] !== $this->getColumnsToDrop($schema);
}
protected function up(): void
{
$schema = $this->entityManager->getConnection()->createSchemaManager()->introspectSchema();
foreach ($this->getColumnsToDrop($schema) as $table => $columns) {
foreach ($columns as $column) {
$this->addSql("ALTER TABLE {$table} DROP COLUMN {$column}");
}
}
}
/**
* @return array<string, string[]> prefixed table => existing columns to drop
*/
private function getColumnsToDrop(Schema $schema): array
{
$drop = [];
foreach (self::COLUMNS as $table => $columns) {
$table = $this->concatPrefix($table);
if (!$schema->hasTable($table)) {
continue;
}
$existing = array_values(array_filter($columns, fn (string $column): bool => $schema->getTable($table)->hasColumn($column)));
if ([] !== $existing) {
$drop[$table] = $existing;
}
}
return $drop;
}
}