diff --git a/src/Core/Content/Blog/Author/AuthorDefinition.php b/src/Core/Content/Blog/Author/AuthorDefinition.php index 6b55db5..17cb791 100644 --- a/src/Core/Content/Blog/Author/AuthorDefinition.php +++ b/src/Core/Content/Blog/Author/AuthorDefinition.php @@ -8,6 +8,7 @@ namespace Magefan\Blog\Core\Content\Blog\Author; +use Magefan\Blog\Core\Content\Blog\Author\AuthorTranslation\AuthorTranslationDefinition; use Magefan\Blog\Core\Content\Blog\Post\PostDefinition; use Shopware\Core\Content\Media\MediaDefinition; use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition; @@ -61,11 +62,10 @@ protected function defineFields(): FieldCollection return new FieldCollection([ (new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()), (new IdField('admin_user_id', 'adminUserId'))->addFlags(new Required()), - (new BoolField('is_active', 'isActive')), + new FkField('media_id', 'mediaId', MediaDefinition::class), + (new StringField('firstname', 'firstname')), (new StringField('lastname', 'lastname')), - (new StringField('email', 'email')), - (new StringField('role', 'role')), (new StringField('facebook_page_url', 'facebookPageUrl')), (new StringField('twitter_page_url', 'twitterPageUrl')), (new StringField('instagram_page_url', 'instagramPageUrl')), @@ -79,6 +79,9 @@ protected function defineFields(): FieldCollection (new LongTextField('content', 'content')), (new LongTextField('short_content', 'short_content')), (new StringField('featured_img', 'featuredImg')), + (new BoolField('is_active', 'isActive')), + (new StringField('email', 'email')), + (new StringField('role', 'role')), (new StringField('page_layout', 'pageLayout')), (new StringField('layout_update_xml', 'layoutUpdateXml')), (new StringField('custom_theme', 'customTheme')), @@ -91,7 +94,8 @@ protected function defineFields(): FieldCollection (new IdField('media_id', 'mediaId')), (new StringField('created_at', 'createdAt')), (new StringField('updated_at', 'updatedAt')), - new FkField('media_id', 'mediaId', MediaDefinition::class), + + // associations new OneToManyAssociationField('authorPosts', PostDefinition::class, 'author_id'), (new OneToOneAssociationField('media', 'media_id', 'id', MediaDefinition::class, true))->addFlags(new ApiAware()), ]); diff --git a/src/Core/Content/Blog/Category/CategoryDefinition.php b/src/Core/Content/Blog/Category/CategoryDefinition.php index 4ea5042..5871383 100644 --- a/src/Core/Content/Blog/Category/CategoryDefinition.php +++ b/src/Core/Content/Blog/Category/CategoryDefinition.php @@ -8,15 +8,19 @@ namespace Magefan\Blog\Core\Content\Blog\Category; +use Magefan\Blog\Core\Content\Blog\Category\CategoryTranslation\CategoryTranslationDefinition; use Magefan\Blog\Core\Content\Blog\Post\PostDefinition; use Magefan\Blog\Core\Content\Blog\PostCategory\PostCategoryDefinition; use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition; use Shopware\Core\Framework\DataAbstractionLayer\Field\DateField; +use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware; use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\CascadeDelete; +use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Inherited; use Shopware\Core\Framework\DataAbstractionLayer\Field\IntField; -use Shopware\Core\Framework\DataAbstractionLayer\Field\LongTextField; use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyAssociationField; use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToOneAssociationField; +use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslatedField; +use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslationsAssociationField; use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection; use Shopware\Core\Framework\DataAbstractionLayer\Field\BoolField; use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey; @@ -59,16 +63,18 @@ protected function defineFields(): FieldCollection { return new FieldCollection([ (new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()), - (new StringField('title', 'title'))->addFlags(new Required()), - (new StringField('meta_title', 'metaTitle')), - (new StringField('meta_keywords', 'metaKeywords')), - (new StringField('meta_description', 'metaDescription')), - (new StringField('identifier', 'identifier')), - (new LongTextField('content_heading', 'contentHeading')), - (new LongTextField('content', 'content')), - (new StringField('path', 'path')), + + //translations + (new TranslatedField('title'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('metaTitle'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('metaKeywords'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('metaDescription'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('contentHeading'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('content'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('path'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('identifier'))->addFlags(new ApiAware(), new Inherited()), + (new IntField('position', 'position')), - (new StringField('path', 'path')), (new StringField('posts_sort_by', 'postsSortBy')), (new BoolField('include_in_menu', 'includeInMenu')), (new BoolField('is_active', 'isActive')), @@ -84,7 +90,10 @@ protected function defineFields(): FieldCollection (new StringField('posts_list_template', 'postsListTemplate')), (new StringField('created_at', 'createdAt')), (new StringField('updated_at', 'updatedAt')), + + // associations (new OneToOneAssociationField('blogCategories', 'id', 'category_id', PostCategoryDefinition::class, false))->addFlags(new CascadeDelete()), new ManyToManyAssociationField('blogPosts', PostDefinition::class, PostCategoryDefinition::class, 'category_id', 'post_id'), + (new TranslationsAssociationField(CategoryTranslationDefinition::class, 'magefanblog_category_id'))->addFlags(new ApiAware(), new Required()) ]); } } diff --git a/src/Core/Content/Blog/Category/CategoryTranslation/CategoryTranslationCollection.php b/src/Core/Content/Blog/Category/CategoryTranslation/CategoryTranslationCollection.php new file mode 100644 index 0000000..afe348c --- /dev/null +++ b/src/Core/Content/Blog/Category/CategoryTranslation/CategoryTranslationCollection.php @@ -0,0 +1,31 @@ +addFlags(new ApiAware(), new Required()), + (new StringField('title', 'title'))->addFlags(new Required()), + (new StringField('meta_title', 'metaTitle')), + (new StringField('meta_keywords', 'metaKeywords')), + (new StringField('meta_description', 'metaDescription')), + (new LongTextField('content_heading', 'contentHeading')), + (new LongTextField('content', 'content')), + (new StringField('identifier', 'identifier')), + (new StringField('path', 'path')), + ]); + } +} diff --git a/src/Core/Content/Blog/Category/CategoryTranslation/CategoryTranslationEntity.php b/src/Core/Content/Blog/Category/CategoryTranslation/CategoryTranslationEntity.php new file mode 100644 index 0000000..dcfd73f --- /dev/null +++ b/src/Core/Content/Blog/Category/CategoryTranslation/CategoryTranslationEntity.php @@ -0,0 +1,18 @@ +addFilter(new EqualsFilter('identifier', $identifier)) + ->addFilter(new EqualsFilter('id', $identifier)) ->addFilter(new EqualsFilter('isActive', 1)) ->addAssociation('blogCategories') ->addAssociation('blogPosts'); @@ -97,8 +97,9 @@ public function getPostsByCategory($category, $request, $context): EntityCollect ->addAssociation('blogCategories') ->addAssociation('postTags') ->addAssociation('postAuthor') + ->addFilter(new EqualsFilter('isActive', 1)) ->addSorting(new FieldSorting('postTags'. '.' . $sortBy, $sorting)) - ->addFilter(new EqualsFilter('postCategories.identifier', $category->getIdentifier())) + ->addFilter(new EqualsFilter('postCategories.id', $category->getId())) ->setLimit((bool)$category->getPostsPerPage() ? $category->getPostsPerPage() : $limit) ->setOffset($pageOffset); diff --git a/src/Core/Content/Blog/DataResolver/BlogListResolver.php b/src/Core/Content/Blog/DataResolver/BlogListResolver.php index 0056219..791cce5 100644 --- a/src/Core/Content/Blog/DataResolver/BlogListResolver.php +++ b/src/Core/Content/Blog/DataResolver/BlogListResolver.php @@ -18,15 +18,6 @@ class BlogListResolver { - /** - * @var EntityRepository - */ - private EntityRepository $blogAuthorRepository; - - /** - * @var EntityRepository - */ - private EntityRepository $blogCategoryRepository; /** * @var SystemConfigService diff --git a/src/Core/Content/Blog/DataResolver/BlogPostResolver.php b/src/Core/Content/Blog/DataResolver/BlogPostResolver.php index a827c3f..a965b5d 100644 --- a/src/Core/Content/Blog/DataResolver/BlogPostResolver.php +++ b/src/Core/Content/Blog/DataResolver/BlogPostResolver.php @@ -43,7 +43,7 @@ public function __construct( public function getPost($identifier, $context) { $postCriteria = (new Criteria()) - ->addFilter(new EqualsFilter('identifier', $identifier)) + ->addFilter(new EqualsFilter('id', $identifier)) ->addFilter(new EqualsFilter('isActive', 1)) ->addAssociation('postCategories') ->addAssociation('postTags') diff --git a/src/Core/Content/Blog/DataResolver/BlogTagResolver.php b/src/Core/Content/Blog/DataResolver/BlogTagResolver.php index b699d7a..5778b2f 100644 --- a/src/Core/Content/Blog/DataResolver/BlogTagResolver.php +++ b/src/Core/Content/Blog/DataResolver/BlogTagResolver.php @@ -52,7 +52,7 @@ public function getTag($tagId, $context) { $criteria = (new Criteria()) ->addFilter(new EqualsFilter('isActive', 1)) - ->addFilter(new EqualsFilter('identifier', $tagId)) + ->addFilter(new EqualsFilter('id', $tagId)) ->addAssociation('postTags'); $author = $this->blogTagRepository->search($criteria, $context->getContext())->getEntities()->first(); diff --git a/src/Core/Content/Blog/Post/PostDefinition.php b/src/Core/Content/Blog/Post/PostDefinition.php index c51c229..eb3173f 100644 --- a/src/Core/Content/Blog/Post/PostDefinition.php +++ b/src/Core/Content/Blog/Post/PostDefinition.php @@ -11,6 +11,7 @@ use Magefan\Blog\Core\Content\Blog\Author\AuthorDefinition; use Magefan\Blog\Core\Content\Blog\Category\CategoryDefinition; use Magefan\Blog\Core\Content\Blog\Comment\CommentDefinition; +use Magefan\Blog\Core\Content\Blog\Post\PostTranslation\PostTranslationDefinition; use Magefan\Blog\Core\Content\Blog\PostCategory\PostCategoryDefinition; use Magefan\Blog\Core\Content\Blog\PostTag\PostTagDefinition; use Magefan\Blog\Core\Content\Blog\Tag\TagDefinition; @@ -20,12 +21,14 @@ use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField; use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\AllowHtml; use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware; +use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Inherited; use Shopware\Core\Framework\DataAbstractionLayer\Field\IntField; -use Shopware\Core\Framework\DataAbstractionLayer\Field\LongTextField; use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyAssociationField; use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField; use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField; use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToOneAssociationField; +use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslatedField; +use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslationsAssociationField; use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection; use Shopware\Core\Framework\DataAbstractionLayer\Field\BoolField; use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey; @@ -68,33 +71,40 @@ protected function defineFields(): FieldCollection { return new FieldCollection([ (new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()), - (new StringField('title', 'title'))->addFlags(new Required()), - (new StringField('meta_title', 'metaTitle')), - (new StringField('meta_keywords', 'metaKeywords')), - (new StringField('meta_description', 'metaDescription')), - (new LongTextField('content_heading', 'contentHeading'))->addFlags(new AllowHtml()), - (new LongTextField('content', 'content'))->addFlags(new AllowHtml()), - (new StringField('identifier', 'identifier'))->addFlags(new Required()), + new FkField('media_id', 'mediaId', MediaDefinition::class), + new FkField('author_id', 'authorId', AuthorDefinition::class), + + //translations + (new TranslatedField('title'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('metaTitle'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('metaKeywords'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('metaDescription'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('contentHeading'))->addFlags(new ApiAware(), new AllowHtml()), + (new TranslatedField('content'))->addFlags(new ApiAware(), new AllowHtml()), + (new TranslatedField('featuredImg'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('featuredImgAlt'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('ogTitle'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('ogDescription'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('ogImg'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('ogType'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('identifier'))->addFlags(new ApiAware(), new Inherited()), + (new IntField('position', 'position')), - (new StringField('featured_img', 'featuredImg')), - (new StringField('featured_img_alt', 'featuredImgAlt')), (new BoolField('include_in_recent', 'includeInRecent')), - (new StringField('og_title', 'ogTitle')), - (new StringField('og_description', 'ogDescription')), - (new IdField('og_img', 'ogImg')), - (new StringField('og_type', 'ogType')), (new DateTimeField('publish_time', 'publishTime')), (new StringField('created_at', 'createdAt')), (new StringField('updated_at', 'updatedAt')), (new DateTimeField('publish_time', 'publishTime')), (new BoolField('is_active', 'isActive')), - new FkField('media_id', 'mediaId', MediaDefinition::class), + + // associations (new OneToOneAssociationField('media', 'media_id', 'id', MediaDefinition::class, true))->addFlags(new ApiAware()), new FkField('author_id', 'authorId', AuthorDefinition::class), new ManyToOneAssociationField('postAuthor', 'author_id', AuthorDefinition::class, 'id'), new ManyToManyAssociationField('postTags', TagDefinition::class, PostTagDefinition::class, 'post_id', 'tag_id'), new ManyToManyAssociationField('postCategories', CategoryDefinition::class, PostCategoryDefinition::class, 'post_id', 'category_id'), - new OneToManyAssociationField('postComments', CommentDefinition::class, 'post_id') + new OneToManyAssociationField('postComments', CommentDefinition::class, 'post_id'), + (new TranslationsAssociationField(PostTranslationDefinition::class, 'magefanblog_post_id'))->addFlags(new ApiAware(), new Required()) ]); } } diff --git a/src/Core/Content/Blog/Post/PostEntity.php b/src/Core/Content/Blog/Post/PostEntity.php index d7b5f09..128ec6a 100644 --- a/src/Core/Content/Blog/Post/PostEntity.php +++ b/src/Core/Content/Blog/Post/PostEntity.php @@ -375,7 +375,12 @@ public function setOgType($ogType) */ public function getContentHeading(): ?string { - return $this->contentHeading; + $desc = $this->contentHeading; + if (!$desc) { + $desc = $this->content; + } + + return $desc; } /** diff --git a/src/Core/Content/Blog/Post/PostTranslation/PostTranslationCollection.php b/src/Core/Content/Blog/Post/PostTranslation/PostTranslationCollection.php new file mode 100644 index 0000000..9750b5c --- /dev/null +++ b/src/Core/Content/Blog/Post/PostTranslation/PostTranslationCollection.php @@ -0,0 +1,31 @@ +addFlags(new ApiAware(), new Required()), + + (new StringField('title', 'title'))->addFlags(new ApiAware(), new Required()), + (new StringField('meta_title', 'metaTitle'))->addFlags(new ApiAware()), + (new StringField('meta_keywords', 'metaKeywords'))->addFlags(new ApiAware()), + (new StringField('meta_description', 'metaDescription'))->addFlags(new ApiAware()), + (new LongTextField('content_heading', 'contentHeading'))->addFlags(new ApiAware(), new AllowHtml()), + (new LongTextField('content', 'content'))->addFlags(new ApiAware(), new AllowHtml()), + (new StringField('featured_img', 'featuredImg'))->addFlags(new ApiAware()), + (new StringField('featured_img_alt', 'featuredImgAlt'))->addFlags(new ApiAware()), + (new StringField('og_title', 'ogTitle'))->addFlags(new ApiAware()), + (new StringField('og_description', 'ogDescription'))->addFlags(new ApiAware()), + (new StringField('og_img', 'ogImg'))->addFlags(new ApiAware()), + (new StringField('og_type', 'ogType'))->addFlags(new ApiAware()), + (new StringField('identifier', 'identifier'))->addFlags(new Required()), + (new StringField('created_at', 'createdAt'))->addFlags(new ApiAware()), + (new StringField('updated_at', 'updatedAt'))->addFlags(new ApiAware()), + ]); + } +} diff --git a/src/Core/Content/Blog/Post/PostTranslation/PostTranslationEntity.php b/src/Core/Content/Blog/Post/PostTranslation/PostTranslationEntity.php new file mode 100644 index 0000000..21ce555 --- /dev/null +++ b/src/Core/Content/Blog/Post/PostTranslation/PostTranslationEntity.php @@ -0,0 +1,440 @@ +title; + } + + /** + * @param $title + * @return void + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string|null + */ + public function getMetaTitle(): ?string + { + return $this->metaTitle; + } + + /** + * @param $metaTitle + * @return void + */ + public function setMetaTitle($metaTitle) + { + $this->metaTitle = $metaTitle; + } + + /** + * @return string|null + */ + public function getMetaKeywords(): ?string + { + return $this->metaKeywords; + } + + /** + * @param $metaKeywords + * @return void + */ + public function setMetaKeywords($metaKeywords) + { + $this->metaKeywords = $metaKeywords; + } + + /** + * @return string|null + */ + public function getMetaDescription(): ?string + { + $desc = $this->metaDescription; + if (!$desc) { + $desc = $this->getContentHeading() ?: ''; + $desc = str_replace(['

', '

'], [' ', ''], $desc); + } + + $desc = strip_tags($desc); + if (mb_strlen($desc) > 200) { + $desc = mb_substr($desc, 0, 200); + } + + return trim($desc); + } + + /** + * @param $metaDescription + * @return void + */ + public function setMetaDescription($metaDescription) + { + $this->metaDescription = $metaDescription; + } + + /** + * @return string|null + */ + public function getIdentifier(): ?string + { + return $this->identifier; + } + + /** + * @param $identifier + * @return void + */ + public function setIdentifier($identifier) + { + $this->identifier = $identifier; + } + + /** + * @return string|null + */ + public function getOgTitle(): ?string + { + $title = $this->ogTitle; + if (!$title) { + $title = $this->getMetaTitle(); + } + + return $title ? trim($title) : ''; + } + + /** + * @param $ogTitle + * @return void + */ + public function setOgTitle($ogTitle) + { + $this->ogTitle = $ogTitle; + } + + /** + * @return string|null + */ + public function getOgDescription(): ?string + { + $desc = $this->ogDescription; + if (!$desc) { + $desc = $this->getMetaDescription(); + } else { + $desc = strip_tags($desc); + if (mb_strlen($desc) > 300) { + $desc = mb_substr($desc, 0, 300); + } + } + + return trim(html_entity_decode($desc)); + } + + /** + * @param $ogDescription + * @return void + */ + public function setOgDescription($ogDescription) + { + $this->ogDescription = $ogDescription; + } + + /** + * @return string|null + */ + public function getOgImg(): ?string + { + $img = $this->ogImg; + if (!$img) { + $img = $this->getFeaturedImg(); + } + + return $img; + } + + /** + * @param $ogImg + * @return void + */ + public function setOgImg($ogImg) + { + $this->ogImg = $ogImg; + } + + /** + * @return string|null + */ + public function getOgType(): ?string + { + $type = $this->ogType; + if (!$type) { + $type = 'article'; + } + + return trim($type); + } + + /** + * @param $ogType + * @return void + */ + public function setOgType($ogType) + { + $this->ogType = $ogType; + } + + /** + * @return string|null + */ + public function getContentHeading(): ?string + { + return $this->contentHeading; + } + + /** + * @param $contentHeading + * @return void + */ + public function setContentHeading($contentHeading) + { + $this->contentHeading = $contentHeading; + } + + /** + * @return string|null + */ + public function getContent(): ?string + { + return $this->content; + } + + /** + * @param $content + * @return void + */ + public function setContent($content) + { + $this->content = $content; + } + + /** + * @return string|null + */ + public function getFeaturedImg(): ?string + { + return $this->featuredImg; + } + + /** + * @param $featuredImg + * @return void + */ + public function setFeaturedImg($featuredImg) + { + $this->featuredImg = $featuredImg; + } + + /** + * @return string|null + */ + public function getFeaturedImgAlt(): ?string + { + return $this->featuredImgAlt; + } + + /** + * @param $featuredImgAlt + * @return void + */ + public function setFeaturedImgAlt($featuredImgAlt) + { + $this->featuredImgAlt = $featuredImgAlt; + } +} diff --git a/src/Core/Content/Blog/Sitemap/Provider/BlogUrlProvider.php b/src/Core/Content/Blog/Sitemap/Provider/BlogUrlProvider.php index a8b9cff..f3d01ea 100644 --- a/src/Core/Content/Blog/Sitemap/Provider/BlogUrlProvider.php +++ b/src/Core/Content/Blog/Sitemap/Provider/BlogUrlProvider.php @@ -169,7 +169,7 @@ protected function getBlogCategories($limit, $offset, $context) $blogCategoryUrl->setIdentifier($blogCategoryEntity->getId()); $blogCategoryUrl->setLoc( $this->router->generate('frontend.blog.category', - ['identifier' => $blogCategoryEntity->getIdentifier()], + ['id' => $blogCategoryEntity->getId()], UrlGeneratorInterface::ABSOLUTE_PATH) ); diff --git a/src/Core/Content/Blog/Tag/TagDefinition.php b/src/Core/Content/Blog/Tag/TagDefinition.php index fd1f5f7..cb1272d 100644 --- a/src/Core/Content/Blog/Tag/TagDefinition.php +++ b/src/Core/Content/Blog/Tag/TagDefinition.php @@ -10,11 +10,16 @@ use Magefan\Blog\Core\Content\Blog\Post\PostDefinition; use Magefan\Blog\Core\Content\Blog\PostTag\PostTagDefinition; +use Magefan\Blog\Core\Content\Blog\Tag\TagTranslation\TagTranslationDefinition; use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition; use Shopware\Core\Framework\DataAbstractionLayer\Field\DateField; +use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware; +use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Inherited; use Shopware\Core\Framework\DataAbstractionLayer\Field\IntField; use Shopware\Core\Framework\DataAbstractionLayer\Field\LongTextField; use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyAssociationField; +use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslatedField; +use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslationsAssociationField; use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection; use Shopware\Core\Framework\DataAbstractionLayer\Field\BoolField; use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey; @@ -57,16 +62,18 @@ protected function defineFields(): FieldCollection { return new FieldCollection([ (new IdField('id', 'id'))->addFlags(new Required(), new PrimaryKey()), - (new StringField('title', 'title'))->addFlags(new Required()), - (new StringField('meta_robots', 'metaRobots')), - (new StringField('meta_description', 'metaDescription')), - (new StringField('meta_keywords', 'metaKeywords')), - (new StringField('meta_title', 'metaTitle')), - (new LongTextField('content', 'content')), - (new StringField('identifier', 'identifier')), + + //translations + (new TranslatedField('title'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('metaRobots'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('metaDescription'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('metaKeywords'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('metaTitle'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('content'))->addFlags(new ApiAware(), new Inherited()), + (new TranslatedField('identifier'))->addFlags(new ApiAware(), new Inherited()), + (new StringField('page_layout', 'pageLayout')), (new BoolField('is_active', 'isActive')), - (new StringField('content', 'content')), (new StringField('layout_update_xml', 'layoutUpdateXml')), (new StringField('custom_theme', 'customTheme')), (new StringField('custom_layout', 'customLayout')), @@ -77,6 +84,8 @@ protected function defineFields(): FieldCollection (new StringField('posts_list_template', 'postsListTemplate')), (new DateField('created_at', 'createdAt')), (new DateField('updated_at', 'updatedAt')), + + // associations new ManyToManyAssociationField( 'postTags', PostDefinition::class, @@ -84,6 +93,10 @@ protected function defineFields(): FieldCollection 'tag_id', 'post_id' ), + (new TranslationsAssociationField( + TagTranslationDefinition::class, + 'magefanblog_tag_id') + )->addFlags(new ApiAware(), new Required()) ]); } } diff --git a/src/Core/Content/Blog/Tag/TagTranslation/TagTranslationCollection.php b/src/Core/Content/Blog/Tag/TagTranslation/TagTranslationCollection.php new file mode 100644 index 0000000..00779f0 --- /dev/null +++ b/src/Core/Content/Blog/Tag/TagTranslation/TagTranslationCollection.php @@ -0,0 +1,31 @@ +addFlags(new ApiAware(), new Required()), + (new StringField('title', 'title'))->addFlags(new Required()), + (new StringField('meta_robots', 'metaRobots')), + (new StringField('meta_description', 'metaDescription')), + (new StringField('meta_keywords', 'metaKeywords')), + (new StringField('meta_title', 'metaTitle')), + (new LongTextField('content', 'content')), + (new StringField('identifier', 'identifier')), + (new StringField('created_at', 'createdAt')), + (new StringField('updated_at', 'updatedAt')), + ]); + } +} diff --git a/src/Core/Content/Blog/Tag/TagTranslation/TagTranslationEntity.php b/src/Core/Content/Blog/Tag/TagTranslation/TagTranslationEntity.php new file mode 100644 index 0000000..1d8e275 --- /dev/null +++ b/src/Core/Content/Blog/Tag/TagTranslation/TagTranslationEntity.php @@ -0,0 +1,19 @@ +executeStatement('SET FOREIGN_KEY_CHECKS=0;'); $connection->executeStatement('DROP TABLE IF EXISTS `magefanblog_author`'); $connection->executeStatement('DROP TABLE IF EXISTS `magefanblog_category`'); + $connection->executeStatement('DROP TABLE IF EXISTS `magefanblog_category_translation`'); $connection->executeStatement('DROP TABLE IF EXISTS `magefanblog_comment`'); $connection->executeStatement('DROP TABLE IF EXISTS `magefanblog_post`'); + $connection->executeStatement('DROP TABLE IF EXISTS `magefanblog_post_translation`'); $connection->executeStatement('DROP TABLE IF EXISTS `magefanblog_post_category`'); $connection->executeStatement('DROP TABLE IF EXISTS `magefanblog_post_tag`'); $connection->executeStatement('DROP TABLE IF EXISTS `magefanblog_tag`'); + $connection->executeStatement('DROP TABLE IF EXISTS `magefanblog_tag_translation`'); + $connection->executeStatement("DELETE FROM seo_url_template WHERE entity_name LIKE 'magefanblog_%';"); + $connection->executeStatement("DELETE FROM seo_url WHERE route_name LIKE 'frontend.blog%';"); $connection->executeStatement('SET FOREIGN_KEY_CHECKS=1;'); } @@ -102,10 +107,12 @@ public function activate(ActivateContext $activateContext): void 'SELECT HEX(id),`include_in_menu`,`is_active` FROM `magefanblog_category` WHERE id = :id', ['id' => Uuid::fromHexToBytes($blogCategory->getId())] )->fetchAll(); - $categoryRepository->update( - [['id' => $blogCategory->getId(), 'active' => (bool)($status[0]['include_in_menu'] && $status[0]['is_active'])]] - , $context - ); + if (isset($status[0])) { + $categoryRepository->update( + [['id' => $blogCategory->getId(), 'active' => (bool)($status[0]['include_in_menu'] && $status[0]['is_active'])]] + , $context + ); + } } } } diff --git a/src/Migration/Migration1663319539CreateBlogPostTable.php b/src/Migration/Migration1663319539CreateBlogPostTable.php index f4c7cbc..140e16a 100644 --- a/src/Migration/Migration1663319539CreateBlogPostTable.php +++ b/src/Migration/Migration1663319539CreateBlogPostTable.php @@ -35,22 +35,9 @@ public function update(Connection $connection): void ' CREATE TABLE `magefanblog_post` ( `id` binary(16) NOT NULL COMMENT "Post ID", - `title` varchar(255) NOT NULL COMMENT "Post Title", - `meta_title` varchar(255) DEFAULT NULL COMMENT "Post Meta Title", - `meta_keywords` text COMMENT "Post Meta Keywords", - `meta_description` text COMMENT "Post Meta Description", - `identifier` varchar(100) DEFAULT NULL COMMENT "Post String Identifier", - `og_title` varchar(255) DEFAULT NULL COMMENT "Post OG Title", - `og_description` varchar(255) DEFAULT NULL COMMENT "Post OG Description", - `og_img` binary(16) DEFAULT NULL COMMENT "Post OG Img", - `og_type` varchar(255) DEFAULT NULL COMMENT "Post OG Type", - `content_heading` mediumtext DEFAULT NULL COMMENT "Post Content Heading", - `content` mediumtext COMMENT "Post Content", `publish_time` DATETIME(3) NULL DEFAULT NULL COMMENT "Post Publish Time", `is_active` smallint NOT NULL DEFAULT 1 COMMENT "Is Post Active", `position` smallint NOT NULL DEFAULT 0 COMMENT "Position", - `featured_img` varchar(255) DEFAULT NULL COMMENT "Thumbnail Image", - `featured_img_alt` varchar(255) DEFAULT NULL COMMENT "Featured Image Alt", `author_id` binary(16) DEFAULT NULL COMMENT "Author ID", `page_layout` varchar(255) DEFAULT NULL COMMENT "Post Layout", `layout_update_xml` text COMMENT "Post Layout Update Content", @@ -64,65 +51,110 @@ public function update(Connection $connection): void `secret` varchar(32) DEFAULT NULL COMMENT "Post Secret", `views_count` int DEFAULT NULL COMMENT "Post Views Count", `is_recent_posts_skip` smallint DEFAULT NULL COMMENT "Is Post Skipped From Recent Posts", - `short_content` mediumtext COMMENT "Post Short Content", `comments_count` int DEFAULT NULL COMMENT "Post Comment Counts", `media_id` binary(16) DEFAULT NULL COMMENT "Media Id", `post_media_version_id` binary(16) DEFAULT NULL, `created_at` DATETIME(3) NOT NULL COMMENT "Post Comment Counts", - `updated_at` DATETIME(3) NULL COMMENT "Post Comment Counts", - PRIMARY KEY (`id`), - KEY `MAGEFANBLOG_POST_IDENTIFIER` (`identifier`), - KEY `MAGEFANBLOG_POST_AUTHOR_ID` (`author_id`), - KEY `MAGEFANBLOG_POST_VIEWS_COUNT` (`views_count`), - KEY `MAGEFANBLOG_POST_IS_RECENT_POSTS_SKIP` (`is_recent_posts_skip`), - FULLTEXT KEY `FTI_A31A6CE1BAE9596AD2A53A8D37C22351` (`title`,`meta_keywords`,`meta_description`,`identifier`,`content`) + `updated_at` DATETIME(3) NULL COMMENT "Post Comment Counts", + PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb3 COMMENT="Magefan Blog Post Table"; ' ); $connection->executeStatement( ' - INSERT INTO `magefanblog_post` ( - `id`, `title`, `meta_title`, + CREATE TABLE `magefanblog_post_translation` ( + `magefanblog_post_id` binary(16) NOT NULL COMMENT "Post ID", + `language_id` BINARY(16) NOT NULL, + `title` varchar(255) NOT NULL COMMENT "Post Title", + `identifier` varchar(100) DEFAULT NULL COMMENT "Post String Identifier", + `meta_title` varchar(255) DEFAULT NULL COMMENT "Post Meta Title", + `meta_keywords` text COMMENT "Post Meta Keywords", + `meta_description` text COMMENT "Post Meta Description", + `og_title` varchar(255) DEFAULT NULL COMMENT "Post OG Title", + `og_description` varchar(255) DEFAULT NULL COMMENT "Post OG Description", + `og_img` binary(16) DEFAULT NULL COMMENT "Post OG Img", + `og_type` varchar(255) DEFAULT NULL COMMENT "Post OG Type", + `content_heading` mediumtext DEFAULT NULL COMMENT "Post Content Heading", + `content` mediumtext COMMENT "Post Content", + `featured_img` varchar(255) DEFAULT NULL COMMENT "Thumbnail Image", + `featured_img_alt` varchar(255) DEFAULT NULL COMMENT "Featured Image Alt", + `short_content` mediumtext COMMENT "Post Short Content", + `created_at` DATETIME(3) NOT NULL COMMENT "Post Comment Counts", + `updated_at` DATETIME(3) NULL COMMENT "Post Comment Counts", + PRIMARY KEY (`magefanblog_post_id`, `language_id`), + KEY `MAGEFANBLOG_POST_IDENTIFIER` (`identifier`), + FULLTEXT KEY `FTI_A31A6CE1BAE9596AD2A53A8D37C22351` (`title`,`meta_keywords`,`meta_description`,`content`) + ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb3 COMMENT="Magefan Blog Post Table Translation"; + ' + ); + + $id = '265e0b57d2c54b49ba9e9e36ad4bc981'; + + $connection->executeStatement( + ' + INSERT INTO `magefanblog_post` ( + `id`, `created_at`, `updated_at`, `publish_time`, + `is_active`, `include_in_recent`, + `author_id`, `page_layout`, `layout_update_xml`, + `custom_theme`, `custom_layout`, + `custom_layout_update_xml`, `custom_theme_from`, + `custom_theme_to`, `media_gallery`, `secret`, + `views_count`, `is_recent_posts_skip`, `comments_count` + ) + VALUES + ( + :id, :createdAt, :updatedAt, + :publishTime, 1, 1, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, 0 + ); + ', + [ + 'id' => Uuid::fromHexToBytes($id), + 'publishTime' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT), + 'updatedAt' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT), + 'createdAt' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT) + ] + ); + + $languages = $connection->executeQuery('SELECT DISTINCT `language_id` FROM `sales_channel_language`')->fetchAll(); + + foreach ($languages as $language) { + + $connection->executeStatement( + ' + INSERT INTO `magefanblog_post_translation` ( + `magefanblog_post_id`, `language_id`, `title`,`identifier`, `meta_title`, `meta_keywords`, `meta_description`, - `identifier`, `og_title`, `og_description`, + `og_title`, `og_description`, `og_img`, `og_type`, `content_heading`, - `content`, `created_at`, `updated_at`, - `publish_time`, `is_active`, `include_in_recent`, - `position`, `featured_img`, `featured_img_alt`, - `author_id`, `page_layout`, `layout_update_xml`, - `custom_theme`, `custom_layout`, - `custom_layout_update_xml`, `custom_theme_from`, - `custom_theme_to`, `media_gallery`, - `secret`, `views_count`, `is_recent_posts_skip`, - `short_content`, `comments_count` + `content`,`featured_img`, `featured_img_alt`, + `short_content`, `created_at`, `updated_at` ) VALUES ( - :id, :title, - NULL, :metaKeywords, :metaDescription, - :identifier , NULL, + :id, :languageId, :title, :identifier, + NULL, :metaKeywords, :metaDescription, NULL, NULL, NULL, NULL, :contentHeading, - :content,:createdAt, :updatedAt, - :publishTime, 1, 1, 0, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, 0 + :content, 0, NULL, NULL, :createdAt, :updatedAt ); ', - [ - 'id' => Uuid::randomBytes(), - 'title' => 'Magefan Blog Post Sample', - 'identifier' => 'magefan-blog-post-sample', - 'metaKeywords' => 'Magefan blog sample', - 'metaDescription' => 'Magefan blog default post.', - 'contentHeading' => 'Magefan Blog Post Sample', - 'content' => '

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

', - 'publishTime' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT), - 'updatedAt' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT), - 'createdAt' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT) + [ + 'id' => Uuid::fromHexToBytes($id), + 'languageId' => $language['language_id'], + 'title' => 'Magefan Blog Post Sample', + 'identifier' => 'magefan-blog-post-sample', + 'metaKeywords' => 'Magefan blog sample', + 'metaDescription' => 'Magefan blog default post.', + 'contentHeading' => 'Magefan Blog Post Sample', + 'content' => '

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

', + 'updatedAt' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT), + 'createdAt' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT) ] - ); + ); + } } /** diff --git a/src/Migration/Migration1663321276CreateBlogPostToCategoryLinkTable.php b/src/Migration/Migration1663321276CreateBlogPostToCategoryLinkTable.php index 68d4eda..85c5094 100644 --- a/src/Migration/Migration1663321276CreateBlogPostToCategoryLinkTable.php +++ b/src/Migration/Migration1663321276CreateBlogPostToCategoryLinkTable.php @@ -35,12 +35,10 @@ public function update(Connection $connection): void `id` binary(16) NOT NULL COMMENT "Depend ID", `post_id` binary(16) NOT NULL COMMENT "Post ID", `category_id` binary(16) NOT NULL COMMENT "Category ID", + `created_at` DATETIME(3) NOT NULL COMMENT "Depend Created At", + `updated_at` DATETIME(3) NULL COMMENT "Depend Updated At", PRIMARY KEY (`id`, `post_id`,`category_id`), - `created_at` DATETIME(3) NOT NULL, - `updated_at` DATETIME(3) NULL, - KEY `MAGEFAN_BLOG_POST_CATEGORY_CATEGORY_ID` (`category_id`), - CONSTRAINT `MAGEFAN_BLOG_POST_CATEGORY_POST_ID_MAGEFAN_BLOG_POST_POST_ID` FOREIGN KEY (`post_id`) REFERENCES `magefanblog_post` (`id`) ON DELETE CASCADE, - CONSTRAINT `MAGEFAN_BLOG_POST_CTGR_CTGR_ID_MAGEFAN_BLOG_CTGR_CTGR_ID` FOREIGN KEY (`category_id`) REFERENCES `magefanblog_category` (`id`) ON DELETE CASCADE + KEY `MAGEFAN_BLOG_POST_CATEGORY_CATEGORY_ID` (`category_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT="Magefan Blog Post To Category Linkage Table" ' ); diff --git a/src/Migration/Migration1663321745CreateBlogCategoryTable.php b/src/Migration/Migration1663321745CreateBlogCategoryTable.php index 06197d4..f1cff2f 100644 --- a/src/Migration/Migration1663321745CreateBlogCategoryTable.php +++ b/src/Migration/Migration1663321745CreateBlogCategoryTable.php @@ -33,37 +33,50 @@ public function update(Connection $connection): void ' CREATE TABLE `magefanblog_category` ( `id` binary(16) NOT NULL COMMENT "Category ID", - `title` varchar(255) DEFAULT NULL COMMENT "Category Title", - `meta_title` varchar(255) DEFAULT NULL COMMENT "Category Meta Title", - `meta_keywords` text COMMENT "Category Meta Keywords", - `meta_description` text COMMENT "Category Meta Description", - `identifier` varchar(100) DEFAULT NULL COMMENT "Category String Identifier", - `content_heading` mediumtext DEFAULT NULL COMMENT "Category Content Heading", - `content` mediumtext COMMENT "Category Content", - `path` varchar(255) DEFAULT NULL COMMENT "Category Path", `position` smallint DEFAULT 10 COMMENT "Category Position", - `posts_sort_by` varchar(15) DEFAULT "createdAt" NOT NULL COMMENT "Post Sort By", + `posts_sort_by` varchar(15) DEFAULT "createdAt" NOT NULL COMMENT "Category Sort By", `include_in_menu` smallint DEFAULT NULL COMMENT "Category In Menu", `is_active` smallint NOT NULL DEFAULT 1 COMMENT "Is Category Active", `display_mode` smallint NOT NULL DEFAULT 0 COMMENT "Display Mode", - `page_layout` varchar(255) DEFAULT NULL COMMENT "Post Layout", - `layout_update_xml` text COMMENT "Post Layout Update Content", - `custom_theme` varchar(100) DEFAULT NULL COMMENT "Post Custom Theme", - `custom_layout` varchar(255) DEFAULT NULL COMMENT "Post Custom Template", - `custom_layout_update_xml` text COMMENT "Post Custom Layout Update Content", - `custom_theme_from` date DEFAULT NULL COMMENT "Post Custom Theme Active From Date", - `custom_theme_to` date DEFAULT NULL COMMENT "Post Custom Theme Active To Date", + `page_layout` varchar(255) DEFAULT NULL COMMENT "Category Layout", + `layout_update_xml` text COMMENT "Category Layout Update Content", + `custom_theme` varchar(100) DEFAULT NULL COMMENT "Category Custom Theme", + `custom_layout` varchar(255) DEFAULT NULL COMMENT "Category Custom Template", + `custom_layout_update_xml` text COMMENT "Category Custom Layout Update Content", + `custom_theme_from` date DEFAULT NULL COMMENT "Category Custom Theme Active From Date", + `custom_theme_to` date DEFAULT NULL COMMENT "Category Custom Theme Active To Date", `posts_per_page` int DEFAULT NULL COMMENT "Posts Per Page", `posts_list_template` varchar(100) DEFAULT NULL COMMENT "Posts List Template", `created_at` DATETIME(3) NOT NULL, `updated_at` DATETIME(3) NULL, PRIMARY KEY (`id`), - KEY `MYM2MAGEFAN_BLOG_CATEGORY_IDENTIFIER` (`identifier`), - KEY `MYM2MAGEFAN_BLOG_CATEGORY_INCLUDE_IN_MENU` (`include_in_menu`), - FULLTEXT KEY `FTI_C41E1A43EC863C41B00FA78BD3B8E0EC` (`title`,`meta_keywords`,`meta_description`,`identifier`,`content`) + KEY `MYM2MAGEFAN_BLOG_CATEGORY_INCLUDE_IN_MENU` (`include_in_menu`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT="Magefan Blog Category Table" ' ); + + $connection->executeStatement( + ' + CREATE TABLE `magefanblog_category_translation` ( + `magefanblog_category_id` binary(16) NOT NULL COMMENT "Category ID", + `language_id` BINARY(16) NOT NULL COMMENT "Language Id", + `title` varchar(255) DEFAULT NULL COMMENT "Category Title", + `identifier` varchar(100) DEFAULT NULL COMMENT "Category String Identifier", + `meta_title` varchar(255) DEFAULT NULL COMMENT "Category Meta Title", + `meta_keywords` text COMMENT "Category Meta Keywords", + `meta_description` text COMMENT "Category Meta Description", + `content_heading` mediumtext DEFAULT NULL COMMENT "Category Content Heading", + `content` mediumtext COMMENT "Category Content", + `path` varchar(255) DEFAULT NULL COMMENT "Category Path", + `created_at` DATETIME(3) NOT NULL COMMENT "Category Translation Created At", + `updated_at` DATETIME(3) NULL COMMENT "Category Translation Updated At", + PRIMARY KEY (`magefanblog_category_id`, `language_id`), + KEY `MAGEFANBLOG_POST_IDENTIFIER` (`identifier`), + FULLTEXT KEY `FTI_A31A6CE1BAE9596AD2A53A8D37C22351` (`title`,`meta_keywords`,`meta_description`,`content`) + ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb3 COMMENT="Magefan Blog Category Table Translation"; + ' + ); + } /** diff --git a/src/Migration/Migration1663570403CreateBlogPostCommentTable.php b/src/Migration/Migration1663570403CreateBlogPostCommentTable.php index 460d958..1132030 100644 --- a/src/Migration/Migration1663570403CreateBlogPostCommentTable.php +++ b/src/Migration/Migration1663570403CreateBlogPostCommentTable.php @@ -49,8 +49,7 @@ public function update(Connection $connection): void KEY `MAGEFAN_BLOG_COMMENT_POST_ID` (`id`), KEY `MAGEFAN_BLOG_COMMENT_CUSTOMER_ID` (`customer_id`), KEY `MAGEFAN_BLOG_COMMENT_ADMIN_ID` (`admin_id`), - KEY `MAGEFAN_BLOG_COMMENT_STATUS` (`status`), - CONSTRAINT `MAGEFANBLOG_COMMENT_POST_ID_MAGEFAN_BLOG_POST_POST_ID` FOREIGN KEY (`post_id`) REFERENCES `magefanblog_post` (`id`) ON DELETE CASCADE + KEY `MAGEFAN_BLOG_COMMENT_STATUS` (`status`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT="magefanblog_comment" ' ); diff --git a/src/Migration/Migration1663655011CreateBlogTagTable.php b/src/Migration/Migration1663655011CreateBlogTagTable.php index ebf79b7..1949d4d 100644 --- a/src/Migration/Migration1663655011CreateBlogTagTable.php +++ b/src/Migration/Migration1663655011CreateBlogTagTable.php @@ -33,15 +33,8 @@ public function update(Connection $connection): void ' CREATE TABLE `magefanblog_tag` ( `id` binary(16) NOT NULL COMMENT "Tag ID", - `title` varchar(255) NOT NULL COMMENT "Tag Title", - `meta_robots` varchar(255) DEFAULT NULL COMMENT "Tag Default Robots", - `meta_description` varchar(255) DEFAULT NULL COMMENT "Tag Meta Description", - `meta_keywords` varchar(255) DEFAULT NULL COMMENT "Tag Meta Keywords", - `meta_title` varchar(255) DEFAULT NULL COMMENT "Tag Meta Title", - `identifier` varchar(100) DEFAULT NULL COMMENT "Tag String Identifier", `page_layout` varchar(255) DEFAULT NULL COMMENT "Tag Layout", `is_active` smallint NOT NULL DEFAULT 1 COMMENT "Is Tag Active", - `content` mediumtext COMMENT "Tag Content", `layout_update_xml` text COMMENT "Tag Layout Update Content", `custom_theme` varchar(100) DEFAULT NULL COMMENT "Tag Custom Theme", `custom_layout` varchar(255) DEFAULT NULL COMMENT "Tag Custom Template", @@ -50,14 +43,33 @@ public function update(Connection $connection): void `custom_theme_to` date DEFAULT NULL COMMENT "Tag Custom Theme Active To Date", `posts_per_page` int DEFAULT NULL COMMENT "Posts Per Page", `posts_list_template` varchar(100) DEFAULT NULL COMMENT "Posts List Template", - `created_at` DATETIME(3) NOT NULL, - `updated_at` DATETIME(3) NULL, + `created_at` DATETIME(3) NOT NULL COMMENT "Tag Created At", + `updated_at` DATETIME(3) NULL COMMENT "Tag Update At", PRIMARY KEY (`id`), - KEY `MAGEFANBLOG_TAG_IDENTIFIER` (`identifier`), KEY `MAGEFANBLOG_TAG_active` (`is_active`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT="Magefan Blog Tag Table" ' ); + + $connection->executeStatement( + ' + CREATE TABLE `magefanblog_tag_translation` ( + `magefanblog_tag_id` binary(16) NOT NULL COMMENT "Tag ID", + `language_id` BINARY(16) NOT NULL, + `title` varchar(255) NOT NULL COMMENT "Tag Title", + `identifier` varchar(100) DEFAULT NULL COMMENT "Tag String Identifier", + `meta_robots` varchar(255) DEFAULT NULL COMMENT "Tag Default Robots", + `meta_description` varchar(255) DEFAULT NULL COMMENT "Tag Meta Description", + `meta_keywords` varchar(255) DEFAULT NULL COMMENT "Tag Meta Keywords", + `meta_title` varchar(255) DEFAULT NULL COMMENT "Tag Meta Title", + `content` mediumtext COMMENT "Tag Content", + `created_at` DATETIME(3) NOT NULL COMMENT "Tag Translation Created At", + `updated_at` DATETIME(3) NULL COMMENT "Tag Translation Update At", + PRIMARY KEY (`magefanblog_tag_id`, `language_id`), + KEY `MAGEFANBLOG_POST_IDENTIFIER` (`identifier`) + ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb3 COMMENT="Magefan Blog Tag Table Translation"; + ' + ); } /** diff --git a/src/Migration/Migration1663658563CreateBlogPostTagTable.php b/src/Migration/Migration1663658563CreateBlogPostTagTable.php index cba058c..4f17011 100644 --- a/src/Migration/Migration1663658563CreateBlogPostTagTable.php +++ b/src/Migration/Migration1663658563CreateBlogPostTagTable.php @@ -35,12 +35,10 @@ public function update(Connection $connection): void `id` binary(16) NOT NULL COMMENT "Depend ID", `post_id` binary(16) NOT NULL COMMENT "Post ID", `tag_id` binary(16) NOT NULL COMMENT "Tag ID", - `created_at` DATETIME(3) NOT NULL, - `updated_at` DATETIME(3) NULL, + `created_at` DATETIME(3) NOT NULL COMMENT "Depend Created At", + `updated_at` DATETIME(3) NULL COMMENT "Depend Updated At", PRIMARY KEY (`id`), - KEY `MAGEFANBLOG_POST_TAG_TAG_ID` (`tag_id`), - CONSTRAINT `MAGEFANBLOG_POST_TAG_POST_ID_MAGEFAN_BLOG_POST_POST_ID` FOREIGN KEY (`post_id`) REFERENCES `magefanblog_post` (`id`) ON DELETE CASCADE, - CONSTRAINT `MAGEFANBLOG_POST_TAG_TAG_ID_MAGEFAN_BLOG_TAG_TAG_ID` FOREIGN KEY (`tag_id`) REFERENCES `magefanblog_tag` (`id`) ON DELETE CASCADE + KEY `MAGEFANBLOG_POST_TAG_TAG_ID` (`tag_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT="Magefan Blog Post To Category Linkage Table" ' ); diff --git a/src/Migration/Migration1663741704CreateBlogAuthorTable.php b/src/Migration/Migration1663741704CreateBlogAuthorTable.php index 9b6afc6..9a82b2e 100644 --- a/src/Migration/Migration1663741704CreateBlogAuthorTable.php +++ b/src/Migration/Migration1663741704CreateBlogAuthorTable.php @@ -33,12 +33,8 @@ public function update(Connection $connection): void ' CREATE TABLE `magefanblog_author` ( `id` binary(16) NOT NULL COMMENT "Author ID", - `is_active` smallint NOT NULL DEFAULT 1 COMMENT "Is Author Active", `firstname` varchar(255) DEFAULT NULL COMMENT "Author FirstName", `lastname` varchar(255) DEFAULT NULL COMMENT "Author LastName", - `admin_user_id` binary(16) NOT NULL COMMENT "Admin user ID", - `email` varchar(255) DEFAULT NULL COMMENT "Author Email", - `role` varchar(255) DEFAULT NULL COMMENT "Author role (developer)", `facebook_page_url` varchar(255) DEFAULT NULL COMMENT "Author in Facebook", `twitter_page_url` varchar(255) DEFAULT NULL COMMENT "Author in Twitter", `instagram_page_url` varchar(255) DEFAULT NULL COMMENT "Author in Instagram", @@ -52,6 +48,10 @@ public function update(Connection $connection): void `content` mediumtext COMMENT "Author Content", `short_content` mediumtext COMMENT "Author Short Content", `featured_img` varchar(255) DEFAULT NULL COMMENT "Author Image", + `is_active` smallint NOT NULL DEFAULT 1 COMMENT "Is Author Active", + `admin_user_id` binary(16) NOT NULL COMMENT "Admin user ID", + `email` varchar(255) DEFAULT NULL COMMENT "Author Email", + `role` varchar(255) DEFAULT NULL COMMENT "Author role (developer)", `page_layout` varchar(255) DEFAULT NULL COMMENT "Author Layout", `layout_update_xml` text COMMENT "Author Layout Update Content", `custom_theme` varchar(100) DEFAULT NULL COMMENT "Author Custom Thema", diff --git a/src/Migration/Migration1677140148StaticSeoUrl.php b/src/Migration/Migration1677140148StaticSeoUrl.php new file mode 100644 index 0000000..466711a --- /dev/null +++ b/src/Migration/Migration1677140148StaticSeoUrl.php @@ -0,0 +1,95 @@ +getLanguages($connection) as $language) { + + $translationUrl[] = + [ + 'id' => Uuid::randomBytes(), + 'sales_channel_id' => $this->getSalesChannelId($connection), + 'foreign_key' => Uuid::fromHexToBytes($id), + 'route_name' => 'frontend.blog.post', + 'path_info' => '/blog/post/265e0b57d2c54b49ba9e9e36ad4bc981', + 'is_canonical' => 1, + 'is_modified' => 0, + 'is_deleted' => 0, + 'seo_path_info' => 'blog/post/magefan-blog-post-sample' + ]; + } + $this->importTranslation('seo_url', new Translations( + $translationUrl[1] ?? $translationUrl[0], + $translationUrl[0] + ), + $connection); + } + + /** + * @param Connection $connection + * @return void + */ + public function updateDestructive(Connection $connection): void + { + } + + /** + * @param $connection + * @return mixed + */ + private function getLanguages($connection) + { + return $connection->executeQuery('SELECT DISTINCT `language_id` FROM `sales_channel_language`')->fetchAll(); + } + + /** + * @param Connection $connection + * @return string|null + * @throws Exception + */ + private function getSalesChannelId(Connection $connection): ?string + { + $sql = <<fetchOne($sql, [ + 'typeId' => Uuid::fromHexToBytes(Defaults::SALES_CHANNEL_TYPE_STOREFRONT) + ]); + + if (!$salesChannelId) { + return null; + } + + return $salesChannelId; + } +} diff --git a/src/Migration/Migration1677140955AddBlogSeoUrlTemplate.php b/src/Migration/Migration1677140955AddBlogSeoUrlTemplate.php new file mode 100644 index 0000000..9d9253e --- /dev/null +++ b/src/Migration/Migration1677140955AddBlogSeoUrlTemplate.php @@ -0,0 +1,57 @@ + 'magefanblog_post', + 'Category' => 'magefanblog_category', + 'Tag' => 'magefanblog_tag' + ]; + + /** + * @return int + */ + public function getCreationTimestamp(): int + { + return 1677140955; + } + + /** + * @param Connection $connection + * @return void + * @throws Exception + */ + public function update(Connection $connection): void + { + foreach (self::TEMPLATES_DETAIL as $name => $entityDetail) { + $className = '\Magefan\Blog\Storefront\Framework\Seo\SeoUrlRoute\Blog' . $name . 'PageSeoUrlRoute'; + if ($entityDetail) { + $connection->insert('seo_url_template', [ + 'id' => Uuid::randomBytes(), + 'sales_channel_id' => null, + 'route_name' => $className::ROUTE_NAME, + 'entity_name' => $entityDetail, + 'template' => $className::DEFAULT_TEMPLATE, + 'created_at' => (new \DateTimeImmutable())->format(Defaults::STORAGE_DATE_TIME_FORMAT), + ]); + } + } + } + + /** + * @param Connection $connection + * @return void + */ + public function updateDestructive(Connection $connection): void + { + // implement update destructive + } +} diff --git a/src/Resources/app/administration/src/module/blog-category/component/blog-category-clone-modal/index.js b/src/Resources/app/administration/src/module/blog-category/component/blog-category-clone-modal/index.js index bfa22db..c778913 100644 --- a/src/Resources/app/administration/src/module/blog-category/component/blog-category-clone-modal/index.js +++ b/src/Resources/app/administration/src/module/blog-category/component/blog-category-clone-modal/index.js @@ -71,7 +71,7 @@ Component.register('blog-category-clone-modal', { }, }; - await this.repository.save(this.product); + await this.repository.save(this.category, Context.api); const clone = await this.repository.clone(this.category.id, Shopware.Context.api, behavior); return {id: clone.id, productNumber: number.number}; diff --git a/src/Resources/app/administration/src/module/blog-category/component/blog-category-seo/blog-category-seo.html.twig b/src/Resources/app/administration/src/module/blog-category/component/blog-category-seo/blog-category-seo.html.twig index e52a528..475202c 100644 --- a/src/Resources/app/administration/src/module/blog-category/component/blog-category-seo/blog-category-seo.html.twig +++ b/src/Resources/app/administration/src/module/blog-category/component/blog-category-seo/blog-category-seo.html.twig @@ -17,7 +17,7 @@ type="text" :label="$tc('blog-category.detail.labelIdentifier')" :placeholder="$tc('blog-category.detail.placeholderUrlKey')" - :disabled="!allowEdit" + :disabled="true" /> {% endblock %} diff --git a/src/Resources/app/administration/src/module/blog-category/page/blog-category-detail/blog-category-detail.html.twig b/src/Resources/app/administration/src/module/blog-category/page/blog-category-detail/blog-category-detail.html.twig index dc028a6..d6bf73d 100644 --- a/src/Resources/app/administration/src/module/blog-category/page/blog-category-detail/blog-category-detail.html.twig +++ b/src/Resources/app/administration/src/module/blog-category/page/blog-category-detail/blog-category-detail.html.twig @@ -43,6 +43,21 @@ {% endblock %} + {% block blog_category_detail_language_switch %} + + {% endblock %} + + {% block blog_category_detail_language_info %} + + {% endblock %} + {% block blog_category_detail_content %} {% endblock %} + {% block blog_category_list_language_switch %} + + {% endblock %} + {% endblock %} + {% block blog_post_detail_language_switch %} + + {% endblock %} + + {% block blog_post_detail_language_info %} + + {% endblock %} + {% block blog_post_detail_content %} {% endblock %} + {% block blog_post_list_language_switch %} + + {% endblock %} + {% endblock %} + {% block blog_tag_detail_language_switch %} + + {% endblock %} + + {% block blog_tag_detail_language_info %} + + {% endblock %} + {% block blog_tag_detail_content %}