15
15
use Symfony \Component \Console \Helper \ProgressBar ;
16
16
use Magento \Framework \ObjectManagerInterface ;
17
17
18
+ /**
19
+ * Class for catalog image resizing via CLI
20
+ */
18
21
class ImagesResizeCommand extends \Symfony \Component \Console \Command \Command
19
22
{
20
23
/**
@@ -49,7 +52,7 @@ public function __construct(
49
52
}
50
53
51
54
/**
52
- * { @inheritdoc}
55
+ * @inheritdoc
53
56
*/
54
57
protected function configure ()
55
58
{
@@ -58,19 +61,23 @@ protected function configure()
58
61
}
59
62
60
63
/**
61
- * { @inheritdoc}
64
+ * @inheritdoc
62
65
*/
63
66
protected function execute (InputInterface $ input , OutputInterface $ output )
64
67
{
65
68
try {
69
+ $ errors = [];
66
70
$ this ->appState ->setAreaCode (Area::AREA_GLOBAL );
67
71
$ generator = $ this ->resize ->resizeFromThemes ();
68
72
69
73
/** @var ProgressBar $progress */
70
- $ progress = $ this ->objectManager ->create (ProgressBar::class, [
71
- 'output ' => $ output ,
72
- 'max ' => $ generator ->current ()
73
- ]);
74
+ $ progress = $ this ->objectManager ->create (
75
+ ProgressBar::class,
76
+ [
77
+ 'output ' => $ output ,
78
+ 'max ' => $ generator ->current ()
79
+ ]
80
+ );
74
81
$ progress ->setFormat (
75
82
"%current%/%max% [%bar%] %percent:3s%% %elapsed% %memory:6s% \t| <info>%message%</info> "
76
83
);
@@ -79,8 +86,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
79
86
$ progress ->setOverwrite (false );
80
87
}
81
88
89
+ // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
82
90
for (; $ generator ->valid (); $ generator ->next ()) {
83
- $ progress ->setMessage ($ generator ->key ());
91
+ $ resizeInfo = $ generator ->key ();
92
+ $ error = $ resizeInfo ['error ' ];
93
+ $ filename = $ resizeInfo ['filename ' ];
94
+
95
+ if ($ error !== '' ) {
96
+ $ errors [$ filename ] = $ error ;
97
+ }
98
+
99
+ $ progress ->setMessage ($ filename );
84
100
$ progress ->advance ();
85
101
}
86
102
} catch (\Exception $ e ) {
@@ -90,6 +106,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
90
106
}
91
107
92
108
$ output ->write (PHP_EOL );
93
- $ output ->writeln ("<info>Product images resized successfully</info> " );
109
+ if (count ($ errors )) {
110
+ $ output ->writeln ("<info>Product images resized with errors:</info> " );
111
+ foreach ($ errors as $ error ) {
112
+ $ output ->writeln ("<error> {$ error }</error> " );
113
+ }
114
+ } else {
115
+ $ output ->writeln ("<info>Product images resized successfully</info> " );
116
+ }
94
117
}
95
118
}
0 commit comments