@@ -87,15 +87,15 @@ protected function prepareSelect(array $data)
8787 }
8888
8989 /**
90- * { @inheritdoc}
90+ * @inheritdoc
9191 */
9292 protected function doFindAllByData (array $ data )
9393 {
9494 return $ this ->connection ->fetchAll ($ this ->prepareSelect ($ data ));
9595 }
9696
9797 /**
98- * { @inheritdoc}
98+ * @inheritdoc
9999 */
100100 protected function doFindOneByData (array $ data )
101101 {
@@ -161,26 +161,22 @@ private function deleteOldUrls(array $urls): void
161161 $ oldUrlsSelect ->from (
162162 $ this ->resource ->getTableName (self ::TABLE_NAME )
163163 );
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+ }
184180 }
185181
186182 // prevent query locking in a case when nothing to delete
@@ -198,6 +194,28 @@ private function deleteOldUrls(array $urls): void
198194 }
199195 }
200196
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+
201219 /**
202220 * @inheritDoc
203221 */
@@ -289,7 +307,7 @@ protected function createFilterDataBasedOnUrls($urls)
289307 }
290308
291309 /**
292- * { @inheritdoc}
310+ * @inheritdoc
293311 */
294312 public function deleteByData (array $ data )
295313 {
0 commit comments