Skip to content

Commit

Permalink
Merge branch 'bugfix/content-migration' into 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Aug 21, 2024
2 parents d9597c7 + da005f6 commit f010ea7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Digital Products

## Unreleased

- Fixed a bug where product fields content was not prepared for Craft 5.

## 4.0.0 - 2024-03-20

- Digital Products now requires Craft Commerce 5.0.0-beta.1 or later.
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Plugin extends BasePlugin
/**
* @inheritDoc
*/
public string $schemaVersion = '3.0.3';
public string $schemaVersion = '4.0.0.1';

/**
* @inheritDoc
Expand Down
39 changes: 39 additions & 0 deletions src/migrations/m240620_150738_content_refactor_elements.php
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;
}
}

1 comment on commit f010ea7

@rob-c-baker
Copy link

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.

Please sign in to comment.