Skip to content

Commit d1d72f7

Browse files
committed
Added PatchVersionInterface to the setup/patch/data
1 parent d9b6435 commit d1d72f7

File tree

3 files changed

+55
-25
lines changed

3 files changed

+55
-25
lines changed

Setup/Patch/Data/CreateSamplePost.php

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,18 @@
99
namespace Magefan\Blog\Setup\Patch\Data;
1010

1111
use Magento\Framework\Setup\Patch\DataPatchInterface;
12+
use Magento\Framework\Setup\Patch\PatchVersionInterface;
1213
use Magefan\Blog\Model\PostFactory;
13-
use Magefan\Blog\Model\ResourceModel\Post\CollectionFactory as PostCollectionFactory;
1414
use Magento\Framework\App\State;
1515
use Magento\Framework\App\Config\ScopeConfigInterface;
1616

17-
class CreateSamplePost implements DataPatchInterface
17+
class CreateSamplePost implements DataPatchInterface, PatchVersionInterface
1818
{
1919
/**
2020
* @var PostFactory
2121
*/
2222
private $_postFactory;
2323

24-
/**
25-
* @var PostCollectionFactory
26-
*/
27-
private $postCollection;
28-
2924
/**
3025
* @var State
3126
*/
@@ -38,18 +33,15 @@ class CreateSamplePost implements DataPatchInterface
3833

3934
/**
4035
* @param PostFactory $postFactory
41-
* @param PostCollectionFactory $postCollection
4236
* @param State $state
4337
* @param ScopeConfigInterface $scopeConfig
4438
*/
4539
public function __construct(
4640
PostFactory $postFactory,
47-
PostCollectionFactory $postCollection,
4841
State $state,
4942
ScopeConfigInterface $scopeConfig
5043
) {
5144
$this->_postFactory = $postFactory;
52-
$this->postCollection = $postCollection;
5345
$this->state = $state;
5446
$this->scopeConfig = $scopeConfig;
5547
}
@@ -62,20 +54,17 @@ public function apply()
6254
/* Do nothing, it's OK */
6355
}
6456

65-
if (!$this->postCollection->create()->getSize()) {
57+
$data = [
58+
'title' => 'Magento 2 Blog Post Sample',
59+
'meta_keywords' => 'magento 2 blog sample',
60+
'meta_description' => 'Magento 2 blog default post.',
61+
'identifier' => 'magento-2-blog-post-sample',
62+
'content_heading' => 'Magento 2 Blog Post Sample',
63+
'content' => '<p>Welcome to Magento 2 Blog extension by Magefan. This is your first post. Edit or delete it, then start blogging!</p>',
64+
'store_ids' => [0]
65+
];
6666

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-
];
76-
77-
$this->_postFactory->create()->setData($data)->save();
78-
}
67+
$this->_postFactory->create()->setData($data)->save();
7968
}
8069

8170
public static function getDependencies()
@@ -87,4 +76,12 @@ public function getAliases()
8776
{
8877
return[];
8978
}
79+
80+
/**
81+
* @return string
82+
*/
83+
public static function getVersion()
84+
{
85+
return '2.0.2';
86+
}
9087
}

Setup/Patch/Data/TagInStore.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
namespace Magefan\Blog\Setup\Patch\Data;
1010

1111
use Magento\Framework\Setup\Patch\DataPatchInterface;
12+
use Magento\Framework\Setup\Patch\PatchVersionInterface;
1213
use Magento\Framework\App\ResourceConnection;
1314

14-
class TagInStore implements DataPatchInterface
15+
class TagInStore implements DataPatchInterface, PatchVersionInterface
1516
{
1617
/**
1718
* @var ResourceConnection
@@ -27,16 +28,30 @@ public function __construct(
2728
$this->resourceConnection = $resourceConnection;
2829
}
2930

31+
/**
32+
* @return array|string[]
33+
*/
3034
public static function getDependencies()
3135
{
3236
return [];
3337
}
3438

39+
/**
40+
* @return array|string[]
41+
*/
3542
public function getAliases()
3643
{
3744
return [];
3845
}
3946

47+
/**
48+
* @return string
49+
*/
50+
public static function getVersion()
51+
{
52+
return '2.9.8';
53+
}
54+
4055
public function apply()
4156
{
4257
$connection = $this->resourceConnection->getConnection();

Setup/Patch/Data/UpdatePostCommentsCount.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010

1111
use Magento\Framework\Module\ModuleResource;
1212
use Magento\Framework\Setup\Patch\DataPatchInterface;
13+
use Magento\Framework\Setup\Patch\PatchVersionInterface;
1314
use Magefan\Blog\Model\ResourceModel\Comment;
1415

15-
class UpdatePostCommentsCount implements DataPatchInterface
16+
class UpdatePostCommentsCount implements DataPatchInterface, PatchVersionInterface
1617
{
1718
/**
1819
* @var Comment
@@ -36,6 +37,9 @@ public function __construct(
3637
$this->moduleResource = $moduleResource;
3738
}
3839

40+
/**
41+
* @return void
42+
*/
3943
public function apply()
4044
{
4145
$connection = $this->commentResource->getConnection();
@@ -49,13 +53,27 @@ public function apply()
4953
}
5054
}
5155

56+
/**
57+
* @return array|string[]
58+
*/
5259
public static function getDependencies()
5360
{
5461
return [];
5562
}
5663

64+
/**
65+
* @return array|string[]
66+
*/
5767
public function getAliases()
5868
{
5969
return [];
6070
}
71+
72+
/**
73+
* @return string
74+
*/
75+
public static function getVersion()
76+
{
77+
return '2.9.1';
78+
}
6179
}

0 commit comments

Comments
 (0)