-
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.
- Loading branch information
1 parent
1270c47
commit f8fbcb1
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/redirects/migrations/m240526_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,42 @@ | ||
<?php | ||
|
||
namespace BarrelStrength\Sprout\redirects\migrations; | ||
|
||
use BarrelStrength\Sprout\redirects\components\elements\RedirectElement; | ||
use BarrelStrength\Sprout\redirects\RedirectsModule; | ||
use Craft; | ||
use craft\db\Query; | ||
use craft\migrations\BaseContentRefactorMigration; | ||
use craft\models\FieldLayout; | ||
|
||
class m240526_000000_content_refactor extends BaseContentRefactorMigration | ||
{ | ||
public const REDIRECTS_TABLE = '{{%sprout_redirects}}'; | ||
public const REDIRECT_ELEMENT_TYPE = 'BarrelStrength\Sprout\redirects\components\elements\RedirectElement'; | ||
|
||
public function safeUp(): void | ||
{ | ||
$fieldLayouts = Craft::$app->projectConfig->get('sprout.sprout-module-redirects.fieldLayouts'); | ||
|
||
if ($fieldLayout = reset($fieldLayouts)) { | ||
$layout = FieldLayout::createFromConfig($fieldLayout); | ||
} else { | ||
$layout = new FieldLayout([ | ||
'type' => self::REDIRECT_ELEMENT_TYPE, | ||
]); | ||
} | ||
|
||
// Update Redirect Elements | ||
$this->updateElements( | ||
(new Query())->from(self::REDIRECTS_TABLE), | ||
$layout, | ||
); | ||
} | ||
|
||
public function safeDown(): bool | ||
{ | ||
echo self::class . " cannot be reverted.\n"; | ||
|
||
return false; | ||
} | ||
} |