15
15
use Magento \Framework \App \ObjectManagerFactory ;
16
16
use Magento \Framework \ObjectManagerInterface ;
17
17
use Magento \Framework \Validator \Locale ;
18
- use Magento \Framework \Console \Cli ;
19
- use Magento \Deploy \Model \ProcessManager ;
20
- use Magento \Deploy \Model \Process ;
21
18
use Magento \Framework \Exception \LocalizedException ;
22
19
use Magento \Framework \App \State ;
23
20
use Magento \Deploy \Console \Command \DeployStaticOptionsInterface as Options ;
21
+ use Magento \Deploy \Model \DeployManager ;
24
22
25
23
/**
26
24
* Deploy static content command
@@ -121,109 +119,116 @@ protected function configure()
121
119
Options::FORCE_RUN ,
122
120
'-f ' ,
123
121
InputOption::VALUE_NONE ,
124
- 'If specified, then run files will be deployed in any mode. '
122
+ 'Deploy files in any mode. '
125
123
),
126
124
new InputOption (
127
125
Options::NO_JAVASCRIPT ,
128
126
null ,
129
127
InputOption::VALUE_NONE ,
130
- 'If specified, no JavaScript will be deployed. '
128
+ 'Do not deploy JavaScript files '
131
129
),
132
130
new InputOption (
133
131
Options::NO_CSS ,
134
132
null ,
135
133
InputOption::VALUE_NONE ,
136
- 'If specified, no CSS will be deployed . '
134
+ 'Do not deploy CSS files . '
137
135
),
138
136
new InputOption (
139
137
Options::NO_LESS ,
140
138
null ,
141
139
InputOption::VALUE_NONE ,
142
- 'If specified, no LESS will be deployed . '
140
+ 'Do not deploy LESS files . '
143
141
),
144
142
new InputOption (
145
143
Options::NO_IMAGES ,
146
144
null ,
147
145
InputOption::VALUE_NONE ,
148
- 'If specified, no images will be deployed . '
146
+ 'Do not deploy images. '
149
147
),
150
148
new InputOption (
151
149
Options::NO_FONTS ,
152
150
null ,
153
151
InputOption::VALUE_NONE ,
154
- 'If specified, no font files will be deployed . '
152
+ 'Do not deploy font files. '
155
153
),
156
154
new InputOption (
157
155
Options::NO_HTML ,
158
156
null ,
159
157
InputOption::VALUE_NONE ,
160
- 'If specified, no html files will be deployed . '
158
+ 'Do not deploy HTML files. '
161
159
),
162
160
new InputOption (
163
161
Options::NO_MISC ,
164
162
null ,
165
163
InputOption::VALUE_NONE ,
166
- 'If specified, no miscellaneous files will be deployed . '
164
+ 'Do not deploy other types of files (.md, .jbf, .csv, etc...) . '
167
165
),
168
166
new InputOption (
169
167
Options::NO_HTML_MINIFY ,
170
168
null ,
171
169
InputOption::VALUE_NONE ,
172
- 'If specified, html will not be minified . '
170
+ 'Do not minify HTML files . '
173
171
),
174
172
new InputOption (
175
173
Options::THEME ,
176
174
'-t ' ,
177
175
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL ,
178
- 'If specified, just specific theme(s) will be actually deployed . ' ,
176
+ 'Generate static view files for only the specified themes . ' ,
179
177
['all ' ]
180
178
),
181
179
new InputOption (
182
180
Options::EXCLUDE_THEME ,
183
181
null ,
184
182
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL ,
185
- 'If specified, exclude specific theme(s) from deployment . ' ,
183
+ 'Do not generate files for the specified themes . ' ,
186
184
['none ' ]
187
185
),
188
186
new InputOption (
189
187
Options::LANGUAGE ,
190
188
'-l ' ,
191
189
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL ,
192
- 'List of languages you want the tool populate files for . ' ,
190
+ 'Generate files only for the specified languages . ' ,
193
191
['all ' ]
194
192
),
195
193
new InputOption (
196
194
Options::EXCLUDE_LANGUAGE ,
197
195
null ,
198
196
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL ,
199
- 'List of langiages you do not want the tool populate files for . ' ,
197
+ 'Do not generate files for the specified languages . ' ,
200
198
['none ' ]
201
199
),
202
200
new InputOption (
203
201
Options::AREA ,
204
202
'-a ' ,
205
203
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL ,
206
- 'List of areas you want the tool populate files for . ' ,
204
+ 'Generate files only for the specified areas . ' ,
207
205
['all ' ]
208
206
),
209
207
new InputOption (
210
208
Options::EXCLUDE_AREA ,
211
209
null ,
212
210
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL ,
213
- 'List of areas you do not want the tool populate files for . ' ,
211
+ 'Do not generate files for the specified areas . ' ,
214
212
['none ' ]
215
213
),
216
214
new InputOption (
217
215
Options::JOBS_AMOUNT ,
218
216
'-j ' ,
219
217
InputOption::VALUE_OPTIONAL ,
220
- 'Amount of jobs to which script can be paralleled . ' ,
218
+ 'Enable parallel processing using the specified number of jobs . ' ,
221
219
self ::DEFAULT_JOBS_AMOUNT
222
220
),
221
+ new InputOption (
222
+ Options::SYMLINK_LOCALE ,
223
+ null ,
224
+ InputOption::VALUE_NONE ,
225
+ 'Create symlinks for the files of those locales, which are passed for deployment, '
226
+ . 'but have no customizations '
227
+ ),
223
228
new InputArgument (
224
229
self ::LANGUAGES_ARGUMENT ,
225
230
InputArgument::IS_ARRAY ,
226
- 'List of languages you want the tool populate files for . '
231
+ 'Space-separated list of ISO-636 language codes for which to output static view files . '
227
232
),
228
233
]);
229
234
@@ -374,8 +379,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
374
379
if (!$ input ->getOption (Options::FORCE_RUN ) && $ this ->getAppState ()->getMode () !== State::MODE_PRODUCTION ) {
375
380
throw new LocalizedException (
376
381
__ (
377
- "Deploy static content is applicable only for production mode. \n"
378
- . "Please use command 'bin/magento deploy:mode:set production' for set up production mode. "
382
+ 'NOTE: Manual static content deployment is not required in "default" and "developer" modes. '
383
+ . PHP_EOL . 'In "default" and "developer" modes static contents are being deployed '
384
+ . 'automatically on demand. '
385
+ . PHP_EOL . 'If you still want to deploy in these modes, use -f option: '
386
+ . "'bin/magento setup:static-content:deploy -f' "
379
387
)
380
388
);
381
389
}
@@ -390,20 +398,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
390
398
$ output ->writeln ("Requested areas: " . implode (', ' , array_keys ($ deployableAreaThemeMap )));
391
399
$ output ->writeln ("Requested themes: " . implode (', ' , $ requestedThemes ));
392
400
393
- $ deployer = $ this ->objectManager ->create (
394
- \Magento \Deploy \Model \Deployer::class,
401
+ /** @var $deployManager DeployManager */
402
+ $ deployManager = $ this ->objectManager ->create (
403
+ DeployManager::class,
395
404
[
396
- 'filesUtil ' => $ filesUtil ,
397
405
'output ' => $ output ,
398
406
'options ' => $ this ->input ->getOptions (),
399
407
]
400
408
);
401
409
402
- if ($ this ->isCanBeParalleled ()) {
403
- return $ this ->runProcessesInParallel ($ deployer , $ deployableAreaThemeMap , $ deployableLanguages );
404
- } else {
405
- return $ this ->deploy ($ deployer , $ deployableLanguages , $ deployableAreaThemeMap );
410
+ foreach ($ deployableAreaThemeMap as $ area => $ themes ) {
411
+ foreach ($ deployableLanguages as $ locale ) {
412
+ foreach ($ themes as $ themePath ) {
413
+ $ deployManager ->addPack ($ area , $ themePath , $ locale );
414
+ }
415
+ }
406
416
}
417
+
418
+ return $ deployManager ->deploy ();
407
419
}
408
420
409
421
/**
@@ -464,89 +476,4 @@ private function prepareDeployableEntities($filesUtil)
464
476
465
477
return [$ deployableLanguages , $ deployableAreaThemeMap , $ requestedThemes ];
466
478
}
467
-
468
- /**
469
- * @param \Magento\Deploy\Model\Deployer $deployer
470
- * @param array $deployableLanguages
471
- * @param array $deployableAreaThemeMap
472
- * @return int
473
- */
474
- private function deploy ($ deployer , $ deployableLanguages , $ deployableAreaThemeMap )
475
- {
476
- return $ deployer ->deploy (
477
- $ this ->objectManagerFactory ,
478
- $ deployableLanguages ,
479
- $ deployableAreaThemeMap
480
- );
481
- }
482
-
483
- /**
484
- * @param \Magento\Deploy\Model\Deployer $deployer
485
- * @param array $deployableAreaThemeMap
486
- * @param array $deployableLanguages
487
- * @return int
488
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
489
- */
490
- private function runProcessesInParallel ($ deployer , $ deployableAreaThemeMap , $ deployableLanguages )
491
- {
492
- /** @var ProcessManager $processManager */
493
- $ processManager = $ this ->objectManager ->create (ProcessManager::class);
494
- $ processNumber = 0 ;
495
- $ processQueue = [];
496
- foreach ($ deployableAreaThemeMap as $ area => &$ themes ) {
497
- foreach ($ themes as $ theme ) {
498
- foreach ($ deployableLanguages as $ lang ) {
499
- $ deployerFunc = function (Process $ process ) use ($ area , $ theme , $ lang , $ deployer ) {
500
- return $ this ->deploy ($ deployer , [$ lang ], [$ area => [$ theme ]]);
501
- };
502
- if ($ processNumber >= $ this ->getProcessesAmount ()) {
503
- $ processQueue [] = $ deployerFunc ;
504
- } else {
505
- $ processManager ->fork ($ deployerFunc );
506
- }
507
- $ processNumber ++;
508
- }
509
- }
510
- }
511
- $ returnStatus = null ;
512
- while (count ($ processManager ->getProcesses ()) > 0 ) {
513
- foreach ($ processManager ->getProcesses () as $ process ) {
514
- if ($ process ->isCompleted ()) {
515
- $ processManager ->delete ($ process );
516
- $ returnStatus |= $ process ->getStatus ();
517
- if ($ queuedProcess = array_shift ($ processQueue )) {
518
- $ processManager ->fork ($ queuedProcess );
519
- }
520
- if (count ($ processManager ->getProcesses ()) >= $ this ->getProcessesAmount ()) {
521
- break 1 ;
522
- }
523
- }
524
- }
525
- usleep (5000 );
526
- }
527
-
528
- return $ returnStatus === Cli::RETURN_SUCCESS ?: Cli::RETURN_FAILURE ;
529
- }
530
-
531
- /**
532
- * @return bool
533
- */
534
- private function isCanBeParalleled ()
535
- {
536
- return function_exists ('pcntl_fork ' ) && $ this ->getProcessesAmount () > 1 ;
537
- }
538
-
539
- /**
540
- * @return int
541
- */
542
- private function getProcessesAmount ()
543
- {
544
- $ jobs = (int )$ this ->input ->getOption (Options::JOBS_AMOUNT );
545
- if ($ jobs < 1 ) {
546
- throw new \InvalidArgumentException (
547
- Options::JOBS_AMOUNT . ' argument has invalid value. It must be greater than 0 '
548
- );
549
- }
550
- return $ jobs ;
551
- }
552
479
}
0 commit comments