diff --git a/Api/ManagementInterface.php b/Api/ManagementInterface.php index fb0b5dbf..cb749489 100644 --- a/Api/ManagementInterface.php +++ b/Api/ManagementInterface.php @@ -43,9 +43,10 @@ public function delete($id); * * @api * @param int $id + * @param int|null $storeId * @return bool */ - public function get($id); + public function get($id, $storeId = null); /** * Get item by id and store id, only if item published diff --git a/Model/AbstractManagement.php b/Model/AbstractManagement.php index 884edcd6..9b4aa42a 100644 --- a/Model/AbstractManagement.php +++ b/Model/AbstractManagement.php @@ -114,13 +114,20 @@ public function create($data) public function update($id, $data) { try { + $data = json_decode($data, true); $item = $this->_itemFactory->create(); + + if (!empty($data['store_id'])) { + $item->setStoreId((int)$data['store_id']); + $item->setData('data_to_update', $data); + } + $item->load($id); if (!$item->getId()) { return false; } - $data = json_decode($data, true); + foreach ($this->_imagesMap as $key) { if (empty($data[$key . '_name']) || empty($data[$key . '_content'])) { unset($data[$key . '_name']); @@ -162,12 +169,18 @@ public function delete($id) * Get item by id * * @param int $id + * @param int|null $storeId * @return bool */ - public function get($id) + public function get($id, $storeId = 0) { try { $item = $this->_itemFactory->create(); + + if ($storeId) { + $item->setStoreId((int)$storeId); + } + $item->load($id); if (!$item->getId()) { @@ -190,6 +203,11 @@ public function view($id, $storeId) { try { $item = $this->_itemFactory->create(); + + if ($storeId) { + $item->setStoreId((int)$storeId); + } + $item->getResource()->load($item, $id); if (!$item->isVisibleOnStore($storeId)) { diff --git a/Model/AuthorRepository.php b/Model/AuthorRepository.php index 3a3764ed..e6d79ce3 100644 --- a/Model/AuthorRepository.php +++ b/Model/AuthorRepository.php @@ -128,6 +128,11 @@ public function getById($authorId, $editMode = false, $storeId = null, $forceRel $cacheKey = implode('_', func_get_args()); if (!isset($this->instances[$cacheKey])) { $author = $this->authorFactory->create(); + + if ($storeId) { + $author->setStoreId($storeId); + } + $this->authorResourceModel->load($author, $authorId); if (!$author->getId()) { throw new NoSuchEntityException(__('Requested item doesn\'t exist')); diff --git a/Model/CategoryRepository.php b/Model/CategoryRepository.php index e1697e32..44e32ba7 100644 --- a/Model/CategoryRepository.php +++ b/Model/CategoryRepository.php @@ -127,6 +127,11 @@ public function getById($categoryId, $editMode = false, $storeId = null, $forceR $cacheKey = implode('_', func_get_args()); if (!isset($this->instances[$cacheKey])) { $category = $this->categoryFactory->create(); + + if ($storeId) { + $category->setStoreId($storeId); + } + $this->categoryResourceModel->load($category, $categoryId); if (!$category->getId()) { throw new NoSuchEntityException(__('Requested item doesn\'t exist')); diff --git a/Model/PostRepository.php b/Model/PostRepository.php index dbede1db..71cb694b 100644 --- a/Model/PostRepository.php +++ b/Model/PostRepository.php @@ -120,7 +120,13 @@ public function save(Post $post) public function getById($postId, $editMode = false, $storeId = null, $forceReload = false) { $post = $this->postFactory->create(); + + if ($storeId) { + $post->setStoreId($storeId); + } + $this->postResourceModel->load($post, $postId); + if (!$post->getId()) { throw new NoSuchEntityException(__('Requested item doesn\'t exist')); } diff --git a/Model/ResourceModel/Category.php b/Model/ResourceModel/Category.php index 963dc56e..68f184fc 100755 --- a/Model/ResourceModel/Category.php +++ b/Model/ResourceModel/Category.php @@ -284,4 +284,12 @@ public function lookupStoreIds($categoryId, $useCache = true) return []; } + + /** + * @return string + */ + public function getEntityType() + { + return 'category'; + } } diff --git a/Model/ResourceModel/Category/Collection.php b/Model/ResourceModel/Category/Collection.php index a139fc2d..42a7000a 100755 --- a/Model/ResourceModel/Category/Collection.php +++ b/Model/ResourceModel/Category/Collection.php @@ -13,6 +13,16 @@ */ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection { + /** + * @inheritDoc + */ + protected $_eventPrefix = 'mfblog_category_collection'; + + /** + * @inheritDoc + */ + protected $_eventObject = 'blog_category_collection'; + /** * @inheritDoc */ diff --git a/Model/ResourceModel/Post.php b/Model/ResourceModel/Post.php index 80b51b70..cab04d1d 100755 --- a/Model/ResourceModel/Post.php +++ b/Model/ResourceModel/Post.php @@ -527,4 +527,12 @@ protected function _lookupAll($postId, $tableName, $field) return $adapter->fetchAll($select); } + + /** + * @return string + */ + public function getEntityType() + { + return 'post'; + } } diff --git a/Model/ResourceModel/Post/Collection.php b/Model/ResourceModel/Post/Collection.php index 56b2a488..dd4ecd00 100755 --- a/Model/ResourceModel/Post/Collection.php +++ b/Model/ResourceModel/Post/Collection.php @@ -28,6 +28,11 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab */ protected $_eventObject = 'blog_post_collection'; + /** + * @var string[] + */ + protected $_ftiCollumns = ['title', 'meta_keywords', 'meta_description', 'identifier', 'content']; + /** * @var \Magento\Store\Model\StoreManagerInterface */ @@ -103,7 +108,6 @@ protected function _construct() $this->_map['fields']['store'] = 'store_table.store_id'; $this->_map['fields']['category'] = 'category_table.category_id'; $this->_map['fields']['tag'] = 'tag_table.tag_id'; - $this->_map['fields']['tag'] = 'tag_table.tag_id'; $this->_map['fields']['relatedproduct'] = 'relatedproduct_table.related_id'; } @@ -401,10 +405,7 @@ public function addSearchFilter($term) $tagPostIds = array_slice($tagPostIds, 0, 200); } - $fullExpression = '(0 ' . - '+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST (' - . $this->getConnection()->quote($term) - . '), 4) ' . + $fullExpression = $this->getSearchRateExpression($term, $this->_ftiCollumns) . '+ IF(main_table.post_id IN (' . implode(',', $tagPostIds) . '), "1", "0"))'; $fullExpression = new \Zend_Db_Expr($fullExpression); @@ -420,19 +421,25 @@ public function addSearchFilter($term) ] ); - $fullExpression = '(0 ' . - '+ FORMAT(MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST (' - . $this->getConnection()->quote($term) - . '), 4))'; - - $fullExpression = new \Zend_Db_Expr($fullExpression); + $fullExpression = new \Zend_Db_Expr($this->getSearchRateExpression($term, $this->_ftiCollumns)); $this->getSelect()->columns(['search_rate' => $fullExpression]); + //$this->expressionFieldsToSelect['search_rate'] = $fullExpression; } return $this; } + /** + * @param $term + * @param array $columns + * @return string + */ + public function getSearchRateExpression($term, array $columns): string + { + return '(0 + FORMAT(MATCH (' . implode(',', $columns) . ') AGAINST (' . $this->getConnection()->quote($term) . '), 4)) '; + } + /** * Add tag filter to collection * @param array|int|string|\Magefan\Blog\Model\Tag $tag diff --git a/Model/ResourceModel/Tag.php b/Model/ResourceModel/Tag.php index d9589cb7..42df0172 100755 --- a/Model/ResourceModel/Tag.php +++ b/Model/ResourceModel/Tag.php @@ -48,19 +48,21 @@ protected function _beforeDelete(\Magento\Framework\Model\AbstractModel $object) */ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) { - $object->setTitle( - trim(($object->getTitle())) - ); - - $tag = $object->getCollection() - ->addFieldToFilter('title', $object->getTitle()) - ->addFieldToFilter('tag_id', ['neq' => $object->getId()]) - ->setPageSize(1) - ->getFirstItem(); - if ($tag->getId()) { - throw new \Magento\Framework\Exception\LocalizedException( - __('The tag is already exist.') + if ($object->getTitle()) { + $object->setTitle( + trim(($object->getTitle())) ); + + $tag = $object->getCollection() + ->addFieldToFilter('title', $object->getTitle()) + ->addFieldToFilter('tag_id', ['neq' => $object->getId()]) + ->setPageSize(1) + ->getFirstItem(); + if ($tag->getId()) { + throw new \Magento\Framework\Exception\LocalizedException( + __('The tag is already exist.') + ); + } } $identifierGenerator = \Magento\Framework\App\ObjectManager::getInstance() @@ -180,7 +182,7 @@ public function checkIdentifier($identifier, $storeIds) $select = $this->_getLoadByIdentifierSelect($identifier, $storeIds); $select->reset(\Zend_Db_Select::COLUMNS)->columns(['cp.tag_id', 'cp.identifier'])->order('cps.store_id DESC')->limit(1); - + $row = $this->getConnection()->fetchRow($select); if (isset($row['tag_id']) && isset($row['identifier']) @@ -338,4 +340,12 @@ protected function _lookupAll($tagId, $tableName, $field) return $adapter->fetchAll($select); } + + /** + * @return string + */ + public function getEntityType() + { + return 'tag'; + } } diff --git a/Model/ResourceModel/Tag/Collection.php b/Model/ResourceModel/Tag/Collection.php index 53f261a6..2f45d682 100755 --- a/Model/ResourceModel/Tag/Collection.php +++ b/Model/ResourceModel/Tag/Collection.php @@ -13,6 +13,16 @@ */ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection { + /** + * @inheritDoc + */ + protected $_eventPrefix = 'mfblog_tag_collection'; + + /** + * @inheritDoc + */ + protected $_eventObject = 'blog_tag_collection'; + /** * @inheritDoc */ diff --git a/Model/TagRepository.php b/Model/TagRepository.php index 7bc2beb3..1c333b34 100644 --- a/Model/TagRepository.php +++ b/Model/TagRepository.php @@ -120,6 +120,11 @@ public function save(Tag $tag) public function getById($tagId, $editMode = false, $storeId = null, $forceReload = false) { $tag = $this->tagFactory->create(); + + if ($storeId) { + $tag->setStoreId($storeId); + } + $this->tagResourceModel->load($tag, $tagId); if (!$tag->getId()) { throw new NoSuchEntityException(__('Requested item doesn\'t exist')); diff --git a/Setup/InstallData.php b/Setup/InstallData.php deleted file mode 100755 index 00dd0305..00000000 --- a/Setup/InstallData.php +++ /dev/null @@ -1,121 +0,0 @@ -_postFactory = $postFactory; - $this->state = $state; - $this->scopeConfig = $scopeConfig; - } - - /** - * {@inheritdoc} - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) - { - try { - $this->state->setAreaCode('adminhtml'); - } catch (\Exception $e) { - /* Do nothing, it's OK */ - } - - $url = $this->scopeConfig - ->getValue( - 'web/unsecure/base_url', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - 0 - ); - $useLinks = \Magefan\Community\Model\UrlChecker::showUrl($url); - $useLinks = false; - - $data = [ - 'title' => 'Magento 2 Blog Post Sample', - 'meta_keywords' => 'magento 2 blog sample', - 'meta_description' => 'Magento 2 blog default post.', - 'identifier' => 'magento-2-blog-post-sample', - 'content_heading' => 'Magento 2 Blog Post Sample', - 'content' => - $useLinks - ? '
Welcome to - Magento Blog by - Magefan. - This is your first post. Edit or delete it, then start blogging! -
- -Please also read - Magento 2 Blog online documentation and - How to add "read more" tag to post content -
-Follow Magefan on:
-- Magento 2 Blog Extension GitHub | - Magefan at Twitter | - Magefan at Facebook -
' - : '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(); - } -} 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/Patch/Data/CreateSamplePost.php b/Setup/Patch/Data/CreateSamplePost.php new file mode 100644 index 00000000..3a595c53 --- /dev/null +++ b/Setup/Patch/Data/CreateSamplePost.php @@ -0,0 +1,90 @@ +_postFactory = $postFactory; + $this->postCollection = $postCollection; + $this->state = $state; + $this->scopeConfig = $scopeConfig; + } + + public function apply() + { + try { + $this->state->setAreaCode('adminhtml'); + } catch (\Exception $e) { + /* Do nothing, it's OK */ + } + + if (!$this->postCollection->create()->getSize()) { + + $data = [ + 'title' => 'Magento 2 Blog Post Sample', + 'meta_keywords' => 'magento 2 blog sample', + 'meta_description' => 'Magento 2 blog default post.', + 'identifier' => 'magento-2-blog-post-sample', + 'content_heading' => 'Magento 2 Blog Post Sample', + 'content' => '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[]; + } +} diff --git a/Setup/Patch/Data/TagInStore.php b/Setup/Patch/Data/TagInStore.php new file mode 100644 index 00000000..3c4db238 --- /dev/null +++ b/Setup/Patch/Data/TagInStore.php @@ -0,0 +1,73 @@ +resourceConnection = $resourceConnection; + } + + public static function getDependencies() + { + return []; + } + + public function getAliases() + { + return []; + } + + public function apply() + { + $connection = $this->resourceConnection->getConnection(); + + $connection->delete( + $this->resourceConnection->getTableName('magefan_blog_tag_store'), + ['store_id = ?' => 0] + ); + + $tagSelect = $connection->select()->from( + $this->resourceConnection->getTableName('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, + ]; + + if (count($data) == 100 || $i == $count - 1) { + $connection->insertMultiple( + $this->resourceConnection->getTableName('magefan_blog_tag_store'), + $data + ); + $data = []; + } + } + } + } +} diff --git a/Setup/Patch/Data/UpdatePostCommentsCount.php b/Setup/Patch/Data/UpdatePostCommentsCount.php new file mode 100644 index 00000000..79e43fbb --- /dev/null +++ b/Setup/Patch/Data/UpdatePostCommentsCount.php @@ -0,0 +1,61 @@ +commentResource = $commentResource; + $this->moduleResource = $moduleResource; + } + + public function apply() + { + $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 static function getDependencies() + { + return []; + } + + public function getAliases() + { + return []; + } +} diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php deleted file mode 100644 index 166384d4..00000000 --- a/Setup/UpgradeData.php +++ /dev/null @@ -1,76 +0,0 @@ -commentResource = $commentResource; - } - - public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) - { - $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']); - } - } - - if (version_compare($version, '2.9.8') < 0) { - $connection = $this->commentResource->getConnection(); - - $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); - - $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 = []; - } - } - } - } - } -} diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php deleted file mode 100644 index bd7a4015..00000000 --- a/Setup/UpgradeSchema.php +++ /dev/null @@ -1,937 +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'] - ); - } - } - - if (version_compare($version, '2.12.1') < 0) { - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'meta_robots', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Default Robots', - 'after' => 'meta_description' - ] - ); - $connection->addColumn( - $setup->getTable('magefan_blog_category'), - 'meta_robots', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'comment' => 'Default Robots', - 'after' => 'meta_description' - ] - ); - - $connection->addColumn( - $setup->getTable('magefan_blog_category'), - 'include_in_sidebar_tree', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'default' => '1', - 'comment' => 'Category In Sidebar Tree', - 'after' => 'include_in_menu' - ] - ); - - $connection->addIndex( - $setup->getTable('magefan_blog_category'), - $setup->getIdxName( - 'magefan_blog_category', - ['include_in_sidebar_tree'], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX - ), - ['include_in_sidebar_tree'], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX - ); - - } - if (version_compare($version, '2.12.3') < 0) { - $connection->addColumn( - $setup->getTable('magefan_blog_post'), - 'custom_css', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'nullable' => true, - 'comment' => 'Custom CSS', - 'after' => 'layout_update_xml' - ] - ); - } - $setup->endSetup(); - } -} diff --git a/etc/db_schema.xml b/etc/db_schema.xml new file mode 100644 index 00000000..28bb63c9 --- /dev/null +++ b/etc/db_schema.xml @@ -0,0 +1,343 @@ + + +