99namespace Magefan \Blog \Setup \Patch \Data ;
1010
1111use Magento \Framework \Setup \Patch \DataPatchInterface ;
12- use Magento \Framework \Setup \Patch \PatchVersionInterface ;
12+ use Magefan \Blog \Model \PostFactory ;
13+ use Magefan \Blog \Model \ResourceModel \Post \CollectionFactory as PostCollectionFactory ;
14+ use Magento \Framework \App \State ;
15+ use Magento \Framework \App \Config \ScopeConfigInterface ;
1316
14- class CreateSamplePost implements DataPatchInterface, PatchVersionInterface
17+ class CreateSamplePost implements DataPatchInterface
1518{
1619 /**
17- * Post factory
18- *
19- * @var \Magefan\Blog\Model\PostFactory
20+ * @var PostFactory
2021 */
2122 private $ _postFactory ;
2223
2324 /**
24- * State
25- *
26- * @var \Magento\Framework\App\State
25+ * @var PostCollectionFactory
26+ */
27+ private $ postCollection ;
28+
29+ /**
30+ * @var State
2731 */
2832 private $ state ;
2933
3034 /**
31- * @var \Magento\Framework\App\Config\ ScopeConfigInterface
35+ * @var ScopeConfigInterface
3236 */
3337 private $ scopeConfig ;
3438
35-
39+ /**
40+ * @param PostFactory $postFactory
41+ * @param PostCollectionFactory $postCollection
42+ * @param State $state
43+ * @param ScopeConfigInterface $scopeConfig
44+ */
3645 public function __construct (
37- \Magefan \Blog \Model \PostFactory $ postFactory ,
38- \Magento \Framework \App \State $ state ,
39- \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig
46+ PostFactory $ postFactory ,
47+ PostCollectionFactory $ postCollection ,
48+ State $ state ,
49+ ScopeConfigInterface $ scopeConfig
4050 ) {
4151 $ this ->_postFactory = $ postFactory ;
52+ $ this ->postCollection = $ postCollection ;
4253 $ this ->state = $ state ;
4354 $ this ->scopeConfig = $ scopeConfig ;
4455 }
@@ -51,58 +62,20 @@ public function apply()
5162 /* Do nothing, it's OK */
5263 }
5364
54- $ url = $ this ->scopeConfig
55- ->getValue (
56- 'web/unsecure/base_url ' ,
57- \Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
58- 0
59- );
60- $ useLinks = \Magefan \Community \Model \UrlChecker::showUrl ($ url );
61- $ useLinks = false ;
65+ if (!$ this ->postCollection ->create ()->getSize ()) {
6266
63- $ data = [
64- 'title ' => 'Magento 2 Blog Post Sample ' ,
65- 'meta_keywords ' => 'magento 2 blog sample ' ,
66- 'meta_description ' => 'Magento 2 blog default post. ' ,
67- 'identifier ' => 'magento-2-blog-post-sample ' ,
68- 'content_heading ' => 'Magento 2 Blog Post Sample ' ,
69- 'content ' =>
70- $ useLinks
71- ? '<p>Welcome to
72- <a title="Magento Blog"
73- href="https://magefan.com/magento2-blog-extension"
74- target="_blank">Magento Blog</a> by
75- <a title="Magento 2 Extensions"
76- href="https://magefan.com/magento-2-extensions"
77- target="_blank">Magefan</a>.
78- This is your first post. Edit or delete it, then start blogging!
79- </p>
80- <p><!-- pagebreak --></p>
81- <p>Please also read
82- <a title="Magento 2 Blog online documentation"
83- href="https://magefan.com/blog/magento-2-blog-extension-documentation"
84- target="_blank">Magento 2 Blog online documentation</a> and
85- <a href="https://magefan.com/blog/add-read-more-tag-to-blog-post-content"
86- target="_blank">How to add "read more" tag to post content</a>
87- </p>
88- <p>Follow Magefan on:</p>
89- <p>
90- <a title="Magento 2 Blog Extension GitHub"
91- href="https://github.com/magefan/module-blog"
92- target="_blank">Magento 2 Blog Extension GitHub</a> |
93- <a href="https://twitter.com/magento2fan" title="Magefan at Twitter"
94- target="_blank">Magefan at Twitter</a> |
95- <a href="https://www.facebook.com/magefan/" title="Magefan at Facebook"
96- target="_blank">Magefan at Facebook</a>
97- </p> '
98- : '<p>Welcome to Magento 2 Blog extension by Magefan.
99- This is your first post. Edit or delete it, then start blogging!
100- </p> ' ,
101- 'store_ids ' => [0 ]
102- ];
103-
104- $ this ->_postFactory ->create ()->setData ($ data )->save ();
67+ $ data = [
68+ 'title ' => 'Magento 2 Blog Post Sample ' ,
69+ 'meta_keywords ' => 'magento 2 blog sample ' ,
70+ 'meta_description ' => 'Magento 2 blog default post. ' ,
71+ 'identifier ' => 'magento-2-blog-post-sample ' ,
72+ 'content_heading ' => 'Magento 2 Blog Post Sample ' ,
73+ 'content ' => '<p>Welcome to Magento 2 Blog extension by Magefan. This is your first post. Edit or delete it, then start blogging!</p> ' ,
74+ 'store_ids ' => [0 ]
75+ ];
10576
77+ $ this ->_postFactory ->create ()->setData ($ data )->save ();
78+ }
10679 }
10780
10881 public static function getDependencies ()
@@ -114,9 +87,4 @@ public function getAliases()
11487 {
11588 return [];
11689 }
117-
118- public static function getVersion ()
119- {
120- return '2.12.3 ' ;
121- }
122- }
90+ }
0 commit comments