@@ -79,15 +79,15 @@ protected function prepareSelect(array $data)
79
79
}
80
80
81
81
/**
82
- * { @inheritdoc}
82
+ * @inheritdoc
83
83
*/
84
84
protected function doFindAllByData (array $ data )
85
85
{
86
86
return $ this ->connection ->fetchAll ($ this ->prepareSelect ($ data ));
87
87
}
88
88
89
89
/**
90
- * { @inheritdoc}
90
+ * @inheritdoc
91
91
*/
92
92
protected function doFindOneByData (array $ data )
93
93
{
@@ -152,26 +152,22 @@ private function deleteOldUrls(array $urls)
152
152
$ oldUrlsSelect ->from (
153
153
$ this ->resource ->getTableName (self ::TABLE_NAME )
154
154
);
155
- /** @var UrlRewrite $url */
156
- foreach ($ urls as $ url ) {
157
- $ oldUrlsSelect ->orWhere (
158
- $ this ->connection ->quoteIdentifier (
159
- UrlRewrite::ENTITY_TYPE
160
- ) . ' = ? ' ,
161
- $ url ->getEntityType ()
162
- );
163
- $ oldUrlsSelect ->where (
164
- $ this ->connection ->quoteIdentifier (
165
- UrlRewrite::ENTITY_ID
166
- ) . ' = ? ' ,
167
- $ url ->getEntityId ()
168
- );
169
- $ oldUrlsSelect ->where (
170
- $ this ->connection ->quoteIdentifier (
171
- UrlRewrite::STORE_ID
172
- ) . ' = ? ' ,
173
- $ url ->getStoreId ()
174
- );
155
+
156
+ $ uniqueEntities = $ this ->prepareUniqueEntities ($ urls );
157
+ foreach ($ uniqueEntities as $ storeId => $ entityTypes ) {
158
+ foreach ($ entityTypes as $ entityType => $ entities ) {
159
+ $ oldUrlsSelect ->orWhere (
160
+ $ this ->connection ->quoteIdentifier (
161
+ UrlRewrite::STORE_ID
162
+ ) . ' = ' . $ this ->connection ->quote ($ storeId , 'INTEGER ' ) .
163
+ ' AND ' . $ this ->connection ->quoteIdentifier (
164
+ UrlRewrite::ENTITY_ID
165
+ ) . ' IN ( ' . $ this ->connection ->quote ($ entities , 'INTEGER ' ) . ') ' .
166
+ ' AND ' . $ this ->connection ->quoteIdentifier (
167
+ UrlRewrite::ENTITY_TYPE
168
+ ) . ' = ' . $ this ->connection ->quote ($ entityType )
169
+ );
170
+ }
175
171
}
176
172
177
173
// prevent query locking in a case when nothing to delete
@@ -189,6 +185,28 @@ private function deleteOldUrls(array $urls)
189
185
}
190
186
}
191
187
188
+ /**
189
+ * Prepare array with unique entities
190
+ *
191
+ * @param UrlRewrite[] $urls
192
+ * @return array
193
+ */
194
+ private function prepareUniqueEntities (array $ urls ): array
195
+ {
196
+ $ uniqueEntities = [];
197
+ /** @var UrlRewrite $url */
198
+ foreach ($ urls as $ url ) {
199
+ $ entityIds = (!empty ($ uniqueEntities [$ url ->getStoreId ()][$ url ->getEntityType ()])) ?
200
+ $ uniqueEntities [$ url ->getStoreId ()][$ url ->getEntityType ()] : [];
201
+
202
+ if (!\in_array ($ url ->getEntityId (), $ entityIds )) {
203
+ $ entityIds [] = $ url ->getEntityId ();
204
+ }
205
+ $ uniqueEntities [$ url ->getStoreId ()][$ url ->getEntityType ()] = $ entityIds ;
206
+ }
207
+ return $ uniqueEntities ;
208
+ }
209
+
192
210
/**
193
211
* @inheritDoc
194
212
*/
@@ -279,7 +297,7 @@ protected function createFilterDataBasedOnUrls($urls)
279
297
}
280
298
281
299
/**
282
- * { @inheritdoc}
300
+ * @inheritdoc
283
301
*/
284
302
public function deleteByData (array $ data )
285
303
{
0 commit comments