Skip to content

Commit

Permalink
Adds content migration
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethormandy committed Jun 20, 2024
1 parent d9597c7 commit 5c1e7bd
Showing 1 changed file with 39 additions and 0 deletions.
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;
}
}

0 comments on commit 5c1e7bd

Please sign in to comment.