66
77namespace Magento \SampleData \Console \Command ;
88
9- use Composer \Console \Application ;
109use Composer \Console \ApplicationFactory ;
1110use Exception ;
1211use Magento \Framework \App \Filesystem \DirectoryList ;
1514use Magento \Framework \Exception \InvalidArgumentException ;
1615use Magento \Framework \Exception \LocalizedException ;
1716use Magento \Framework \Filesystem ;
18- use Magento \Framework \Serialize \Serializer \Json ;
1917use Magento \SampleData \Model \Dependency ;
2018use Magento \Setup \Model \PackagesAuth ;
2119use Symfony \Component \Console \Command \Command ;
2220use Symfony \Component \Console \Input \ArrayInput ;
23- use Symfony \Component \Console \Input \ArrayInputFactory ;
2421use Symfony \Component \Console \Input \InputInterface ;
2522use Symfony \Component \Console \Input \InputOption ;
2623use Symfony \Component \Console \Output \OutputInterface ;
3229 */
3330class SampleDataDeployCommand extends Command
3431{
35- const OPTION_NO_UPDATE = 'no-update ' ;
32+ public const OPTION_NO_UPDATE = 'no-update ' ;
3633
37- /**
38- * @var Filesystem
39- */
40- private $ filesystem ;
34+ /** @var Filesystem */
35+ private Filesystem $ filesystem ;
4136
42- /**
43- * @var Dependency
44- */
45- private $ sampleDataDependency ;
37+ /** @var Dependency */
38+ private Dependency $ sampleDataDependency ;
4639
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 ;
6242
6343 /**
6444 * @param Filesystem $filesystem
6545 * @param Dependency $sampleDataDependency
66- * @param ArrayInputFactory $arrayInputFactory
6746 * @param ApplicationFactory $applicationFactory
68- * @param Json $serializer
6947 */
7048 public function __construct (
7149 Filesystem $ filesystem ,
7250 Dependency $ sampleDataDependency ,
73- ArrayInputFactory $ arrayInputFactory ,
74- ApplicationFactory $ applicationFactory ,
75- Json $ serializer
51+ ApplicationFactory $ applicationFactory
7652 ) {
7753 $ this ->filesystem = $ filesystem ;
7854 $ this ->sampleDataDependency = $ sampleDataDependency ;
79- $ this ->arrayInputFactory = $ arrayInputFactory ;
8055 $ this ->applicationFactory = $ applicationFactory ;
81- $ this -> serializer = $ serializer ;
56+
8257 parent ::__construct ();
8358 }
8459
@@ -107,35 +82,8 @@ protected function configure()
10782 * @throws FileSystemException
10883 * @throws LocalizedException
10984 */
110- protected function execute (InputInterface $ input , OutputInterface $ output )
85+ protected function execute (InputInterface $ input , OutputInterface $ output ): int
11186 {
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- }
13987 $ this ->updateMemoryLimit ();
14088 $ this ->createAuthFile ();
14189 $ sampleDataPackages = $ this ->sampleDataDependency ->getSampleDataPackages ();
@@ -153,15 +101,8 @@ function ($package) {
153101 $ arguments = array_merge (['command ' => 'require ' ], $ commonArgs );
154102 $ commandInput = new ArrayInput ($ arguments );
155103
156- /** @var Application $application */
157104 $ application = $ this ->applicationFactory ->create ();
158105 $ 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- }
165106 $ result = $ application ->run ($ commandInput , $ output );
166107 if ($ result !== 0 ) {
167108 $ output ->writeln (
@@ -173,12 +114,18 @@ function ($package) {
173114 return Cli::RETURN_FAILURE ;
174115 }
175116
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+ );
179122
180- return Cli::RETURN_FAILURE ;
123+ return Cli::RETURN_SUCCESS ;
181124 }
125+
126+ $ output ->writeln ('<info> ' . 'There is no sample data for current set of modules. ' . '</info> ' );
127+
128+ return Cli::RETURN_FAILURE ;
182129 }
183130
184131 /**
@@ -189,7 +136,7 @@ function ($package) {
189136 * @return void
190137 * @throws LocalizedException
191138 */
192- private function createAuthFile ()
139+ private function createAuthFile (): void
193140 {
194141 $ directory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::COMPOSER_HOME );
195142
@@ -211,7 +158,7 @@ private function createAuthFile()
211158 * @throws InvalidArgumentException
212159 * @return void
213160 */
214- private function updateMemoryLimit ()
161+ private function updateMemoryLimit (): void
215162 {
216163 if (function_exists ('ini_set ' )) {
217164 // phpcs:ignore Magento2.Functions.DiscouragedFunction
@@ -244,7 +191,7 @@ private function updateMemoryLimit()
244191 * @param string $value
245192 * @return int
246193 */
247- private function getMemoryInBytes ($ value )
194+ private function getMemoryInBytes (string $ value ): int
248195 {
249196 $ unit = strtolower (substr ($ value , -1 , 1 ));
250197 $ value = (int ) $ value ;
0 commit comments