Skip to content

Commit

Permalink
Adds Transactional Email Elements migration
Browse files Browse the repository at this point in the history
  • Loading branch information
BenParizek committed May 27, 2024
1 parent 355ee7b commit de8aa9d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/transactional/migrations/m240527_000000_content_refactor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace BarrelStrength\Sprout\transactional\migrations;

use BarrelStrength\Sprout\mailer\emailtypes\EmailTypeHelper;
use Craft;
use craft\db\Query;
use craft\migrations\BaseContentRefactorMigration;
use craft\models\FieldLayout;

class m240527_000000_content_refactor extends BaseContentRefactorMigration
{
public const EMAILS_TABLE = '{{%sprout_emails}}';

public function safeUp(): void
{
$emailTypes = EmailTypeHelper::getEmailTypes();

// Update Email Elements
foreach ($emailTypes as $emailType) {
$this->updateElements(
(new Query())
->from(self::EMAILS_TABLE)
->where(['emailTypeUid' => $emailType->uid]),
$emailType->getFieldLayout(),
);
}

}

public function safeDown(): bool
{
echo self::class . " cannot be reverted.\n";

return false;
}
}

0 comments on commit de8aa9d

Please sign in to comment.