-
Notifications
You must be signed in to change notification settings - Fork 9
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
d9597c7
commit 5c1e7bd
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/migrations/m240620_150738_content_refactor_elements.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,39 @@ | ||
<?php | ||
|
||
namespace craft\digitalproducts\migrations; | ||
|
||
use craft\db\Query; | ||
use craft\digitalproducts\db\Table; | ||
use craft\digitalproducts\Plugin; | ||
use craft\migrations\BaseContentRefactorMigration; | ||
|
||
/** | ||
* m240620_150738_content_refactor_elements migration. | ||
*/ | ||
class m240620_150738_content_refactor_elements extends BaseContentRefactorMigration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp(): bool | ||
{ | ||
// Migrate digital products by product type | ||
foreach (Plugin::getInstance()->getProductTypes()->getAllProductTypes() as $productType) { | ||
$this->updateElements( | ||
(new Query())->from(Table::PRODUCTS)->where(['typeId' => $productType->id]), | ||
$productType->getProductFieldLayout() | ||
); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown(): bool | ||
{ | ||
echo "m240620_150738_content_refactor_elements cannot be reverted.\n"; | ||
return false; | ||
} | ||
} |