-
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.
Merge branch 'bugfix/content-migration' into 4.x
- Loading branch information
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
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
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
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; | ||
} | ||
} |
f010ea7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An the assumption this is the fix for #103, I have just tried the critical part of
m240620_150738_content_refactor_elements::safeUp()
in a manually created migration and it works.