@@ -55,6 +55,11 @@ class RegenerateProductUrl
55
55
*/
56
56
private int $ regeneratedCount = 0 ;
57
57
58
+ /**
59
+ * @var bool
60
+ */
61
+ private bool $ isVerboseMode = false ;
62
+
58
63
/**
59
64
* Constructor.
60
65
*
@@ -87,11 +92,12 @@ public function __construct(
87
92
*/
88
93
public function execute (?array $ productIds = null , ?int $ storeId = null , bool $ verbose = false ): void
89
94
{
95
+ $ this ->isVerboseMode = $ verbose ;
90
96
$ this ->regeneratedCount = 0 ;
91
97
92
98
$ stores = null !== $ storeId
93
99
? [$ this ->storeManager ->getStore ($ storeId )]
94
- : $ this ->storeManager ->getStores (false );
100
+ : $ this ->storeManager ->getStores ();
95
101
96
102
foreach ($ stores as $ store ) {
97
103
$ regeneratedForStore = 0 ;
@@ -132,7 +138,7 @@ public function execute(?array $productIds = null, ?int $storeId = null, bool $v
132
138
$ newUrls = [];
133
139
/** @var Product $product */
134
140
foreach ($ collection as $ product ) {
135
- if ($ verbose ) {
141
+ if ($ this -> isVerboseMode ) {
136
142
$ this ->log (
137
143
sprintf (
138
144
'Regenerating urls for %s (%s) in store (%s) ' ,
@@ -216,19 +222,27 @@ private function replaceUrls(array &$urls, bool $last = false): int
216
222
{
217
223
$ this ->log (sprintf ('replaceUrls%s batch: %d ' , $ last ? ' last ' : '' , count ($ urls )));
218
224
219
- foreach ($ urls as $ url ) {
225
+ if ($ this ->isVerboseMode ) {
226
+ foreach ($ urls as $ url ) {
227
+ try {
228
+ $ this ->urlPersist ->replace ([$ url ]);
229
+ } catch (Exception $ e ) {
230
+ $ this ->log (
231
+ sprintf (
232
+ $ e ->getMessage () . ' Entity id: %d Request path: %s ' ,
233
+ $ url ->getEntityId (),
234
+ $ url ->getRequestPath ()
235
+ )
236
+ );
237
+ }
238
+ }
239
+ } else {
220
240
try {
221
- $ this ->urlPersist ->replace ([$ url ]);
222
- } catch (Exception $ e ) {
223
- $ this ->log (
224
- sprintf (
225
- $ e ->getMessage () . ' Entity id: %d Request path: %s ' ,
226
- $ url ->getEntityId (),
227
- $ url ->getRequestPath ()
228
- )
229
- );
241
+ $ this ->urlPersist ->replace ($ urls );
242
+ } catch (Exception $ e ) {//phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
230
243
}
231
244
}
245
+
232
246
$ count = count ($ urls );
233
247
$ urls = [];
234
248
0 commit comments