Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds content migration, fixing upgrading from Craft 4 #102

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading