From 6a551640225b050ec29af0a63354ae01008725f8 Mon Sep 17 00:00:00 2001 From: "ivan.hrytsai" Date: Tue, 12 Nov 2024 17:45:48 +0200 Subject: [PATCH 1/3] init commit --- Setup/InstallSchema.php | 396 -------- .../Data/CreateDefaultPost.php} | 56 +- .../Data/TagInStore.php} | 59 +- Setup/Patch/Data/UpdatePostCommentsCount.php | 69 ++ Setup/UpgradeSchema.php | 876 ------------------ etc/db_schema.xml | 271 ++++++ etc/module.xml | 2 +- 7 files changed, 408 insertions(+), 1321 deletions(-) delete mode 100755 Setup/InstallSchema.php rename Setup/{InstallData.php => Patch/Data/CreateDefaultPost.php} (81%) mode change 100755 => 100644 rename Setup/{UpgradeData.php => Patch/Data/TagInStore.php} (60%) create mode 100644 Setup/Patch/Data/UpdatePostCommentsCount.php delete mode 100644 Setup/UpgradeSchema.php create mode 100644 etc/db_schema.xml diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php deleted file mode 100755 index 290b6d4e..00000000 --- a/Setup/InstallSchema.php +++ /dev/null @@ -1,396 +0,0 @@ -startSetup(); - - /** - * Create table 'magefan_blog_post' - */ - $table = $installer->getConnection()->newTable( - $installer->getTable('magefan_blog_post') - )->addColumn( - 'post_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['identity' => true, 'nullable' => false, 'primary' => true], - 'Post ID' - )->addColumn( - 'title', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - ['nullable' => true], - 'Post Title' - )->addColumn( - 'meta_keywords', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - '64k', - ['nullable' => true], - 'Post Meta Keywords' - )->addColumn( - 'meta_description', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - '64k', - ['nullable' => true], - 'Post Meta Description' - )->addColumn( - 'identifier', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 100, - ['nullable' => true, 'default' => null], - 'Post String Identifier' - )->addColumn( - 'content_heading', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - ['nullable' => true], - 'Post Content Heading' - )->addColumn( - 'content', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - '2M', - [], - 'Post Content' - )->addColumn( - 'creation_time', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - [], - 'Post Creation Time' - )->addColumn( - 'update_time', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - [], - 'Post Modification Time' - )->addColumn( - 'publish_time', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - [], - 'Post Publish Time' - )->addColumn( - 'is_active', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - ['nullable' => false, 'default' => '1'], - 'Is Post Active' - )->addIndex( - $installer->getIdxName('magefan_blog_post', ['identifier']), - ['identifier'] - )->addIndex( - $setup->getIdxName( - $installer->getTable('magefan_blog_post'), - ['title', 'meta_keywords', 'meta_description', 'identifier', 'content'], - AdapterInterface::INDEX_TYPE_FULLTEXT - ), - ['title', 'meta_keywords', 'meta_description', 'identifier', 'content'], - ['type' => AdapterInterface::INDEX_TYPE_FULLTEXT] - )->setComment( - 'Magefan Blog Post Table' - ); - $installer->getConnection()->createTable($table); - - /** - * Create table 'magefan_blog_post_store' - */ - $table = $installer->getConnection()->newTable( - $installer->getTable('magefan_blog_post_store') - )->addColumn( - 'post_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false, 'primary' => true], - 'Post ID' - )->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - ['unsigned' => true, 'nullable' => false, 'primary' => true], - 'Store ID' - )->addIndex( - $installer->getIdxName('magefan_blog_post_store', ['store_id']), - ['store_id'] - )->addForeignKey( - $installer->getFkName('magefan_blog_post_store', 'post_id', 'magefan_blog_post', 'post_id'), - 'post_id', - $installer->getTable('magefan_blog_post'), - 'post_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->addForeignKey( - $installer->getFkName('magefan_blog_post_store', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->setComment( - 'Magefan Blog Post To Store Linkage Table' - ); - $installer->getConnection()->createTable($table); - - $table = $installer->getConnection()->newTable( - $installer->getTable('magefan_blog_category') - )->addColumn( - 'category_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['identity' => true, 'nullable' => false, 'primary' => true], - 'Category ID' - )->addColumn( - 'title', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - ['nullable' => true], - 'Category Title' - )->addColumn( - 'meta_keywords', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - '64k', - ['nullable' => true], - 'Category Meta Keywords' - )->addColumn( - 'meta_description', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - '64k', - ['nullable' => true], - 'Category Meta Description' - )->addColumn( - 'identifier', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 100, - ['nullable' => true, 'default' => null], - 'Category String Identifier' - )->addColumn( - 'content_heading', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - ['nullable' => true], - 'Category Content Heading' - )->addColumn( - 'content', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - '2M', - [], - 'Category Content' - )->addColumn( - 'path', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - ['nullable' => true], - 'Category Path' - )->addColumn( - 'position', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - ['nullable' => false], - 'Category Position' - )->addColumn( - 'is_active', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - ['nullable' => false, 'default' => '1'], - 'Is Category Active' - )->addIndex( - $installer->getIdxName('magefan_blog_category', ['identifier']), - ['identifier'] - )->addIndex( - $setup->getIdxName( - $installer->getTable('magefan_blog_category'), - ['title', 'meta_keywords', 'meta_description', 'identifier', 'content'], - AdapterInterface::INDEX_TYPE_FULLTEXT - ), - ['title', 'meta_keywords', 'meta_description', 'identifier', 'content'], - ['type' => AdapterInterface::INDEX_TYPE_FULLTEXT] - )->setComment( - 'Magefan Blog Category Table' - ); - $installer->getConnection()->createTable($table); - - /** - * Create table 'magefan_blog_category_store' - */ - $table = $installer->getConnection()->newTable( - $installer->getTable('magefan_blog_category_store') - )->addColumn( - 'category_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false, 'primary' => true], - 'Category ID' - )->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - ['unsigned' => true, 'nullable' => false, 'primary' => true], - 'Store ID' - )->addIndex( - $installer->getIdxName('magefan_blog_category_store', ['store_id']), - ['store_id'] - )->addForeignKey( - $installer->getFkName('magefan_blog_category_store', 'category_id', 'magefan_blog_category', 'category_id'), - 'category_id', - $installer->getTable('magefan_blog_category'), - 'category_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->addForeignKey( - $installer->getFkName('magefan_blog_category_store', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->setComment( - 'Magefan Blog Category To Store Linkage Table' - ); - $installer->getConnection()->createTable($table); - - /** - * Create table 'magefan_blog_post_category' - */ - $table = $installer->getConnection()->newTable( - $installer->getTable('magefan_blog_post_category') - )->addColumn( - 'post_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false, 'primary' => true], - 'Post ID' - )->addColumn( - 'category_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false, 'primary' => true], - 'Category ID' - )->addIndex( - $installer->getIdxName('magefan_blog_post_category', ['category_id']), - ['category_id'] - )->addForeignKey( - $installer->getFkName('magefan_blog_post_category', 'post_id', 'magefan_blog_post', 'post_id'), - 'post_id', - $installer->getTable('magefan_blog_post'), - 'post_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->addForeignKey( - $installer->getFkName('magefan_blog_post_category', 'category_id', 'magefan_blog_category', 'category_id'), - 'category_id', - $installer->getTable('magefan_blog_category'), - 'category_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->setComment( - 'Magefan Blog Post To Category Linkage Table' - ); - $installer->getConnection()->createTable($table); - - /** - * Create table 'magefan_blog_post_relatedproduct' - */ - $table = $installer->getConnection()->newTable( - $installer->getTable('magefan_blog_post_relatedproduct') - )->addColumn( - 'post_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false, 'primary' => true], - 'Post ID' - )->addColumn( - 'related_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['unsigned' => true, 'nullable' => false, 'primary' => true], - 'Related Product ID' - )->addIndex( - $installer->getIdxName( - 'magefan_blog_post_relatedproduct', - ['related_id'] - ), - ['related_id'] - )->addForeignKey( - $installer->getFkName( - 'magefan_blog_post_relatedproduct', - 'post_id', - 'magefan_blog_post', - 'post_id' - ), - 'post_id', - $installer->getTable('magefan_blog_post'), - 'post_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->addForeignKey( - $installer->getFkName( - 'magefan_blog_post_relatedproduct', - 'related_id', - 'catalog_product_entity', - 'entity_id' - ), - 'related_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->setComment( - 'Magefan Blog Post To Product Linkage Table' - ); - $installer->getConnection()->createTable($table); - - /** - * Create table 'magefan_blog_post_relatedproduct' - */ - $table = $installer->getConnection()->newTable( - $installer->getTable('magefan_blog_post_relatedpost') - )->addColumn( - 'post_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false, 'primary' => true], - 'Post ID' - )->addColumn( - 'related_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false, 'primary' => true], - 'Related Post ID' - )->addIndex( - $installer->getIdxName('magefan_blog_post_relatedproduct', ['related_id']), - ['related_id'] - )->addForeignKey( - $installer->getFkName('magefan_blog_post_relatedproduct1', 'post_id', 'magefan_blog_post', 'post_id'), - 'post_id', - $installer->getTable('magefan_blog_post'), - 'post_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->addForeignKey( - $installer->getFkName('magefan_blog_post_relatedproduct2', 'related_id', 'magefan_blog_post', 'post_id'), - 'post_id', - $installer->getTable('magefan_blog_post'), - 'post_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->setComment( - 'Magefan Blog Post To Post Linkage Table' - ); - $installer->getConnection()->createTable($table); - - $installer->endSetup(); - } -} diff --git a/Setup/InstallData.php b/Setup/Patch/Data/CreateDefaultPost.php old mode 100755 new mode 100644 similarity index 81% rename from Setup/InstallData.php rename to Setup/Patch/Data/CreateDefaultPost.php index 00dd0305..027f068d --- a/Setup/InstallData.php +++ b/Setup/Patch/Data/CreateDefaultPost.php @@ -2,23 +2,16 @@ /** * Copyright © Magefan (support@magefan.com). All rights reserved. * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). - * - * Glory to Ukraine! Glory to the heroes! */ -namespace Magefan\Blog\Setup; +declare(strict_types=1); -use Magefan\Blog\Model\Post; -use Magefan\Blog\Model\PostFactory; -use Magento\Framework\Module\Setup\Migration; -use Magento\Framework\Setup\InstallDataInterface; -use Magento\Framework\Setup\ModuleContextInterface; -use Magento\Framework\Setup\ModuleDataSetupInterface; +namespace Magefan\Blog\Setup\Patch\Data; -/** - * @codeCoverageIgnore - */ -class InstallData implements InstallDataInterface +use Magento\Framework\Setup\Patch\DataPatchInterface; +use Magento\Framework\Setup\Patch\PatchRevertableInterface; + +class CreateDefaultPost implements DataPatchInterface, PatchRevertableInterface { /** * Post factory @@ -39,11 +32,6 @@ class InstallData implements InstallDataInterface */ private $scopeConfig; - /** - * Init - * - * @param \Magefan\Blog\Model\PostFactory $postFactory - */ public function __construct( \Magefan\Blog\Model\PostFactory $postFactory, \Magento\Framework\App\State $state, @@ -54,12 +42,13 @@ public function __construct( $this->scopeConfig = $scopeConfig; } - /** - * {@inheritdoc} - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) + + public function apply() { + /*if (version_compare($version, '2.9.1') < 0) { + return; + }*/ + try { $this->state->setAreaCode('adminhtml'); } catch (\Exception $e) { @@ -83,7 +72,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface 'content_heading' => 'Magento 2 Blog Post Sample', 'content' => $useLinks - ? '

Welcome to + ? '

Welcome to Magento Blog by @@ -110,12 +99,27 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface Magefan at Facebook

' - : '

Welcome to Magento 2 Blog extension by Magefan. + : '

Welcome to Magento 2 Blog extension by Magefan. This is your first post. Edit or delete it, then start blogging!

', 'store_ids' => [0] ]; $this->_postFactory->create()->setData($data)->save(); + + } + + public static function getDependencies() + { + return[]; + } + + public function getAliases() + { + return[]; + } + + public function revert() + { } -} +} \ No newline at end of file diff --git a/Setup/UpgradeData.php b/Setup/Patch/Data/TagInStore.php similarity index 60% rename from Setup/UpgradeData.php rename to Setup/Patch/Data/TagInStore.php index 166384d4..0e47886d 100644 --- a/Setup/UpgradeData.php +++ b/Setup/Patch/Data/TagInStore.php @@ -2,43 +2,54 @@ /** * Copyright © Magefan (support@magefan.com). All rights reserved. * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). - * - * Glory to Ukraine! Glory to the heroes! */ -namespace Magefan\Blog\Setup; +declare(strict_types=1); + +namespace Magefan\Blog\Setup\Patch\Data; -use Magento\Framework\Setup\UpgradeDataInterface; -use Magento\Framework\Setup\ModuleContextInterface; -use Magento\Framework\Setup\ModuleDataSetupInterface; use Magefan\Blog\Model\ResourceModel\Comment; +use Magento\Framework\Module\ModuleResource; +use Magento\Framework\Setup\Patch\DataPatchInterface; +use Magento\Framework\Setup\Patch\PatchRevertableInterface; -class UpgradeData implements UpgradeDataInterface +class TagInStore implements DataPatchInterface, PatchRevertableInterface { + /** + * @var Comment + */ protected $commentResource; - protected $_commentCollection; + /** + * @var ModuleResource + */ + private $moduleResource; + /** + * @param Comment $commentResource + * @param ModuleContextInterface $context + */ public function __construct( - Comment $commentResource + Comment $commentResource, + ModuleResource $moduleResource ) { $this->commentResource = $commentResource; + $this->moduleResource = $moduleResource; } - public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) + public static function getDependencies() { - $version = $context->getVersion(); - if (version_compare($version, '2.9.1') < 0) { - $connection = $this->commentResource->getConnection(); - $postSelect = $connection->select()->from( - [$this->commentResource->getTable('magefan_blog_post')] - ) - ->where('is_active = ?', 1); - $posts = $connection->fetchAll($postSelect); - foreach ($posts as $post) { - $this->commentResource->updatePostCommentsCount($post['post_id']); - } - } + return[]; + } + + public function getAliases() + { + return[]; + } + + public function apply() + { + $version = $this->moduleResource->getDbVersion('Magefan_Blog'); if (version_compare($version, '2.9.8') < 0) { $connection = $this->commentResource->getConnection(); @@ -73,4 +84,8 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface } } } + + public function revert() + { + } } diff --git a/Setup/Patch/Data/UpdatePostCommentsCount.php b/Setup/Patch/Data/UpdatePostCommentsCount.php new file mode 100644 index 00000000..99f2ae09 --- /dev/null +++ b/Setup/Patch/Data/UpdatePostCommentsCount.php @@ -0,0 +1,69 @@ +commentResource = $commentResource; + $this->moduleResource = $moduleResource; + } + + public static function getDependencies() + { + return[]; + } + + public function getAliases() + { + return[]; + } + + public function apply() + { + $version = $this->moduleResource->getDbVersion('Magefan_Blog'); + if (version_compare($version, '2.9.1') < 0) { + $connection = $this->commentResource->getConnection(); + $postSelect = $connection->select()->from( + [$this->commentResource->getTable('magefan_blog_post')] + ) + ->where('is_active = ?', 1); + $posts = $connection->fetchAll($postSelect); + foreach ($posts as $post) { + $this->commentResource->updatePostCommentsCount($post['post_id']); + } + } + } + + public function revert() + { + } +} diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php deleted file mode 100644 index 7f4b63d3..00000000 --- a/Setup/UpgradeSchema.php +++ /dev/null @@ -1,876 +0,0 @@ -startSetup(); - - $version = $context->getVersion(); - $connection = $setup->getConnection(); - - if (version_compare($version, '2.0.1') < 0) { - foreach (['magefan_blog_post_relatedpost', 'magefan_blog_post_relatedproduct'] as $tableName) { - // Get module table - $tableName = $setup->getTable($tableName); - - // Check if the table already exists - if ($connection->isTableExists($tableName) == true) { - $columns = [ - 'position' => [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 'nullable' => false, - 'comment' => 'Position', - ], - ]; - - foreach ($columns as $name => $definition) { - $connection->addColumn($tableName, $name, $definition); - } - } - } - - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'featured_img', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Thumbnail Image', - ] - ); - } - - if (version_compare($version, '2.2.0') < 0) { - /* Add author field to posts table */ - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'author_id', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 'nullable' => true, - 'comment' => 'Author ID', - - ] - ); - - $connection->addIndex( - $setup->getTable('magefan_blog_post'), - $setup->getIdxName($setup->getTable('magefan_blog_post'), ['author_id']), - ['author_id'] - ); - } - - if (version_compare($version, '2.2.5') < 0) { - /* Add layout field to posts and category table */ - foreach (['magefan_blog_post', 'magefan_blog_category'] as $table) { - $table = $setup->getTable($table); - $connection->addColumn( - $setup->getTable($table), - 'page_layout', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Post Layout', - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'layout_update_xml', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => '64k', - 'nullable' => true, - 'comment' => 'Post Layout Update Content', - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'custom_theme', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 100, - 'nullable' => true, - 'comment' => 'Post Custom Theme', - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'custom_layout', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Post Custom Template', - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'custom_layout_update_xml', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => '64k', - 'nullable' => true, - 'comment' => 'Post Custom Layout Update Content', - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'custom_theme_from', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATE, - 'nullable' => true, - 'comment' => 'Post Custom Theme Active From Date', - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'custom_theme_to', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATE, - 'nullable' => true, - 'comment' => 'Post Custom Theme Active To Date', - ] - ); - } - } - - if (version_compare($version, '2.3.0') < 0) { - /* Add meta title field to posts table */ - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'meta_title', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Post Meta Title', - 'after' => 'title' - ] - ); - - /* Add og tags fields to post table */ - foreach (['type', 'img', 'description', 'title'] as $type) { - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'og_' . $type, - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Post OG ' . ucfirst($type), - 'after' => 'identifier' - ] - ); - } - - /* Add meta title field to category table */ - $connection->addColumn( - $setup->getTable('magefan_blog_category'), - 'meta_title', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Category Meta Title', - 'after' => 'title' - ] - ); - - /** - * Create table 'magefan_blog_tag' - */ - $table = $setup->getConnection()->newTable( - $setup->getTable('magefan_blog_tag') - )->addColumn( - 'tag_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['identity' => true, 'nullable' => false, 'primary' => true], - 'Tag ID' - )->addColumn( - 'title', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - ['nullable' => true], - 'Tag Title' - )->addColumn( - 'identifier', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 100, - ['nullable' => true, 'default' => null], - 'Tag String Identifier' - )->addIndex( - $setup->getIdxName('magefan_blog_tag', ['identifier']), - ['identifier'] - )->setComment( - 'Magefan Blog Tag Table' - ); - $setup->getConnection()->createTable($table); - - /** - * Create table 'magefan_blog_post_tag' - */ - $table = $setup->getConnection()->newTable( - $setup->getTable('magefan_blog_post_tag') - )->addColumn( - 'post_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false, 'primary' => true], - 'Post ID' - )->addColumn( - 'tag_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false, 'primary' => true], - 'Tag ID' - )->addIndex( - $setup->getIdxName('magefan_blog_post_tag', ['tag_id']), - ['tag_id'] - )->addForeignKey( - $setup->getFkName('magefan_blog_post_tag', 'post_id', 'magefan_blog_post', 'post_id'), - 'post_id', - $setup->getTable('magefan_blog_post'), - 'post_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->addForeignKey( - $setup->getFkName('magefan_blog_post_tag', 'tag_id', 'magefan_blog_tag', 'tag_id'), - 'tag_id', - $setup->getTable('magefan_blog_tag'), - 'tag_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->setComment( - 'Magefan Blog Post To Category Linkage Table' - ); - $setup->getConnection()->createTable($table); - } - - if (version_compare($version, '2.4.4') < 0) { - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'media_gallery', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => '2M', - 'nullable' => true, - 'comment' => 'Media Gallery', - ] - ); - } - - if (version_compare($version, '2.5.2') < 0) { - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'secret', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => '32', - 'nullable' => true, - 'comment' => 'Post Secret', - ] - ); - - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'views_count', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - 'nullable' => true, - 'comment' => 'Post Views Count', - ] - ); - - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'is_recent_posts_skip', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - 'nullable' => true, - 'comment' => 'Is Post Skipped From Recent Posts', - ] - ); - - $connection->addIndex( - $setup->getTable('magefan_blog_post'), - $setup->getIdxName($setup->getTable('magefan_blog_post'), ['views_count']), - ['views_count'] - ); - - $connection->addIndex( - $setup->getTable('magefan_blog_post'), - $setup->getIdxName($setup->getTable('magefan_blog_post'), ['is_recent_posts_skip']), - ['is_recent_posts_skip'] - ); - } - - if (version_compare($version, '2.5.3') < 0) { - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'short_content', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => '2M', - 'nullable' => true, - 'comment' => 'Post Short Content', - ] - ); - } - - if (version_compare($version, '2.6.0') < 0) { - /** - * Create table 'magefan_blog_comment' - */ - $table = $setup->getConnection()->newTable( - $setup->getTable('magefan_blog_comment') - )->addColumn( - 'comment_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['identity' => true, 'nullable' => false, 'primary' => true], - 'Comment ID' - )->addColumn( - 'parent_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false], - 'Parent Comment ID' - )->addColumn( - 'post_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false], - 'Post ID' - )->addColumn( - 'customer_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => true], - 'Customer ID' - )->addColumn( - 'admin_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => true], - 'Admin User ID' - )->addColumn( - 'status', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - ['nullable' => false], - 'Comment status' - )->addColumn( - 'author_type', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - ['nullable' => false], - 'Author Type' - )->addColumn( - 'author_nickname', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - ['nullable' => false], - 'Comment Author Nickname' - )->addColumn( - 'author_email', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - ['nullable' => true], - 'Comment Author Email' - )->addColumn( - 'text', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - '2M', - [], - 'Text' - )->addColumn( - 'creation_time', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - [], - 'Comment Creation Time' - )->addColumn( - 'update_time', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - [], - 'Comment Update Time' - )->addIndex( - $installer->getIdxName('magefan_blog_comment', ['parent_id']), - ['parent_id'] - )->addIndex( - $installer->getIdxName('magefan_blog_comment', ['post_id']), - ['post_id'] - )->addIndex( - $installer->getIdxName('magefan_blog_comment', ['customer_id']), - ['customer_id'] - )->addIndex( - $installer->getIdxName('magefan_blog_comment', ['admin_id']), - ['admin_id'] - )->addIndex( - $installer->getIdxName('magefan_blog_comment', ['status']), - ['status'] - )->addForeignKey( - $installer->getFkName('magefan_blog_comment', 'post_id', 'magefan_blog_post', 'post_id'), - 'post_id', - $installer->getTable('magefan_blog_post'), - 'post_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - ); - $setup->getConnection()->createTable($table); - } - - if (version_compare($version, '2.6.2') < 0) { - /* Add include in menu field into categories table */ - $connection->addColumn( - $setup->getTable('magefan_blog_category'), - 'include_in_menu', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - ['nullable' => false, 'default' => '0'], - 'comment' => 'Category In Menu', - 'after' => 'position' - ] - ); - - $connection->addIndex( - $setup->getTable('magefan_blog_category'), - $setup->getIdxName($setup->getTable('magefan_blog_category'), ['include_in_menu']), - ['include_in_menu'] - ); - } - - if (version_compare($version, '2.6.3') < 0) { - /* Add display mode field into category table */ - $connection->addColumn( - $setup->getTable('magefan_blog_category'), - 'display_mode', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - 'nullable' => false, - 'default' => '0', - 'comment' => 'Display Mode', - 'after' => 'is_active' - ] - ); - } - - if (version_compare($version, '2.6.3.1') < 0) { - /* Add include in recent posts into post table */ - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'include_in_recent', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - 'nullable' => false, - 'default' => '1', - 'comment' => 'Include in Recent Posts', - 'after' => 'is_active' - ] - ); - } - - if (version_compare($version, '2.7.2') < 0) { - /* Add position column into post table */ - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'position', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - 'nullable' => false, - 'default' => '0', - 'comment' => 'Position', - 'after' => 'include_in_recent' - ] - ); - - $connection->addColumn( - $setup->getTable('magefan_blog_category'), - 'posts_sort_by', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - 'nullable' => false, - 'default' => '0', - 'comment' => 'Post Sort By', - 'after' => 'position' - ] - ); - } - - if (version_compare($version, '2.8.0') < 0) { - /* Add layout field to tag table */ - $table = $setup->getTable('magefan_blog_tag'); - $connection->addColumn( - $setup->getTable($table), - 'page_layout', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Tag Layout', - ] - ); - $connection->addColumn( - $setup->getTable($table), - 'is_active', - [ - 'type' =>\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - 'length' => 1, - 'nullable' => false, - 'default' => 1, - 'comment' => 'Is Tag Active' - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'content', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => '2M', - [], - 'comment' =>'Tag Content' - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'meta_title', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Tag Meta Title', - 'after' => 'title' - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'meta_keywords', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Tag Meta Keywords', - 'after' => 'title' - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'meta_description', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Tag Meta Description', - 'after' => 'title' - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'layout_update_xml', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => '64k', - 'nullable' => true, - 'comment' => 'Tag Layout Update Content', - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'custom_theme', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 100, - 'nullable' => true, - 'comment' => 'Tag Custom Theme', - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'custom_layout', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Tag Custom Template', - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'custom_layout_update_xml', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => '64k', - 'nullable' => true, - 'comment' => 'Tag Custom Layout Update Content', - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'custom_theme_from', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATE, - 'nullable' => true, - 'comment' => 'Tag Custom Theme Active From Date', - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'custom_theme_to', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATE, - 'nullable' => true, - 'comment' => 'Tag Custom Theme Active To Date', - ] - ); - - $connection->addIndex( - $setup->getTable($table), - $setup->getIdxName($setup->getTable($table), ['is_active']), - ['is_active'] - ); - } - - /* remove multi-fulltext, it does not supported in some DB - if (version_compare($version, '2.8.3.1') < 0) { - // Fix issue https://github.com/magefan/module-blog/issues/205 - $table = $setup->getTable('magefan_blog_post'); - foreach (['title', 'content', 'short_content'] as $field) { - $connection->addIndex( - $table, - $setup->getIdxName( - $table, - [$field], - AdapterInterface::INDEX_TYPE_FULLTEXT - ), - [$field], - AdapterInterface::INDEX_TYPE_FULLTEXT - ); - } - } - */ - - if (version_compare($version, '2.8.4.1') < 0) { - $table = $setup->getTable('magefan_blog_tag'); - $connection->addColumn( - $setup->getTable($table), - 'meta_robots', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Tag Default Robots', - 'after' => 'title' - ] - ); - } - - if (version_compare($version, '2.9.1') < 0) { - $table = $setup->getTable('magefan_blog_post'); - $connection->addColumn( - $setup->getTable($table), - 'featured_img_alt', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Featured Image Alt', - 'after' => 'featured_img' - ] - ); - - $connection->addColumn( - $setup->getTable($table), - 'comments_count', - [ - 'type' =>\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 'length' => null, - 'nullable' => true, - 'comment' => 'Post Comment Counts' - - ] - ); - } - - if (version_compare($version, '2.9.8') < 0) { - /** - * Create table 'magefan_blog_tag_store' - */ - $table = $connection->newTable( - $setup->getTable('magefan_blog_tag_store') - )->addColumn( - 'tag_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false, 'primary' => true], - 'Tag ID' - )->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - ['unsigned' => true, 'nullable' => false, 'primary' => true], - 'Store ID' - )->addIndex( - $setup->getIdxName('magefan_blog_tag_store', ['store_id']), - ['store_id'] - )->addForeignKey( - $setup->getFkName('magefan_blog_tag_store', 'tag_id', 'magefan_blog_tag', 'tag_id'), - 'tag_id', - $setup->getTable('magefan_blog_tag'), - 'tag_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->addForeignKey( - $setup->getFkName('magefan_blog_tag_store', 'store_id', 'store', 'store_id'), - 'store_id', - $setup->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - )->setComment( - 'Magefan Blog Tag To Store Linkage Table' - ); - $connection->createTable($table); - } - - if (version_compare($version, '2.10.0') < 0) { - foreach (['magefan_blog_tag', 'magefan_blog_category'] as $table) { - $connection->addColumn( - $setup->getTable($table), - 'posts_per_page', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 'nullable' => true, - 'comment' => 'Posts Per Page', - - ] - ); - $connection->addColumn( - $setup->getTable($table), - 'posts_list_template', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 100, - 'nullable' => true, - 'comment' => 'Posts List Template', - ] - ); - } - } - - if (version_compare($version, '2.11.1') < 0) { - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'structure_data_type', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - 'nullable' => false, - 'default' => '0', - 'comment' => 'Rich Snippet / Structured Data', - 'after' => 'meta_description' - ] - ); - - /* Add reading time to posts table */ - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'reading_time', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 'length' => 20, - 'nullable' => true, - 'comment' => 'Post Reading Time', - 'after' => 'views_count' - ] - ); - } - - if (version_compare($version, '2.11.3') < 0) { - if ($connection->isTableExists($setup->getTable('magefan_blog_category'))) { - $connection->addIndex( - $setup->getTable('magefan_blog_category'), - $setup->getIdxName( - $setup->getTable('magefan_blog_category'), - ['is_active'] - ), - ['is_active'] - ); - } - - if ($connection->isTableExists($setup->getTable('magefan_blog_post'))) { - $connection->addIndex( - $setup->getTable('magefan_blog_post'), - $setup->getIdxName( - $setup->getTable('magefan_blog_post'), - ['is_active'] - ), - ['is_active'] - ); - - $connection->addIndex( - $setup->getTable('magefan_blog_post'), - $setup->getIdxName( - $setup->getTable('magefan_blog_post'), - ['include_in_recent'] - ), - ['include_in_recent'] - ); - - $connection->addIndex( - $setup->getTable('magefan_blog_post'), - $setup->getIdxName( - $setup->getTable('magefan_blog_post'), - ['publish_time'] - ), - ['publish_time'] - ); - } - } - - $setup->endSetup(); - } -} diff --git a/etc/db_schema.xml b/etc/db_schema.xml new file mode 100644 index 00000000..f1e99404 --- /dev/null +++ b/etc/db_schema.xml @@ -0,0 +1,271 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+
diff --git a/etc/module.xml b/etc/module.xml index 5a66c28c..55ef8304 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -8,7 +8,7 @@ */ --> - + From 559392eb2f774d9eb19de285c64f7059ae5aa8de Mon Sep 17 00:00:00 2001 From: "ivan.hrytsai" Date: Wed, 13 Nov 2024 10:46:12 +0200 Subject: [PATCH 2/3] 12220-Declarative-Schema-for-Blog-extensions [in progress] --- Setup/Patch/Data/CreateDefaultPost.php | 14 +++-- Setup/Patch/Data/TagInStore.php | 75 +++++++++++--------------- 2 files changed, 38 insertions(+), 51 deletions(-) diff --git a/Setup/Patch/Data/CreateDefaultPost.php b/Setup/Patch/Data/CreateDefaultPost.php index 027f068d..76fcc1f6 100644 --- a/Setup/Patch/Data/CreateDefaultPost.php +++ b/Setup/Patch/Data/CreateDefaultPost.php @@ -9,9 +9,10 @@ namespace Magefan\Blog\Setup\Patch\Data; use Magento\Framework\Setup\Patch\DataPatchInterface; -use Magento\Framework\Setup\Patch\PatchRevertableInterface; -class CreateDefaultPost implements DataPatchInterface, PatchRevertableInterface +use Magento\Framework\Setup\Patch\PatchVersionInterface; + +class CreateDefaultPost implements DataPatchInterface, PatchVersionInterface { /** * Post factory @@ -32,6 +33,7 @@ class CreateDefaultPost implements DataPatchInterface, PatchRevertableInterface */ private $scopeConfig; + public function __construct( \Magefan\Blog\Model\PostFactory $postFactory, \Magento\Framework\App\State $state, @@ -42,13 +44,8 @@ public function __construct( $this->scopeConfig = $scopeConfig; } - public function apply() { - /*if (version_compare($version, '2.9.1') < 0) { - return; - }*/ - try { $this->state->setAreaCode('adminhtml'); } catch (\Exception $e) { @@ -119,7 +116,8 @@ public function getAliases() return[]; } - public function revert() + public static function getVersion() { + return '2.11.3'; } } \ No newline at end of file diff --git a/Setup/Patch/Data/TagInStore.php b/Setup/Patch/Data/TagInStore.php index 0e47886d..58fac89a 100644 --- a/Setup/Patch/Data/TagInStore.php +++ b/Setup/Patch/Data/TagInStore.php @@ -9,83 +9,72 @@ namespace Magefan\Blog\Setup\Patch\Data; use Magefan\Blog\Model\ResourceModel\Comment; -use Magento\Framework\Module\ModuleResource; use Magento\Framework\Setup\Patch\DataPatchInterface; -use Magento\Framework\Setup\Patch\PatchRevertableInterface; +use Magento\Framework\Setup\Patch\PatchVersionInterface; -class TagInStore implements DataPatchInterface, PatchRevertableInterface +class TagInStore implements DataPatchInterface, PatchVersionInterface { /** * @var Comment */ protected $commentResource; - /** - * @var ModuleResource - */ - private $moduleResource; - /** * @param Comment $commentResource - * @param ModuleContextInterface $context */ public function __construct( - Comment $commentResource, - ModuleResource $moduleResource - ) { + Comment $commentResource + ) + { $this->commentResource = $commentResource; - $this->moduleResource = $moduleResource; } public static function getDependencies() { - return[]; + return []; } public function getAliases() { - return[]; + return []; } public function apply() { - $version = $this->moduleResource->getDbVersion('Magefan_Blog'); - - if (version_compare($version, '2.9.8') < 0) { - $connection = $this->commentResource->getConnection(); + $connection = $this->commentResource->getConnection(); - $connection->delete( - $this->commentResource->getTable('magefan_blog_tag_store'), - ['store_id = ?' => 0] - ); + $connection->delete( + $this->commentResource->getTable('magefan_blog_tag_store'), + ['store_id = ?' => 0] + ); - $tagSelect = $connection->select()->from( - [$this->commentResource->getTable('magefan_blog_tag')] - ); - $tags = $connection->fetchAll($tagSelect); + $tagSelect = $connection->select()->from( + [$this->commentResource->getTable('magefan_blog_tag')] + ); + $tags = $connection->fetchAll($tagSelect); - $count = count($tags); - if ($count) { - $data = []; - foreach ($tags as $i => $tag) { - $data[] = [ - 'tag_id' => $tag['tag_id'], - 'store_id' => 0, - ]; + $count = count($tags); + if ($count) { + $data = []; + foreach ($tags as $i => $tag) { + $data[] = [ + 'tag_id' => $tag['tag_id'], + 'store_id' => 0, + ]; - if (count($data) == 100 || $i == $count - 1) { - $connection->insertMultiple( - $this->commentResource->getTable('magefan_blog_tag_store'), - $data - ); - $data = []; - } + if (count($data) == 100 || $i == $count - 1) { + $connection->insertMultiple( + $this->commentResource->getTable('magefan_blog_tag_store'), + $data + ); + $data = []; } } } } - public function revert() + public static function getVersion() { + return '2.9.8'; } } From b23f2de4500df11202a98335a61156c4c24798e0 Mon Sep 17 00:00:00 2001 From: "ivan.hrytsai" Date: Wed, 13 Nov 2024 10:51:11 +0200 Subject: [PATCH 3/3] 12220-Declarative-Schema-for-Blog-extensions [in progress] --- Setup/Patch/Data/UpdatePostCommentsCount.php | 37 +++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/Setup/Patch/Data/UpdatePostCommentsCount.php b/Setup/Patch/Data/UpdatePostCommentsCount.php index 99f2ae09..b053527f 100644 --- a/Setup/Patch/Data/UpdatePostCommentsCount.php +++ b/Setup/Patch/Data/UpdatePostCommentsCount.php @@ -10,10 +10,10 @@ use Magento\Framework\Module\ModuleResource; use Magento\Framework\Setup\Patch\DataPatchInterface; -use Magento\Framework\Setup\Patch\PatchRevertableInterface; use Magefan\Blog\Model\ResourceModel\Comment; +use Magento\Framework\Setup\Patch\PatchVersionInterface; -class UpdatePostCommentsCount implements DataPatchInterface, PatchRevertableInterface +class UpdatePostCommentsCount implements DataPatchInterface, PatchVersionInterface { /** * @var Comment @@ -30,40 +30,43 @@ class UpdatePostCommentsCount implements DataPatchInterface, PatchRevertableInte * @param ModuleContextInterface $context */ public function __construct( - Comment $commentResource, + Comment $commentResource, ModuleResource $moduleResource - ) { + ) + { $this->commentResource = $commentResource; $this->moduleResource = $moduleResource; } public static function getDependencies() { - return[]; + return []; } public function getAliases() { - return[]; + return []; } public function apply() { - $version = $this->moduleResource->getDbVersion('Magefan_Blog'); - if (version_compare($version, '2.9.1') < 0) { - $connection = $this->commentResource->getConnection(); - $postSelect = $connection->select()->from( - [$this->commentResource->getTable('magefan_blog_post')] - ) - ->where('is_active = ?', 1); - $posts = $connection->fetchAll($postSelect); - foreach ($posts as $post) { - $this->commentResource->updatePostCommentsCount($post['post_id']); - } + $connection = $this->commentResource->getConnection(); + $postSelect = $connection->select()->from( + [$this->commentResource->getTable('magefan_blog_post')] + ) + ->where('is_active = ?', 1); + $posts = $connection->fetchAll($postSelect); + foreach ($posts as $post) { + $this->commentResource->updatePostCommentsCount($post['post_id']); } } public function revert() { } + + public static function getVersion() + { + return '2.9.1'; + } }