@@ -87,15 +87,15 @@ protected function prepareSelect(array $data)
87
87
}
88
88
89
89
/**
90
- * { @inheritdoc}
90
+ * @inheritdoc
91
91
*/
92
92
protected function doFindAllByData (array $ data )
93
93
{
94
94
return $ this ->connection ->fetchAll ($ this ->prepareSelect ($ data ));
95
95
}
96
96
97
97
/**
98
- * { @inheritdoc}
98
+ * @inheritdoc
99
99
*/
100
100
protected function doFindOneByData (array $ data )
101
101
{
@@ -161,26 +161,22 @@ private function deleteOldUrls(array $urls): void
161
161
$ oldUrlsSelect ->from (
162
162
$ this ->resource ->getTableName (self ::TABLE_NAME )
163
163
);
164
- /** @var UrlRewrite $url */
165
- foreach ($ urls as $ url ) {
166
- $ oldUrlsSelect ->orWhere (
167
- $ this ->connection ->quoteIdentifier (
168
- UrlRewrite::ENTITY_TYPE
169
- ) . ' = ? ' ,
170
- $ url ->getEntityType ()
171
- );
172
- $ oldUrlsSelect ->where (
173
- $ this ->connection ->quoteIdentifier (
174
- UrlRewrite::ENTITY_ID
175
- ) . ' = ? ' ,
176
- $ url ->getEntityId ()
177
- );
178
- $ oldUrlsSelect ->where (
179
- $ this ->connection ->quoteIdentifier (
180
- UrlRewrite::STORE_ID
181
- ) . ' = ? ' ,
182
- $ url ->getStoreId ()
183
- );
164
+
165
+ $ uniqueEntities = $ this ->prepareUniqueEntities ($ urls );
166
+ foreach ($ uniqueEntities as $ storeId => $ entityTypes ) {
167
+ foreach ($ entityTypes as $ entityType => $ entities ) {
168
+ $ oldUrlsSelect ->orWhere (
169
+ $ this ->connection ->quoteIdentifier (
170
+ UrlRewrite::STORE_ID
171
+ ) . ' = ' . $ this ->connection ->quote ($ storeId , 'INTEGER ' ) .
172
+ ' AND ' . $ this ->connection ->quoteIdentifier (
173
+ UrlRewrite::ENTITY_ID
174
+ ) . ' IN ( ' . $ this ->connection ->quote ($ entities , 'INTEGER ' ) . ') ' .
175
+ ' AND ' . $ this ->connection ->quoteIdentifier (
176
+ UrlRewrite::ENTITY_TYPE
177
+ ) . ' = ' . $ this ->connection ->quote ($ entityType )
178
+ );
179
+ }
184
180
}
185
181
186
182
// prevent query locking in a case when nothing to delete
@@ -198,6 +194,28 @@ private function deleteOldUrls(array $urls): void
198
194
}
199
195
}
200
196
197
+ /**
198
+ * Prepare array with unique entities
199
+ *
200
+ * @param UrlRewrite[] $urls
201
+ * @return array
202
+ */
203
+ private function prepareUniqueEntities (array $ urls ): array
204
+ {
205
+ $ uniqueEntities = [];
206
+ /** @var UrlRewrite $url */
207
+ foreach ($ urls as $ url ) {
208
+ $ entityIds = (!empty ($ uniqueEntities [$ url ->getStoreId ()][$ url ->getEntityType ()])) ?
209
+ $ uniqueEntities [$ url ->getStoreId ()][$ url ->getEntityType ()] : [];
210
+
211
+ if (!\in_array ($ url ->getEntityId (), $ entityIds )) {
212
+ $ entityIds [] = $ url ->getEntityId ();
213
+ }
214
+ $ uniqueEntities [$ url ->getStoreId ()][$ url ->getEntityType ()] = $ entityIds ;
215
+ }
216
+ return $ uniqueEntities ;
217
+ }
218
+
201
219
/**
202
220
* @inheritDoc
203
221
*/
@@ -289,7 +307,7 @@ protected function createFilterDataBasedOnUrls($urls)
289
307
}
290
308
291
309
/**
292
- * { @inheritdoc}
310
+ * @inheritdoc
293
311
*/
294
312
public function deleteByData (array $ data )
295
313
{
0 commit comments