-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Transactional Email Elements migration
- Loading branch information
1 parent
355ee7b
commit de8aa9d
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/transactional/migrations/m240527_000000_content_refactor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |