6
6
7
7
namespace Magento \SampleData \Console \Command ;
8
8
9
- use Composer \Console \Application ;
10
9
use Composer \Console \ApplicationFactory ;
11
10
use Exception ;
12
11
use Magento \Framework \App \Filesystem \DirectoryList ;
15
14
use Magento \Framework \Exception \InvalidArgumentException ;
16
15
use Magento \Framework \Exception \LocalizedException ;
17
16
use Magento \Framework \Filesystem ;
18
- use Magento \Framework \Serialize \Serializer \Json ;
19
17
use Magento \SampleData \Model \Dependency ;
20
18
use Magento \Setup \Model \PackagesAuth ;
21
19
use Symfony \Component \Console \Command \Command ;
22
20
use Symfony \Component \Console \Input \ArrayInput ;
23
- use Symfony \Component \Console \Input \ArrayInputFactory ;
24
21
use Symfony \Component \Console \Input \InputInterface ;
25
22
use Symfony \Component \Console \Input \InputOption ;
26
23
use Symfony \Component \Console \Output \OutputInterface ;
32
29
*/
33
30
class SampleDataDeployCommand extends Command
34
31
{
35
- const OPTION_NO_UPDATE = 'no-update ' ;
32
+ public const OPTION_NO_UPDATE = 'no-update ' ;
36
33
37
- /**
38
- * @var Filesystem
39
- */
40
- private $ filesystem ;
34
+ /** @var Filesystem */
35
+ private Filesystem $ filesystem ;
41
36
42
- /**
43
- * @var Dependency
44
- */
45
- private $ sampleDataDependency ;
37
+ /** @var Dependency */
38
+ private Dependency $ sampleDataDependency ;
46
39
47
- /**
48
- * @var ArrayInputFactory
49
- * @deprecated 100.1.0
50
- */
51
- private $ arrayInputFactory ;
52
-
53
- /**
54
- * @var ApplicationFactory
55
- */
56
- private $ applicationFactory ;
57
-
58
- /**
59
- * @var Json
60
- */
61
- private $ serializer ;
40
+ /** @var ApplicationFactory */
41
+ private ApplicationFactory $ applicationFactory ;
62
42
63
43
/**
64
44
* @param Filesystem $filesystem
65
45
* @param Dependency $sampleDataDependency
66
- * @param ArrayInputFactory $arrayInputFactory
67
46
* @param ApplicationFactory $applicationFactory
68
- * @param Json $serializer
69
47
*/
70
48
public function __construct (
71
49
Filesystem $ filesystem ,
72
50
Dependency $ sampleDataDependency ,
73
- ArrayInputFactory $ arrayInputFactory ,
74
- ApplicationFactory $ applicationFactory ,
75
- Json $ serializer
51
+ ApplicationFactory $ applicationFactory
76
52
) {
77
53
$ this ->filesystem = $ filesystem ;
78
54
$ this ->sampleDataDependency = $ sampleDataDependency ;
79
- $ this ->arrayInputFactory = $ arrayInputFactory ;
80
55
$ this ->applicationFactory = $ applicationFactory ;
81
- $ this -> serializer = $ serializer ;
56
+
82
57
parent ::__construct ();
83
58
}
84
59
@@ -107,35 +82,8 @@ protected function configure()
107
82
* @throws FileSystemException
108
83
* @throws LocalizedException
109
84
*/
110
- protected function execute (InputInterface $ input , OutputInterface $ output )
85
+ protected function execute (InputInterface $ input , OutputInterface $ output ): int
111
86
{
112
- $ rootJson = $ this ->serializer ->unserialize (
113
- $ this ->filesystem ->getDirectoryRead (
114
- DirectoryList::ROOT
115
- )->readFile ("composer.json " )
116
- );
117
- if (!isset ($ rootJson ['version ' ])) {
118
- $ magentoProductPackage = array_filter (
119
- $ rootJson ['require ' ],
120
- function ($ package ) {
121
- return false !== strpos ($ package , 'magento/product- ' );
122
- },
123
- ARRAY_FILTER_USE_KEY
124
- );
125
- $ version = reset ($ magentoProductPackage );
126
- $ output ->writeln (
127
- '<info> ' .
128
- // @codingStandardsIgnoreLine
129
- 'We don \'t recommend to remove the "version" field from your composer.json; see https://getcomposer.org/doc/02-libraries.md#library-versioning for more information. ' .
130
- '</info> '
131
- );
132
- $ restoreVersion = new ArrayInput ([
133
- 'command ' => 'config ' ,
134
- 'setting-key ' => 'version ' ,
135
- 'setting-value ' => [$ version ],
136
- '--quiet ' => 1
137
- ]);
138
- }
139
87
$ this ->updateMemoryLimit ();
140
88
$ this ->createAuthFile ();
141
89
$ sampleDataPackages = $ this ->sampleDataDependency ->getSampleDataPackages ();
@@ -153,15 +101,8 @@ function ($package) {
153
101
$ arguments = array_merge (['command ' => 'require ' ], $ commonArgs );
154
102
$ commandInput = new ArrayInput ($ arguments );
155
103
156
- /** @var Application $application */
157
104
$ application = $ this ->applicationFactory ->create ();
158
105
$ application ->setAutoExit (false );
159
- if (!empty ($ restoreVersion )) {
160
- $ result = $ application ->run ($ restoreVersion , clone $ output );
161
- if ($ result === 0 ) {
162
- $ output ->writeln ('<info>The field "version" has been restored.</info> ' );
163
- }
164
- }
165
106
$ result = $ application ->run ($ commandInput , $ output );
166
107
if ($ result !== 0 ) {
167
108
$ output ->writeln (
@@ -173,12 +114,18 @@ function ($package) {
173
114
return Cli::RETURN_FAILURE ;
174
115
}
175
116
176
- return Cli::RETURN_SUCCESS ;
177
- } else {
178
- $ output ->writeln ('<info> ' . 'There is no sample data for current set of modules. ' . '</info> ' );
117
+ $ output ->writeln (
118
+ '<info> '
119
+ . 'Sample data modules have been added via composer. Please run bin/magento setup:upgrade '
120
+ . '</info> '
121
+ );
179
122
180
- return Cli::RETURN_FAILURE ;
123
+ return Cli::RETURN_SUCCESS ;
181
124
}
125
+
126
+ $ output ->writeln ('<info> ' . 'There is no sample data for current set of modules. ' . '</info> ' );
127
+
128
+ return Cli::RETURN_FAILURE ;
182
129
}
183
130
184
131
/**
@@ -189,7 +136,7 @@ function ($package) {
189
136
* @return void
190
137
* @throws LocalizedException
191
138
*/
192
- private function createAuthFile ()
139
+ private function createAuthFile (): void
193
140
{
194
141
$ directory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::COMPOSER_HOME );
195
142
@@ -211,7 +158,7 @@ private function createAuthFile()
211
158
* @throws InvalidArgumentException
212
159
* @return void
213
160
*/
214
- private function updateMemoryLimit ()
161
+ private function updateMemoryLimit (): void
215
162
{
216
163
if (function_exists ('ini_set ' )) {
217
164
// phpcs:ignore Magento2.Functions.DiscouragedFunction
@@ -244,7 +191,7 @@ private function updateMemoryLimit()
244
191
* @param string $value
245
192
* @return int
246
193
*/
247
- private function getMemoryInBytes ($ value )
194
+ private function getMemoryInBytes (string $ value ): int
248
195
{
249
196
$ unit = strtolower (substr ($ value , -1 , 1 ));
250
197
$ value = (int ) $ value ;
0 commit comments